Skip to content

Commit

Permalink
[needs-docs][processing] add help and clarity to the define current p…
Browse files Browse the repository at this point in the history
…rojection algorithm
  • Loading branch information
nirvn committed May 1, 2018
1 parent 3228654 commit 39c6e23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions python/plugins/processing/algs/help/qgis.yaml
Expand Up @@ -550,3 +550,9 @@ qgis:voronoipolygons: >


qgis:zonalstatistics: 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.

20 changes: 11 additions & 9 deletions python/plugins/processing/algs/qgis/DefineProjection.py
Expand Up @@ -56,15 +56,15 @@ def __init__(self):
def initAlgorithm(self, config=None): def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT, self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
self.tr('Input Layer'), types=[QgsProcessing.TypeVectorAnyGeometry])) 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.addOutput(QgsProcessingOutputVectorLayer(self.INPUT,
self.tr('Layer with projection'))) self.tr('Layer with projection')))


def name(self): def name(self):
return 'definecurrentprojection' return 'definecurrentprojection'


def displayName(self): def displayName(self):
return self.tr('Define current projection') return self.tr('Define layer projection')


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


wkt = crs.toWkt() wkt = crs.toWkt()
with open(dsPath + '.prj', 'w') as f: 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) 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.setCrs(crs)
layer.triggerRepaint() layer.triggerRepaint()


Expand Down

0 comments on commit 39c6e23

Please sign in to comment.