Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#1339 closed bug (invalid)

Can't set projection to WGS84 UTM Zone 15N

Reported by: vedgewater Owned by: nobody
Priority: major: does not work as expected Milestone:
Component: Projection Support Version: 0.11.0
Keywords: UTM SRSID Cc:
Must Fix for Release: No Platform: Gentoo
Platform Version: Awaiting user input: no

Description

Hello there,

I'm trying to write a python plugin which needs to determine georeferencing info for layers.

I set a layer's projection by right clicking the layer, selecting properties and then selecting Change SRS under the general tab.

I select SRSID 2992 ( UTM Z 15N ) and click apply

In my python code, I am doing something like this:

srsID = regionLayer.srs().srsid()

srsID always comes out as 3344 instead of 2992!

Other queries through srs() also seem to say the layer is of longlat instead of UTM as I tried to define.

Is this a known issue?

Regards,

Vince

Attachments (1)

boundaryPolygons_004.tgz (1.2 KB ) - added by vedgewater 16 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by fpacheco, 16 years ago

On Linux (Ubuntu) and Windows: I loaded a layer with custom projection (South America LCC: +proj=lcc +lat_1=-5 +lat_2=-42 +lat_0=-32 +lon_0=-60 +x_0=0 +y_0=0 +ellps=aust_SA +units=m no_defs) from a PostgreSQL/PostGIS database. Then I selected the layer with the mouse. I opened the Python console and wrote iface.activeLayer().srs().srsid(). I get the following result 1001.

I loaded a layer with UTM WGS84 15N from a Shape File. Then I selected the layer with the mouse. I opened the Python console and wrote iface.activeLayer().srs().srid(). I get the following result 2992.

I set a layer's projection by right clicking the layer, selecting properties and then selecting Change SRS under the general tab. I changed the SRC several times in the same layer and ask again with iface.activeLayer().srs().srsid() and the result always change, then I believe that in my case it worked smoothly.

Could you please send me more information?. Regards, Fernando.

by vedgewater, 16 years ago

Attachment: boundaryPolygons_004.tgz added

comment:2 by vedgewater, 16 years ago

Hi Fernando,

Sorry for not getting back to you sooner, I have been away last week.

Using python console, I am now able to reproduce the error....

If you:

1 Open the attached shape file in QGIS (it's lat/lon) 2 Save the this as a QGIS workspace 3 Right click the layer, properties, General tab, change SRS, select ID 2992 4 Hit Apply, then OK 5 save the workspace 6 Close QGIS 7 Open QGIS 8 Open last used workspace 9 Check through properties again, it should show the layer as UTM 10 Open python console: 11 iface.activeLayer().srs().srsid()

i get 2992

12 Close and re-open QGIS 13 Open the project again and type the following into python console:

def getVectorLayerByName(myName):

mc = iface.getMapCanvas() nLayers = mc.layerCount() for l in range(nLayers):

layer = mc.getZpos(l) if str(layer.name()) == str(myName):

vlayer = QgsVectorLayer(str(layer.source()), str(myName), str(layer.getDataProvider().name())) if vlayer.isValid():

return vlayer

regionLayer = getVectorLayerByName("boundaryPolygons_004")

regionLayer.srs().srsid()

i get 3344

now type iface.activeLayer().srs().srsid()

i get 2992

I think this might be something to do with changing the SRS in properties only being saved in the workspace and not in the layer itself. If I then save the shape file as a different layer...

(right click layer, save as...)

Add the layer and then in the console:

regionLayer = getVectorLayerByName("boundaryPolygons_005") regionLayer.srs().srsid()

2992

iface.activeLayer().srs().srsid()

2992

Then it's working consistently.

Please bear with me as I'm new to QGIS!

Hopefully you can re-produce this now at your end. Please let me know if for some reason you can't see the layer I attached.

Regards,

Vince

comment:3 by vedgewater, 16 years ago

Hello again,

I've just realised that the code above has been strangely formatted, it's meant to read like

def getVectorLayerByName(myName):
  mc = iface.getMapCanvas()
  nLayers = mc.layerCount()
  for l in range(nLayers):
    layer = mc.getZpos(l)
    if str(layer.name()) == str(myName):
      vlayer = QgsVectorLayer(str(layer.source()),  str(myName),  str(layer.getDataProvider().name()))
      if vlayer.isValid():
        return vlayer
        
regionLayer = getVectorLayerByName("boundaryPolygons_004")

regionLayer.srs().srsid()

Regards,

Vince

comment:4 by fpacheco, 16 years ago

Vince, If you just want to get the layer by name and then take for example the srsid believe that this code would be sufficient:

def getVectorLayerByName(myName):
  mc = iface.getMapCanvas()
  nLayers = mc.layerCount()
  for l in range(nLayers):
    layer = mc.getZpos(l)
    if str(layer.name()) == str(myName):
      return layer
      

regionLayer = getVectorLayerByName("boundaryPolygons_004")

regionLayer.srs().srsid()

Please, try it and tell me the results. Regards, Fernando.

comment:5 by vedgewater, 16 years ago

Hi Fernando,

Thanks for your help, I can use the code you posted without needing to use the "save layer as" workaround in my previous post. It's returning the correct SRS now.

I guess returning vlayer in my original code was the problem.

I shall update my code now...

Shall I make as resolved (fixed) ?

Regards,

Vince

comment:6 by fpacheco, 16 years ago

Resolution: invalid
Status: newclosed

Is not a bug. Close.

comment:7 by (none), 15 years ago

Milestone: Version 1.0.0

Milestone Version 1.0.0 deleted

Note: See TracTickets for help on using tickets.