Bug report #1339

Can't set projection to WGS84 UTM Zone 15N

Added by vedgewater - almost 12 years ago. Updated about 11 years ago.

Status:Closed
Priority:Low
Assignee:nobody -
Category:Projection Support
Affected QGIS version: Regression?:No
Operating System:Gentoo Easy fix?:No
Pull Request or Patch supplied: Resolution:invalid
Crashes QGIS or corrupts data: Copied to github as #:11399

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

boundaryPolygons_004.tgz (1.21 KB) vedgewater -, 2008-10-28 01:19 PM

History

#1 Updated by Fernando Pacheco - almost 12 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.

#2 Updated by vedgewater - almost 12 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

#3 Updated by vedgewater - almost 12 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

#4 Updated by Fernando Pacheco - almost 12 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.

#5 Updated by vedgewater - almost 12 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

#6 Updated by Fernando Pacheco - almost 12 years ago

  • Status changed from Open to Closed
  • Resolution set to invalid

Is not a bug. Close.

#7 Updated by Anonymous about 11 years ago

Milestone Version 1.0.0 deleted

Also available in: Atom PDF