Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] New algorithms to add Z/M values to existing geometries
Allows upgrading geometries to include these dimensions, or overwriting any existing Z/M values with a new value. Intended mostly as a test run for QgsProcessingFeatureBasedAlgorithm
- Loading branch information
1 parent
b9f2259
commit 340cf93
Showing
15 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
SetMValue.py | ||
-------------- | ||
Date : July 2017 | ||
Copyright : (C) 2017 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
*************************************************************************** | ||
""" | ||
|
||
__author__ = 'Nyall Dawson' | ||
__date__ = 'July 2017' | ||
__copyright__ = '(C) 2017, Nyall Dawson' | ||
|
||
# This will get replaced with a git SHA1 when you do a git archive323 | ||
|
||
__revision__ = '$Format:%H$' | ||
|
||
import os | ||
|
||
from qgis.core import (QgsGeometry, | ||
QgsWkbTypes, | ||
QgsProcessingParameterNumber) | ||
|
||
|
||
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm | ||
|
||
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0] | ||
|
||
|
||
class SetMValue(QgisFeatureBasedAlgorithm): | ||
|
||
M_VALUE = 'M_VALUE' | ||
|
||
def group(self): | ||
return self.tr('Vector geometry tools') | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.m_value = 0 | ||
|
||
def name(self): | ||
return 'setmvalue' | ||
|
||
def displayName(self): | ||
return self.tr('Set M Value') | ||
|
||
def outputName(self): | ||
return self.tr('M Added') | ||
|
||
def tags(self): | ||
return self.tr('set,add,m,measure,values').split(',') | ||
|
||
def initParameters(self, config=None): | ||
self.addParameter(QgsProcessingParameterNumber(self.M_VALUE, | ||
self.tr('M Value'), QgsProcessingParameterNumber.Double, defaultValue=0.0)) | ||
|
||
def outputWkbType(self, inputWkb): | ||
return QgsWkbTypes.addM(inputWkb) | ||
|
||
def prepareAlgorithm(self, parameters, context, feedback): | ||
self.m_value = self.parameterAsDouble(parameters, self.M_VALUE, context) | ||
return True | ||
|
||
def processFeature(self, feature, feedback): | ||
input_geometry = feature.geometry() | ||
if input_geometry: | ||
new_geom = input_geometry.geometry().clone() | ||
if QgsWkbTypes.hasM(new_geom.wkbType()): | ||
# addMValue won't alter existing M values, so drop them first | ||
new_geom.dropMValue() | ||
|
||
new_geom.addMValue(self.m_value) | ||
|
||
feature.setGeometry(QgsGeometry(new_geom)) | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
SetZValue.py | ||
-------------- | ||
Date : July 2017 | ||
Copyright : (C) 2017 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
*************************************************************************** | ||
""" | ||
|
||
__author__ = 'Nyall Dawson' | ||
__date__ = 'July 2017' | ||
__copyright__ = '(C) 2017, Nyall Dawson' | ||
|
||
# This will get replaced with a git SHA1 when you do a git archive323 | ||
|
||
__revision__ = '$Format:%H$' | ||
|
||
import os | ||
|
||
from qgis.core import (QgsGeometry, | ||
QgsWkbTypes, | ||
QgsProcessingParameterNumber) | ||
|
||
|
||
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm | ||
|
||
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0] | ||
|
||
|
||
class SetZValue(QgisFeatureBasedAlgorithm): | ||
|
||
Z_VALUE = 'Z_VALUE' | ||
|
||
def group(self): | ||
return self.tr('Vector geometry tools') | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.z_value = 0 | ||
|
||
def name(self): | ||
return 'setzvalue' | ||
|
||
def displayName(self): | ||
return self.tr('Set Z Value') | ||
|
||
def outputName(self): | ||
return self.tr('Z Added') | ||
|
||
def tags(self): | ||
return self.tr('set,add,z,25d,3d,values').split(',') | ||
|
||
def initParameters(self, config=None): | ||
self.addParameter(QgsProcessingParameterNumber(self.Z_VALUE, | ||
self.tr('Z Value'), QgsProcessingParameterNumber.Double, defaultValue=0.0)) | ||
|
||
def outputWkbType(self, inputWkb): | ||
return QgsWkbTypes.addZ(inputWkb) | ||
|
||
def prepareAlgorithm(self, parameters, context, feedback): | ||
self.z_value = self.parameterAsDouble(parameters, self.Z_VALUE, context) | ||
return True | ||
|
||
def processFeature(self, feature, feedback): | ||
input_geometry = feature.geometry() | ||
if input_geometry: | ||
new_geom = input_geometry.geometry().clone() | ||
if QgsWkbTypes.hasZ(new_geom.wkbType()): | ||
# addZValue won't alter existing Z values, so drop them first | ||
new_geom.dropZValue() | ||
|
||
new_geom.addZValue(self.z_value) | ||
|
||
feature.setGeometry(QgsGeometry(new_geom)) | ||
|
||
return True |
Binary file not shown.
1 change: 1 addition & 0 deletions
1
python/plugins/processing/tests/testdata/expected/set_m_value.prj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] |
1 change: 1 addition & 0 deletions
1
python/plugins/processing/tests/testdata/expected/set_m_value.qpj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] |
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions
1
python/plugins/processing/tests/testdata/expected/set_z_value.prj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] |
1 change: 1 addition & 0 deletions
1
python/plugins/processing/tests/testdata/expected/set_z_value.qpj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters