Skip to content

Commit dd0f183

Browse files
committedJul 18, 2017
[FEATURE] Followup addition of set Z/M values algs with Drop Z/M Values 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)
1 parent 340cf93 commit dd0f183

25 files changed

+223
-0
lines changed
 

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ qgis:distancetonearesthub: >
160160
qgis:dropgeometries: >
161161
This algorithm removes any geometries from an input layer and returns a layer containing only the feature attributes.
162162

163+
qgis:dropmzvalues: >
164+
This algorithm can remove any measure (M) or Z values from input geometries.
165+
163166
qgis:eliminateselectedpolygons: >
164167
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.
165168
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.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
DropMZValues.py
6+
--------------
7+
Date : July 2017
8+
Copyright : (C) 2017 by Nyall Dawson
9+
Email : nyall dot dawson at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Nyall Dawson'
21+
__date__ = 'July 2017'
22+
__copyright__ = '(C) 2017, Nyall Dawson'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive323
25+
26+
__revision__ = '$Format:%H$'
27+
28+
import os
29+
30+
from qgis.core import (QgsGeometry,
31+
QgsWkbTypes,
32+
QgsProcessingParameterBoolean)
33+
34+
35+
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm
36+
37+
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
38+
39+
40+
class DropMZValues(QgisFeatureBasedAlgorithm):
41+
42+
DROP_M_VALUES = 'DROP_M_VALUES'
43+
DROP_Z_VALUES = 'DROP_Z_VALUES'
44+
45+
def group(self):
46+
return self.tr('Vector geometry tools')
47+
48+
def __init__(self):
49+
super().__init__()
50+
self.drop_m = False
51+
self.drop_z = False
52+
53+
def name(self):
54+
return 'dropmzvalues'
55+
56+
def displayName(self):
57+
return self.tr('Drop M/Z Values')
58+
59+
def outputName(self):
60+
return self.tr('Z/M Dropped')
61+
62+
def tags(self):
63+
return self.tr('drop,set,convert,m,measure,z,25d,3d,values').split(',')
64+
65+
def initParameters(self, config=None):
66+
self.addParameter(QgsProcessingParameterBoolean(self.DROP_M_VALUES,
67+
self.tr('Drop M Values'), defaultValue=False))
68+
self.addParameter(QgsProcessingParameterBoolean(self.DROP_Z_VALUES,
69+
self.tr('Drop Z Values'), defaultValue=False))
70+
71+
def outputWkbType(self, inputWkb):
72+
wkb = inputWkb
73+
if self.drop_m:
74+
wkb = QgsWkbTypes.dropM(wkb)
75+
if self.drop_z:
76+
wkb = QgsWkbTypes.dropZ(wkb)
77+
return wkb
78+
79+
def prepareAlgorithm(self, parameters, context, feedback):
80+
self.drop_m = self.parameterAsBool(parameters, self.DROP_M_VALUES, context)
81+
self.drop_z = self.parameterAsBool(parameters, self.DROP_Z_VALUES, context)
82+
return True
83+
84+
def processFeature(self, feature, feedback):
85+
input_geometry = feature.geometry()
86+
if input_geometry:
87+
new_geom = input_geometry.geometry().clone()
88+
if self.drop_m:
89+
new_geom.dropMValue()
90+
if self.drop_z:
91+
new_geom.dropZValue()
92+
feature.setGeometry(QgsGeometry(new_geom))
93+
94+
return True

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from .DensifyGeometriesInterval import DensifyGeometriesInterval
5757
from .Difference import Difference
5858
from .DropGeometry import DropGeometry
59+
from .DropMZValues import DropMZValues
5960
from .ExtentFromLayer import ExtentFromLayer
6061
from .ExtractNodes import ExtractNodes
6162
from .FixGeometry import FixGeometry
@@ -245,6 +246,7 @@ def getAlgs(self):
245246
DensifyGeometriesInterval(),
246247
Difference(),
247248
DropGeometry(),
249+
DropMZValues(),
248250
ExtentFromLayer(),
249251
ExtractNodes(),
250252
FixGeometry(),
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation=""
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0</gml:X><gml:Y>-5</gml:Y></gml:coord>
10+
<gml:coord><gml:X>8</gml:X><gml:Y>3</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:set_m_value fid="points.0">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,1</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
<ogr:id>1</ogr:id>
18+
<ogr:id2>2</ogr:id2>
19+
</ogr:set_m_value>
20+
</gml:featureMember>
21+
<gml:featureMember>
22+
<ogr:set_m_value fid="points.1">
23+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3</gml:coordinates></gml:Point></ogr:geometryProperty>
24+
<ogr:id>2</ogr:id>
25+
<ogr:id2>1</ogr:id2>
26+
</ogr:set_m_value>
27+
</gml:featureMember>
28+
<gml:featureMember>
29+
<ogr:set_m_value fid="points.2">
30+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
31+
<ogr:id>3</ogr:id>
32+
<ogr:id2>0</ogr:id2>
33+
</ogr:set_m_value>
34+
</gml:featureMember>
35+
<gml:featureMember>
36+
<ogr:set_m_value fid="points.3">
37+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,2</gml:coordinates></gml:Point></ogr:geometryProperty>
38+
<ogr:id>4</ogr:id>
39+
<ogr:id2>2</ogr:id2>
40+
</ogr:set_m_value>
41+
</gml:featureMember>
42+
<gml:featureMember>
43+
<ogr:set_m_value fid="points.4">
44+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1</gml:coordinates></gml:Point></ogr:geometryProperty>
45+
<ogr:id>5</ogr:id>
46+
<ogr:id2>1</ogr:id2>
47+
</ogr:set_m_value>
48+
</gml:featureMember>
49+
<gml:featureMember>
50+
<ogr:set_m_value fid="points.5">
51+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-5</gml:coordinates></gml:Point></ogr:geometryProperty>
52+
<ogr:id>6</ogr:id>
53+
<ogr:id2>0</ogr:id2>
54+
</ogr:set_m_value>
55+
</gml:featureMember>
56+
<gml:featureMember>
57+
<ogr:set_m_value fid="points.6">
58+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
59+
<ogr:id>7</ogr:id>
60+
<ogr:id2>0</ogr:id2>
61+
</ogr:set_m_value>
62+
</gml:featureMember>
63+
<gml:featureMember>
64+
<ogr:set_m_value fid="points.7">
65+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
66+
<ogr:id>8</ogr:id>
67+
<ogr:id2>0</ogr:id2>
68+
</ogr:set_m_value>
69+
</gml:featureMember>
70+
<gml:featureMember>
71+
<ogr:set_m_value fid="points.8">
72+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
73+
<ogr:id>9</ogr:id>
74+
<ogr:id2>0</ogr:id2>
75+
</ogr:set_m_value>
76+
</gml:featureMember>
77+
</ogr:FeatureCollection>
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

