[QGIS-trac] [Quantum GIS] #2661: QgsVectorLayer.crs not set
correctly
Quantum GIS
qgis at qgis.org
Sun Apr 18 08:54:25 EDT 2010
#2661: QgsVectorLayer.crs not set correctly
------------------------------------------------+---------------------------
Reporter: rehakv1 | Owner: nobody
Type: bug | Status: new
Priority: major: does not work as expected | Milestone: Version 1.5.0
Component: Projection Support | Version: 1.4.0
Keywords: | Platform_version:
Platform: Windows | Must_fix: No
Status_info: 0 |
------------------------------------------------+---------------------------
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(point[0], point[1]))
vlist[i]= renderer.layerToMapCoordinates(vectorlayer, point)
self.tell("reprojected as %s" % vlist[i])
return vlist
--
Ticket URL: <http://trac.osgeo.org/qgis/ticket/2661>
Quantum GIS <http://qgis.org>
Quantum GIS is an Open Source GIS viewer/editor supporting OGR, PostGIS, and GRASS formats
More information about the QGIS-trac
mailing list