Skip to content
Permalink
Browse files

[processing] Add geometry info should add z/m values (fix #14659)

  • Loading branch information
nyalldawson committed Oct 10, 2016
1 parent 49459c8 commit 90aebd117d7a936e606d4993b0bc6ccc7f64080d
@@ -74,6 +74,8 @@ def processAlgorithm(self, progress):
geometryType = layer.geometryType()
fields = layer.fields()

export_z = False
export_m = False
if geometryType == QgsWkbTypes.PolygonGeometry:
areaName = vector.createUniqueFieldName('area', fields)
fields.append(QgsField(areaName, QVariant.Double))
@@ -87,6 +89,14 @@ def processAlgorithm(self, progress):
fields.append(QgsField(xName, QVariant.Double))
yName = vector.createUniqueFieldName('ycoord', fields)
fields.append(QgsField(yName, QVariant.Double))
if QgsWkbTypes.hasZ(layer.wkbType()):
export_z = True
zName = vector.createUniqueFieldName('zcoord', fields)
fields.append(QgsField(zName, QVariant.Double))
if QgsWkbTypes.hasM(layer.wkbType()):
export_m = True
zName = vector.createUniqueFieldName('mvalue', fields)
fields.append(QgsField(zName, QVariant.Double))

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
fields.toList(), layer.wkbType(), layer.crs())
@@ -130,6 +140,13 @@ def processAlgorithm(self, progress):
attrs.append(attr1)
if attr2 is not None:
attrs.append(attr2)

# add point z/m
if export_z:
attrs.append(inGeom.geometry().z())
if export_m:
attrs.append(inGeom.geometry().m())

outFeat.setAttributes(attrs)
writer.addFeature(outFeat)

