Opened 10 years ago

Closed 10 years ago

#2661 closed bug (fixed)

QgsVectorLayer.crs not set correctly

Reported by: rehakv1 Owned by: nobody
Priority: major: does not work as expected Milestone: Version 1.5.0
Component: Projection Support Version: 1.4.0
Keywords: Cc:
Must Fix for Release: No Platform: Windows
Platform Version: Awaiting user input: no

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?(point[0], point[1])) vlist[i]= renderer.layerToMapCoordinates(vectorlayer, point) self.tell("reprojected as %s" % vlist[i])

return vlist

Attachments (1)

mili_test2.qgs (21.1 KB) - added by rehakv1 10 years ago.

Download all attachments as: .zip

Change History (3)

Changed 10 years ago by rehakv1

Attachment: mili_test2.qgs added

comment:1 in reply to:  description Changed 10 years ago by rehakv1

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)

comment:2 Changed 10 years ago by wonder

Resolution: fixed
Status: newclosed

fixed in r13425.

Note: See TracTickets for help on using tickets.