Skip to content
Permalink
Browse files

[FEATURE] Followup addition of set Z/M values algs with Drop Z/M Valu…

…es algorithm

Allows easy access to drop any z or m values present in a layer (e.g. if
required for compatibility with a database destination, etc)
  • Loading branch information
nyalldawson committed Jul 17, 2017
1 parent 340cf93 commit dd0f18355b4bd482b4b868ffdce6c7cb427126b6
Showing with 223 additions and 0 deletions.
  1. +3 −0 python/plugins/processing/algs/help/qgis.yaml
  2. +94 −0 python/plugins/processing/algs/qgis/DropMZValues.py
  3. +2 −0 python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
  4. BIN python/plugins/processing/tests/testdata/custom/pointszm.dbf
  5. +1 −0 python/plugins/processing/tests/testdata/custom/pointszm.prj
  6. +1 −0 python/plugins/processing/tests/testdata/custom/pointszm.qpj
  7. BIN python/plugins/processing/tests/testdata/custom/pointszm.shp
  8. BIN python/plugins/processing/tests/testdata/custom/pointszm.shx
  9. BIN python/plugins/processing/tests/testdata/expected/m_dropped.dbf
  10. +1 −0 python/plugins/processing/tests/testdata/expected/m_dropped.prj
  11. +1 −0 python/plugins/processing/tests/testdata/expected/m_dropped.qpj
  12. BIN python/plugins/processing/tests/testdata/expected/m_dropped.shp
  13. BIN python/plugins/processing/tests/testdata/expected/m_dropped.shx
  14. +77 −0 python/plugins/processing/tests/testdata/expected/set_m_value.gml
  15. BIN python/plugins/processing/tests/testdata/expected/z_dropped.dbf
  16. +1 −0 python/plugins/processing/tests/testdata/expected/z_dropped.prj
  17. +1 −0 python/plugins/processing/tests/testdata/expected/z_dropped.qpj
  18. BIN python/plugins/processing/tests/testdata/expected/z_dropped.shp
  19. BIN python/plugins/processing/tests/testdata/expected/z_dropped.shx
  20. BIN python/plugins/processing/tests/testdata/expected/zm_dropped.dbf
  21. +1 −0 python/plugins/processing/tests/testdata/expected/zm_dropped.prj
  22. +1 −0 python/plugins/processing/tests/testdata/expected/zm_dropped.qpj
  23. BIN python/plugins/processing/tests/testdata/expected/zm_dropped.shp
  24. BIN python/plugins/processing/tests/testdata/expected/zm_dropped.shx
  25. +39 −0 python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
@@ -160,6 +160,9 @@ qgis:distancetonearesthub: >
qgis:dropgeometries: >
This algorithm removes any geometries from an input layer and returns a layer containing only the feature attributes.

qgis:dropmzvalues: >
This algorithm can remove any measure (M) or Z values from input geometries.

qgis:eliminateselectedpolygons: >
This algorithm combines selected polygons of the input layer with certain adjacent polygons by erasing their common boundary. The adjacent polygon can be either the one with the largest or smallest area or the one sharing the largest common boundary with the polygon to be eliminated. The selected features will always be eliminated whether the option "Use only selected features" is set or not.
Eliminate is normally used to get rid of sliver polygons, i.e. tiny polygons that are a result of polygon intersection processes where boundaries of the inputs are similar but not identical.
@@ -0,0 +1,94 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
DropMZValues.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,
QgsProcessingParameterBoolean)


from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]


class DropMZValues(QgisFeatureBasedAlgorithm):

DROP_M_VALUES = 'DROP_M_VALUES'
DROP_Z_VALUES = 'DROP_Z_VALUES'

def group(self):
return self.tr('Vector geometry tools')

def __init__(self):
super().__init__()
self.drop_m = False
self.drop_z = False

def name(self):
return 'dropmzvalues'

def displayName(self):
return self.tr('Drop M/Z Values')

def outputName(self):
return self.tr('Z/M Dropped')

def tags(self):
return self.tr('drop,set,convert,m,measure,z,25d,3d,values').split(',')

