In a python script of qgis I load layers from different datasources using the QgsVectorLayer() and the QgsRasterLayer() commands. The coordinate reference systems of the data sources differs. Since I have for some sources only the permission to read, I cannot transfrom the CRS of the datasource. Thus, i have to change the CRS from old CRS into new CRS in the in memory layer. What is the way to do it, e.g. to get an extent() in the new coordinates?
Asked
Active
Viewed 1,953 times
1 Answers
3
sourceCrs = QgsCoordinateReferenceSystem(...source crs code...)
destCrs = QgsCoordinateReferenceSystem(...dest crs code...)
xform = QgsCoordinateTransform(sourceCrs, destCrs) #you can also do reverse convertion
if geom.transform(xform):
...your code...
where geom is the QgsGeometry you want to transform... in your case a geometry created from the extent coordinate using static method of QgsGeometry:
http://qgis.org/api/classQgsGeometry.html
Regards
ramiroaznar
- 4,419
- 2
- 14
- 29
Luigi Pirelli
- 2,013
- 14
- 19
processing.runalg("",... parameters of the command)
I whould use gdal_translate to convert geometries and to get all processign parameters:
- look for your command with: processing.alglist(
)
- look for your command parameters with: processing.alghelp(
)
– Luigi Pirelli Sep 26 '14 at 08:12