‎python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,45 @@ tests:
546546
name: expected/set_z_value.shp
547547
type: vector
548548

549+
- algorithm: qgis:dropmzvalues
550+
name: Drop M Value
551+
params:
552+
INPUT:
553+
name: custom/pointszm.shp
554+
type: vector
555+
DROP_Z_VALUES: False
556+
DROP_M_VALUES: True
557+
results:
558+
OUTPUT:
559+
name: expected/m_dropped.shp
560+
type: vector
561+
562+
- algorithm: qgis:dropmzvalues
563+
name: Drop Z Value
564+
params:
565+
INPUT:
566+
name: custom/pointszm.shp
567+
type: vector
568+
DROP_Z_VALUES: True
569+
DROP_M_VALUES: False
570+
results:
571+
OUTPUT:
572+
name: expected/z_dropped.shp
573+
type: vector
574+
575+
- algorithm: qgis:dropmzvalues
576+
name: Drop ZM Value
577+
params:
578+
INPUT:
579+
name: custom/pointszm.shp
580+
type: vector
581+
DROP_Z_VALUES: True
582+
DROP_M_VALUES: True
583+
results:
584+
OUTPUT:
585+
name: expected/zm_dropped.shp
586+
type: vector
587+
549588
- algorithm: qgis:pointonsurface
550589
name: Point on polygon surface
551590
params:

0 commit comments

Comments
 (0)
Please sign in to comment.