Closed rduivenvoorde closed 12 years ago
this is the check:
p = QgsProject.instance() error = '' (proj4string,ok) = p.readEntry("SpatialRefSys","ProjectCRSProj4String")
can you check in the python console what this check will return (the values of "ok" and "proj4string") ?
On 2011-12-19 11:25, Alessandro Pasotti wrote:
this is the check:
p = QgsProject.instance() error = '' (proj4string,ok) = p.readEntry("SpatialRefSys","ProjectCRSProj4String")
can you check in the python console what this check will return (the values of "ok" and "proj4string") ?
p = QgsProject.instance() error = ''
(proj4string,ok) = p.readEntry("SpatialRefSys","ProjectCRSProj4String") proj4string PyQt4.QtCore.QString(u'') ok False
Ah, but wait, you are checking from the project file (xml).
But if I start a new project, it apparently is not yet available in there? OR the way the OpenLayers plugin is setting the crs is not reflected in the QgsProject or so? (as said, I'm not sure where this issue exactly stems from)
Richard
I'm not sure where QgsProject.instance() gets its data but since it works even when you start with a new project and set a project CRS manually (not programmatically) I assume it works on an in-memory object.
On 2011-12-19 11:49, Alessandro Pasotti wrote:
I'm not sure where QgsProject.instance() gets its data but since it works even when you start with a new project and set a project CRS manually (not programmatically) I assume it works on an in-memory object.
Looking into the OpenLayers plugin, they set the map srs like this:
def __setMapSrsGoogle(self): mapCanvas = self.iface.mapCanvas()
mapCanvas.mapRenderer().setProjectionsEnabled(True)
theCoodRS = mapCanvas.mapRenderer().destinationSrs()
if theCoodRS != self.__coordRSGoogle:
coodTrans = QgsCoordinateTransform(theCoodRS, self.__coordRSGoogle)
extMap = mapCanvas.extent()
extMap = coodTrans.transform(extMap,
QgsCoordinateTransform.ForwardTransform) mapCanvas.mapRenderer().setDestinationSrs(self.coordRSGoogle) mapCanvas.freeze(False) mapCanvas.setMapUnits(self.coordRSGoogle.mapUnits()) mapCanvas.setExtent(extMap)
so if i ask: iface.mapCanvas().mapRenderer().destinationSrs()
I always get an QgsCoordinateReferenceSystem back.
So actually I think a project always has an 'projection set'? Even a freshly opened Qgis has one... But apparently that is not known by the QgsProject?
If that is the case, You could maybe just skip the check?
Richard
Skipping the check is not a good idea: geocoding needs a CRS to trasform into.
A new project can have a default CRS (see QGIS global options ) but normally doesn't.
I suspect that that setting a CRS for the mapCanvas is not the same as setting a CRS for the project.
not sure about the crs for mapcanvas and project (though I think they are always the same... there is just one mapcanvas per project ins't it)?
Even if you choose 'prompt for crs' in the global options. The mapcanvas renderer always has a destinationSrs() (just tried)
Anyway, it is what you prefer. I just saw a message in a project for which I was sure there was a crs defined...
One option is maybe to check for the destinationSrs also?
Fixed
not sure if it is a real bug, but
As said, maybe it has something to do with the fact that because the projection is set via the OpenLayer plugin that this change is not detected or so..?