def initParameters(self, config=None):
self.addParameter(QgsProcessingParameterBoolean(self.DROP_M_VALUES,
self.tr('Drop M Values'), defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.DROP_Z_VALUES,
self.tr('Drop Z Values'), defaultValue=False))

def outputWkbType(self, inputWkb):
wkb = inputWkb
if self.drop_m:
wkb = QgsWkbTypes.dropM(wkb)
if self.drop_z:
wkb = QgsWkbTypes.dropZ(wkb)
return wkb

def prepareAlgorithm(self, parameters, context, feedback):
self.drop_m = self.parameterAsBool(parameters, self.DROP_M_VALUES, context)
self.drop_z = self.parameterAsBool(parameters, self.DROP_Z_VALUES, context)
return True

def processFeature(self, feature, feedback):
input_geometry = feature.geometry()
if input_geometry:
new_geom = input_geometry.geometry().clone()
if self.drop_m:
new_geom.dropMValue()
if self.drop_z:
new_geom.dropZValue()
feature.setGeometry(QgsGeometry(new_geom))

return True
@@ -56,6 +56,7 @@
from .DensifyGeometriesInterval import DensifyGeometriesInterval
from .Difference import Difference
from .DropGeometry import DropGeometry
from .DropMZValues import DropMZValues
from .ExtentFromLayer import ExtentFromLayer
from .ExtractNodes import ExtractNodes
from .FixGeometry import FixGeometry
@@ -245,6 +246,7 @@ def getAlgs(self):
DensifyGeometriesInterval(),
Difference(),
DropGeometry(),
DropMZValues(),
ExtentFromLayer(),
ExtractNodes(),
FixGeometry(),
Binary file not shown.
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
@@ -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.
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
@@ -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.
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>0</gml:X><gml:Y>-5</gml:Y></gml:coord>
<gml:coord><gml:X>8</gml:X><gml:Y>3</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:set_m_value fid="points.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>1</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:set_m_value>
</gml:featureMember>
<gml:featureMember>
<ogr:set_m_value fid="points.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>2</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:set_m_value>
</gml:featureMember>
<gml:featureMember>
<ogr:set_m_value fid="points.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>3</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:set_m_value>
</gml:featureMember>
<gml:featureMember>
<ogr:set_m_value fid="points.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>4</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:set_m_value>
</gml:featureMember>
<gml:featureMember>
<ogr:set_m_value fid="points.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>5</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:set_m_value>
</gml:featureMember>
<gml:featureMember>
<ogr:set_m_value fid="points.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>6</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:set_m_value>
</gml:featureMember>
<gml:featureMember>
<ogr:set_m_value fid="points.6">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>7</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:set_m_value>
</gml:featureMember>
<gml:featureMember>
<ogr:set_m_value fid="points.7">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>8</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:set_m_value>
</gml:featureMember>
<gml:featureMember>
<ogr:set_m_value fid="points.8">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>9</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:set_m_value>
</gml:featureMember>
</ogr:FeatureCollection>
Binary file not shown.
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
@@ -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.
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
@@ -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.
@@ -546,6 +546,45 @@ tests:
name: expected/set_z_value.shp
type: vector

- algorithm: qgis:dropmzvalues
name: Drop M Value
params:
INPUT:
name: custom/pointszm.shp
type: vector
DROP_Z_VALUES: False
DROP_M_VALUES: True
results:
OUTPUT:
name: expected/m_dropped.shp
type: vector

- algorithm: qgis:dropmzvalues
name: Drop Z Value
params:
INPUT:
name: custom/pointszm.shp
type: vector
DROP_Z_VALUES: True
DROP_M_VALUES: False
results:
OUTPUT:
name: expected/z_dropped.shp
type: vector

- algorithm: qgis:dropmzvalues
name: Drop ZM Value
params:
INPUT:
name: custom/pointszm.shp
type: vector
DROP_Z_VALUES: True
DROP_M_VALUES: True
results:
OUTPUT:
name: expected/zm_dropped.shp
type: vector

- algorithm: qgis:pointonsurface
name: Point on polygon surface
params:

0 comments on commit dd0f183

Please sign in to comment.
You can’t perform that action at this time.