I have this problem accessing to the coordinate reference system(crs) of a raster layer map. I wonder if such thing is possible? I have used this xml from GDAL open map service to load in a raster layer(crs id 900913) to my stand-alone pyqgis application (http://www.gdal.org/frmt_wms_googlemaps_tms.xml) It displays the map just fine, but when I tried to draw an icon at a specific lat long position (crs id 4326), the icon appeared weirdly. I used the QgsCoordinateTransform class to convert the coordinates. Please advise me what I should do to get it right? I am very new to pyqgis. Thanks a ton!

1 Answer 1


I am not entirely sure if i understood your question right, but you flagged it with pyqgis and it is quite simple to get the CRS here.

#Assume that you have a raster layer of type QgsRasterLayer
crs = rasterlayer.crs()
print crs.toProj4()
# You can extract CRS of multiple layers and simply compare them with ==
crs1 == crs2 # Returns false, if the CRS is differnet

Using gdal it would look similar to this

rasterPath = "your file" #load as a gdal image 
srcImage = gdal.Open(str(rasterPath))
srcImage.GetProjection() # Returns a string, which contains the crs. The string can be processed by python string splitting or by turning it into a list
  • Thank you so much. That's exactly what I want. However my problem is not yet solved. I want to draw an icon at a specific (lat, long) onto a raster layer which I loaded from this xml file (gdal.org/frmt_wms_googlemaps_tms.xml). The raster layer is using EPSG:900913, so I converted my lat long position using QgsCoordinateTransform(4326->900913). The icon however appears way off the position i intended to draw. It seems like the origin of destination crs is not set properly. Anyone knows this problem?
    – Justin
    Commented Apr 12, 2013 at 3:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.