@@ -0,0 +1,30 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>add_geometry_pointz</Name>
<ElementPath>add_geometry_pointz</ElementPath>
<GeometryType>-2147483647</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>9</FeatureCount>
<ExtentXMin>0.00000</ExtentXMin>
<ExtentXMax>8.00000</ExtentXMax>
<ExtentYMin>-5.00000</ExtentYMin>
<ExtentYMax>3.00000</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>xcoord</Name>
<ElementPath>xcoord</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>ycoord</Name>
<ElementPath>ycoord</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>zcoord</Name>
<ElementPath>zcoord</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
</GMLFeatureClass>
</GMLFeatureClassList>
@@ -0,0 +1,86 @@
<?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:Z>0</gml:Z></gml:coord>
<gml:coord><gml:X>8</gml:X><gml:Y>3</gml:Y><gml:Z>7</gml:Z></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:add_geometry_pointz fid="points.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,1,3</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:xcoord>1</ogr:xcoord>
<ogr:ycoord>1</ogr:ycoord>
<ogr:zcoord>3</ogr:zcoord>
</ogr:add_geometry_pointz>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_pointz fid="points.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3,0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:xcoord>3</ogr:xcoord>
<ogr:ycoord>3</ogr:ycoord>
<ogr:zcoord>0</ogr:zcoord>
</ogr:add_geometry_pointz>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_pointz fid="points.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:xcoord>2</ogr:xcoord>
<ogr:ycoord>2</ogr:ycoord>
<ogr:zcoord>2</ogr:zcoord>
</ogr:add_geometry_pointz>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_pointz fid="points.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,2,0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:xcoord>5</ogr:xcoord>
<ogr:ycoord>2</ogr:ycoord>
<ogr:zcoord>0</ogr:zcoord>
</ogr:add_geometry_pointz>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_pointz fid="points.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1,0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:xcoord>4</ogr:xcoord>
<ogr:ycoord>1</ogr:ycoord>
<ogr:zcoord>0</ogr:zcoord>
</ogr:add_geometry_pointz>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_pointz fid="points.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-5,5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:xcoord>0</ogr:xcoord>
<ogr:ycoord>-5</ogr:ycoord>
<ogr:zcoord>5</ogr:zcoord>
</ogr:add_geometry_pointz>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_pointz fid="points.6">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-1,7</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:xcoord>8</ogr:xcoord>
<ogr:ycoord>-1</ogr:ycoord>
<ogr:zcoord>7</ogr:zcoord>
</ogr:add_geometry_pointz>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_pointz fid="points.7">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7,-1,6</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:xcoord>7</ogr:xcoord>
<ogr:ycoord>-1</ogr:ycoord>
<ogr:zcoord>6</ogr:zcoord>
</ogr:add_geometry_pointz>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_pointz fid="points.8">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1,4</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:xcoord>0</ogr:xcoord>
<ogr:ycoord>-1</ogr:ycoord>
<ogr:zcoord>4</ogr:zcoord>
</ogr:add_geometry_pointz>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,15 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>pointsz</Name>
<ElementPath>pointsz</ElementPath>
<GeometryType>-2147483647</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>9</FeatureCount>
<ExtentXMin>0.00000</ExtentXMin>
<ExtentXMax>8.00000</ExtentXMax>
<ExtentYMin>-5.00000</ExtentYMin>
<ExtentYMax>3.00000</ExtentYMax>
</DatasetSpecificInfo>
</GMLFeatureClass>
</GMLFeatureClassList>
@@ -0,0 +1,59 @@
<?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:Z>0</gml:Z></gml:coord>
<gml:coord><gml:X>8</gml:X><gml:Y>3</gml:Y><gml:Z>7</gml:Z></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:pointsz fid="points.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,1,3</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:pointsz>
</gml:featureMember>
<gml:featureMember>
<ogr:pointsz fid="points.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3,0</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:pointsz>
</gml:featureMember>
<gml:featureMember>
<ogr:pointsz fid="points.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:pointsz>
</gml:featureMember>
<gml:featureMember>
<ogr:pointsz fid="points.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,2,0</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:pointsz>
</gml:featureMember>
<gml:featureMember>
<ogr:pointsz fid="points.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1,0</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:pointsz>
</gml:featureMember>
<gml:featureMember>
<ogr:pointsz fid="points.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-5,5</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:pointsz>
</gml:featureMember>
<gml:featureMember>
<ogr:pointsz fid="points.6">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-1,7</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:pointsz>
</gml:featureMember>
<gml:featureMember>
<ogr:pointsz fid="points.7">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7,-1,6</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:pointsz>
</gml:featureMember>
<gml:featureMember>
<ogr:pointsz fid="points.8">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1,4</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:pointsz>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -993,3 +993,15 @@ tests:
OUTPUT_LAYER:
name: expected/smoothed_lines_max_angle.gml
type: vector

- algorithm: qgis:exportaddgeometrycolumns
name: Add Geometry PointZ
params:
CALC_METHOD: '0'
INPUT:
name: pointsz.gml
type: vector
results:
OUTPUT:
name: expected/add_geometry_pointz.gml
type: vector
@@ -269,14 +269,15 @@ def simpleMeasure(geom, method=0, ellips=None, crs=None):
# 1 - project CRS
# 2 - ellipsoidal

if geom.wkbType() in [QgsWkbTypes.Point, QgsWkbTypes.Point25D]:
pt = geom.asPoint()
attr1 = pt.x()
attr2 = pt.y()
elif geom.wkbType() in [QgsWkbTypes.MultiPoint, QgsWkbTypes.MultiPoint25D]:
pt = geom.asMultiPoint()
attr1 = pt[0].x()
attr2 = pt[0].y()
if geom.type() == QgsWkbTypes.PointGeometry:
if not geom.isMultipart():
pt = geom.geometry()
attr1 = pt.x()
attr2 = pt.y()
else:
pt = geom.asMultiPoint()
attr1 = pt[0].x()
attr2 = pt[0].y()
else:
measure = QgsDistanceArea()

0 comments on commit 90aebd1

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