Bug report #2661
QgsVectorLayer.crs not set correctly
Status: | Closed | ||
---|---|---|---|
Priority: | Low | ||
Assignee: | |||
Category: | Projection Support | ||
Affected QGIS version: | Regression?: | No | |
Operating System: | Windows | Easy fix?: | No |
Pull Request or Patch supplied: | Resolution: | fixed | |
Crashes QGIS or corrupts data: | Copied to github as #: | 12721 |
Description
I am developing a python plugin operating on data imported from GPX file. My project is to UTM 51N spatialrefsys with On-the-fly transformation enabled and the gpx waypoints layer is in WGS-84 (see attached project file).
I want to reproject my waypoints to project SRS (UTM 51N) a do some calculation. I tried the following code but it does not work (newpoint coordinates are not in UTM)
renderer = self.canvas.mapRenderer()
newpoint = renderer.layerToMapCoordinates(waypointslayer, point)
I found out that it is because waypointslayer.crs is set to UTM in the API even though the GUI shows "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" in the layer properties dialog. If I set the crs manually
srs = QgsCoordinateReferenceSystem(4326)
vectorlayer.setCrs(srs)
the transformations starts to work. I verified this in both 1.4.0 Windows standalone and trunk r13321 from OSGeo4W.
lrend = vectorlayer.renderer()
self.tell("project %s %s" % (renderer.hasCrsTransformEnabled(), renderer.destinationSrs().toWkt()))
self.tell("vectorlayer %s" % vectorlayer.crs().toWkt())
for i, point in enumerate(vlist):
self.tell("reprojecting %s from layer %s" % (point, vectorlayer.name()))
#vlist[i]= renderer.layerToMapCoordinates(vectorlayer, QgsPoint(pointr0, pointr1))
vlist[i]= renderer.layerToMapCoordinates(vectorlayer, point)
self.tell("reprojected as %s" % vlist[i])
return vlist
Associated revisions
Fixed CRS for OSM and GPX providers. Should fix #2661.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13425 c8812cc2-4d05-0410-92ff-de0c093fc19c
Fixed CRS for OSM and GPX providers. Should fix #2661.
git-svn-id: http://svn.osgeo.org/qgis/trunk@13425 c8812cc2-4d05-0410-92ff-de0c093fc19c
History
#1
Updated by Václav Řehák over 14 years ago
Sorry for the formating issues and for accidentally keeping my debug code at the end.
This is the code I use to reproject my points:
renderer = self.canvas.mapRenderer() newpoint = renderer.layerToMapCoordinates(waypointslayer, point)
and I need to add this to make it work
srs = [[QgsCoordinateReferenceSystem]](4326) waypointslayer.setCrs(srs)
#2
Updated by Martin Dobias over 14 years ago
- Resolution set to fixed
- Status changed from Open to Closed
fixed in 986da374 (SVN r13426).