mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[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
This commit is contained in:
parent
b9f225905a
commit
340cf93f93
@ -503,6 +503,10 @@ qgis:selectbyexpression: >
|
||||
qgis:selectbylocation: >
|
||||
This algorithm creates a selection in a vector layer. The criteria for selecting features is based on the spatial relationship between each feature and the features in an additional layer.
|
||||
|
||||
qgis:setmvalue: >
|
||||
This algorithm sets the M value for geometries in a layer.
|
||||
|
||||
If M values already exist in the layer, they will be overwritten with the new value. If no M values exist, the geometry will be upgraded to include M values and the specified value used as the initial M value for all geometries.
|
||||
|
||||
qgis:setstyleforrasterlayer: >
|
||||
This algorithm sets the style of a raster layer. The style must be defined in a QML file.
|
||||
@ -510,6 +514,11 @@ qgis:setstyleforrasterlayer: >
|
||||
qgis:setstyleforvectorlayer: >
|
||||
This algorithm sets the style of a vector layer. The style must be defined in a QML file.
|
||||
|
||||
qgis:setzvalue: >
|
||||
This algorithm sets the Z value for geometries in a layer.
|
||||
|
||||
If Z values already exist in the layer, they will be overwritten with the new value. If no Z values exist, the geometry will be upgraded to include Z values and the specified value used as the initial Z value for all geometries.
|
||||
|
||||
qgis:simplifygeometries: >
|
||||
This algorithm simplifies the geometries in a line or polygon layer. It creates a new layer with the same features as the ones in the input layer, but with geometries containing a lower number of vertices.
|
||||
|
||||
|
@ -89,6 +89,8 @@ from .SelectByAttribute import SelectByAttribute
|
||||
from .SelectByExpression import SelectByExpression
|
||||
from .ServiceAreaFromLayer import ServiceAreaFromLayer
|
||||
from .ServiceAreaFromPoint import ServiceAreaFromPoint
|
||||
from .SetMValue import SetMValue
|
||||
from .SetZValue import SetZValue
|
||||
from .ShortestPathLayerToPoint import ShortestPathLayerToPoint
|
||||
from .ShortestPathPointToLayer import ShortestPathPointToLayer
|
||||
from .ShortestPathPointToPoint import ShortestPathPointToPoint
|
||||
@ -276,6 +278,8 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
SelectByExpression(),
|
||||
ServiceAreaFromLayer(),
|
||||
ServiceAreaFromPoint(),
|
||||
SetMValue(),
|
||||
SetZValue(),
|
||||
ShortestPathLayerToPoint(),
|
||||
ShortestPathPointToLayer(),
|
||||
ShortestPathPointToPoint(),
|
||||
|
86
python/plugins/processing/algs/qgis/SetMValue.py
Normal file
86
python/plugins/processing/algs/qgis/SetMValue.py
Normal file
@ -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
|
86
python/plugins/processing/algs/qgis/SetZValue.py
Normal file
86
python/plugins/processing/algs/qgis/SetZValue.py
Normal file
@ -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
|
BIN
python/plugins/processing/tests/testdata/expected/set_m_value.dbf
vendored
Normal file
BIN
python/plugins/processing/tests/testdata/expected/set_m_value.dbf
vendored
Normal file
Binary file not shown.
1
python/plugins/processing/tests/testdata/expected/set_m_value.prj
vendored
Normal file
1
python/plugins/processing/tests/testdata/expected/set_m_value.prj
vendored
Normal file
@ -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
python/plugins/processing/tests/testdata/expected/set_m_value.qpj
vendored
Normal file
1
python/plugins/processing/tests/testdata/expected/set_m_value.qpj
vendored
Normal file
@ -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"]]
|
BIN
python/plugins/processing/tests/testdata/expected/set_m_value.shp
vendored
Normal file
BIN
python/plugins/processing/tests/testdata/expected/set_m_value.shp
vendored
Normal file
Binary file not shown.
BIN
python/plugins/processing/tests/testdata/expected/set_m_value.shx
vendored
Normal file
BIN
python/plugins/processing/tests/testdata/expected/set_m_value.shx
vendored
Normal file
Binary file not shown.
BIN
python/plugins/processing/tests/testdata/expected/set_z_value.dbf
vendored
Normal file
BIN
python/plugins/processing/tests/testdata/expected/set_z_value.dbf
vendored
Normal file
Binary file not shown.
1
python/plugins/processing/tests/testdata/expected/set_z_value.prj
vendored
Normal file
1
python/plugins/processing/tests/testdata/expected/set_z_value.prj
vendored
Normal file
@ -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
python/plugins/processing/tests/testdata/expected/set_z_value.qpj
vendored
Normal file
1
python/plugins/processing/tests/testdata/expected/set_z_value.qpj
vendored
Normal file
@ -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"]]
|
BIN
python/plugins/processing/tests/testdata/expected/set_z_value.shp
vendored
Normal file
BIN
python/plugins/processing/tests/testdata/expected/set_z_value.shp
vendored
Normal file
Binary file not shown.
BIN
python/plugins/processing/tests/testdata/expected/set_z_value.shx
vendored
Normal file
BIN
python/plugins/processing/tests/testdata/expected/set_z_value.shx
vendored
Normal file
Binary file not shown.
@ -522,6 +522,30 @@ tests:
|
||||
name: expected/multiline_boundary.gml
|
||||
type: vector
|
||||
|
||||
- algorithm: qgis:setmvalue
|
||||
name: Set M Value
|
||||
params:
|
||||
INPUT:
|
||||
name: points.gml
|
||||
type: vector
|
||||
M_VALUE: 7
|
||||
results:
|
||||
OUTPUT:
|
||||
name: expected/set_m_value.shp
|
||||
type: vector
|
||||
|
||||
- algorithm: qgis:setzvalue
|
||||
name: Set Z Value
|
||||
params:
|
||||
INPUT:
|
||||
name: points.gml
|
||||
type: vector
|
||||
Z_VALUE: 6
|
||||
results:
|
||||
OUTPUT:
|
||||
name: expected/set_z_value.shp
|
||||
type: vector
|
||||
|
||||
- algorithm: qgis:pointonsurface
|
||||
name: Point on polygon surface
|
||||
params:
|
||||
|
Loading…
x
Reference in New Issue
Block a user