From 39c6e23c08b4c993e0baf2787b565e85456bc26c Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Tue, 1 May 2018 10:14:08 +0700 Subject: [PATCH] [needs-docs][processing] add help and clarity to the define current projection algorithm --- python/plugins/processing/algs/help/qgis.yaml | 6 ++++++ .../processing/algs/qgis/DefineProjection.py | 20 ++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/python/plugins/processing/algs/help/qgis.yaml b/python/plugins/processing/algs/help/qgis.yaml index 95b929848c05..a6dc03c89f6d 100644 --- a/python/plugins/processing/algs/help/qgis.yaml +++ b/python/plugins/processing/algs/help/qgis.yaml @@ -550,3 +550,9 @@ qgis:voronoipolygons: > qgis:zonalstatistics: + +qgis:definecurrentprojection: > + This algorithm sets an existing layer's projection to the provided CRS. Contrary to the "Assign projection" algorithm, it will not output a new layer. + + For shapefile datasets, the .prj and .qpj files will be overwritten - or created if missing - to match the provided CRS. + diff --git a/python/plugins/processing/algs/qgis/DefineProjection.py b/python/plugins/processing/algs/qgis/DefineProjection.py index 68bb53c20abe..4c7d46aa51d1 100644 --- a/python/plugins/processing/algs/qgis/DefineProjection.py +++ b/python/plugins/processing/algs/qgis/DefineProjection.py @@ -56,7 +56,7 @@ def __init__(self): def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT, self.tr('Input Layer'), types=[QgsProcessing.TypeVectorAnyGeometry])) - self.addParameter(QgsProcessingParameterCrs(self.CRS, 'Output CRS')) + self.addParameter(QgsProcessingParameterCrs(self.CRS, 'CRS')) self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT, self.tr('Layer with projection'))) @@ -64,7 +64,7 @@ def name(self): return 'definecurrentprojection' def displayName(self): - return self.tr('Define current projection') + return self.tr('Define layer projection') def flags(self): return super().flags() | QgsProcessingAlgorithm.FlagNoThreading @@ -81,15 +81,17 @@ def processAlgorithm(self, parameters, context, feedback): if dsPath.lower().endswith('.shp'): dsPath = dsPath[:-4] - wkt = crs.toWkt() - with open(dsPath + '.prj', 'w') as f: - f.write(wkt) - - qpjFile = dsPath + '.qpj' - if os.path.exists(qpjFile): - with open(qpjFile, 'w') as f: + wkt = crs.toWkt() + with open(dsPath + '.prj', 'w') as f: f.write(wkt) + qpjFile = dsPath + '.qpj' + if os.path.exists(qpjFile): + with open(qpjFile, 'w') as f: + f.write(wkt) + else: + feedback.pushConsoleInfo(tr("Data source isn't a shapefile, skipping .prj/.qpj creation")) + layer.setCrs(crs) layer.triggerRepaint()