Skip to content

Commit 39c6e23

Browse files
authoredMay 1, 2018
[needs-docs][processing] add help and clarity to the define current projection algorithm
1 parent 3228654 commit 39c6e23

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed
 

‎python/plugins/processing/algs/help/qgis.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,9 @@ qgis:voronoipolygons: >
550550

551551
qgis:zonalstatistics:
552552

553+
554+
qgis:definecurrentprojection: >
555+
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.
556+
557+
For shapefile datasets, the .prj and .qpj files will be overwritten - or created if missing - to match the provided CRS.
558+

‎python/plugins/processing/algs/qgis/DefineProjection.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ def __init__(self):
5656
def initAlgorithm(self, config=None):
5757
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
5858
self.tr('Input Layer'), types=[QgsProcessing.TypeVectorAnyGeometry]))
59-
self.addParameter(QgsProcessingParameterCrs(self.CRS, 'Output CRS'))
59+
self.addParameter(QgsProcessingParameterCrs(self.CRS, 'CRS'))
6060
self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT,
6161
self.tr('Layer with projection')))
6262

6363
def name(self):
6464
return 'definecurrentprojection'
6565

6666
def displayName(self):
67-
return self.tr('Define current projection')
67+
return self.tr('Define layer projection')
6868

6969
def flags(self):
7070
return super().flags() | QgsProcessingAlgorithm.FlagNoThreading
@@ -81,15 +81,17 @@ def processAlgorithm(self, parameters, context, feedback):
8181
if dsPath.lower().endswith('.shp'):
8282
dsPath = dsPath[:-4]
8383

84-
wkt = crs.toWkt()
85-
with open(dsPath + '.prj', 'w') as f:
86-
f.write(wkt)
87-
88-
qpjFile = dsPath + '.qpj'
89-
if os.path.exists(qpjFile):
90-
with open(qpjFile, 'w') as f:
84+
wkt = crs.toWkt()
85+
with open(dsPath + '.prj', 'w') as f:
9186
f.write(wkt)
9287

88+
qpjFile = dsPath + '.qpj'
89+
if os.path.exists(qpjFile):
90+
with open(qpjFile, 'w') as f:
91+
f.write(wkt)
92+
else:
93+
feedback.pushConsoleInfo(tr("Data source isn't a shapefile, skipping .prj/.qpj creation"))
94+
9395
layer.setCrs(crs)
9496
layer.triggerRepaint()
9597

0 commit comments

Comments
 (0)
Please sign in to comment.