Accessing CRS info with pyqgis in a standalone application

المشرف العام

Administrator
طاقم الإدارة
I'm currently having trouble accessing and defining CRS information in a standalone application. I've read the API documentation and have tried it in the python console in QGIS 2.2.0. The python console works fine. I'm able to get the information I need. But the layers in my stand alone application do not have have valid CRS's. What is the reason for this?

Code:

import qgisfrom qgis.core import *from qgis.utils import *from qgis.gui import *import pdbQgsApplication.setPrefixPath( r"C:\OSGeo4W64\apps\qgis", True )QgsApplication.initQgis()app = QgsApplication([], True) print "Testing Json crs:"layer = QgsVectorLayer("E:/GIS_Data/GeoJsonRendering_Test/test.json" , 'musym', "ogr")QgsMapLayerRegistry.instance().addMapLayer(layer)print layer.isValid()print layer.crs().isValid()print layer.crs().authid()print "Testing QgsCoordinateReferenceSystem:"t = QgsCoordinateTransform()projSrc = QgsCoordinateReferenceSystem(3857, QgsCoordinateReferenceSystem.EpsgCrsId)projDest = QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId)print projSrc.isValid()print projDest.isValid()print "Testing memory layer CRS:"vTemp = QgsVectorLayer("Point?crs=EPSG:3857", "temporary_points", "memory")print vTemp.isValid()print vTemp.crs().isValid()Output:

Testing Json crs:TrueFalseTesting QgsCoordinateReferenceSystem:FalseFalseTesting memory layer CRS:TrueFalseSo I have two valid layers without valid projections.

Here is the output for that code in the python console in QGIS:

Testing Json crs:TrueTrueEPSG:3857Testing QgsCoordinateReferenceSystem:TrueTrueTesting memory layer CRS:TrueTrueSo my code only works in the QGIS python console. I'm assuming that I am not defining settings that need to be defined, but I"m not quite sure what I'm missing.



أكثر...
 
أعلى