Skip to content

Commit

Permalink
[processing] Fix "Add geometry attributes" handling of multipoint geom
Browse files Browse the repository at this point in the history
For multipoints, export the count of geometries only
  • Loading branch information
nyalldawson committed Feb 24, 2019
1 parent 0efa0b1 commit ec12183
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 14 deletions.
28 changes: 14 additions & 14 deletions python/plugins/processing/algs/qgis/ExportGeometryInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ def processAlgorithm(self, parameters, context, feedback):
new_fields.append(QgsField('straightdis', QVariant.Double))
new_fields.append(QgsField('sinuosity', QVariant.Double))
else:
new_fields.append(QgsField('xcoord', QVariant.Double))
new_fields.append(QgsField('ycoord', QVariant.Double))
if QgsWkbTypes.hasZ(source.wkbType()):
self.export_z = True
new_fields.append(QgsField('zcoord', QVariant.Double))
if QgsWkbTypes.hasM(source.wkbType()):
self.export_m = True
new_fields.append(QgsField('mvalue', QVariant.Double))
if QgsWkbTypes.isMultiType(source.wkbType()):
new_fields.append(QgsField('numparts', QVariant.Int))
else:
new_fields.append(QgsField('xcoord', QVariant.Double))
new_fields.append(QgsField('ycoord', QVariant.Double))
if QgsWkbTypes.hasZ(source.wkbType()):
self.export_z = True
new_fields.append(QgsField('zcoord', QVariant.Double))
if QgsWkbTypes.hasM(source.wkbType()):
self.export_m = True
new_fields.append(QgsField('mvalue', QVariant.Double))

fields = QgsProcessingUtils.combineFields(fields, new_fields)
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
Expand Down Expand Up @@ -178,21 +181,18 @@ def processAlgorithm(self, parameters, context, feedback):
return {self.OUTPUT: dest_id}

def point_attributes(self, geometry):
pt = None
attrs = []
if not geometry.isMultipart():
pt = geometry.constGet()
else:
if geometry.numGeometries() > 0:
pt = geometry.geometryN(0)
attrs = []
if pt:
attrs.append(pt.x())
attrs.append(pt.y())
# add point z/m
if self.export_z:
attrs.append(pt.z())
if self.export_m:
attrs.append(pt.m())
else:
attrs = [geometry.constGet().numGeometries()]
return attrs

def line_attributes(self, geometry):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ add_geometry_info_multipoint.xsd"
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:add_geometry_info_multipoint fid="points.9">
<ogr:d>5</ogr:d>
<ogr:numparts xsi:nil="true"/>
</ogr:add_geometry_info_multipoint>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_info_multipoint fid="points.0">
<ogr:geometryProperty><gml:MultiPoint srsName="EPSG:4326"><gml:pointMember><gml:Point><gml:coordinates>1,1</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>2,2</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>3,3</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint></ogr:geometryProperty>
<ogr:d>1</ogr:d>
<ogr:numparts>3</ogr:numparts>
</ogr:add_geometry_info_multipoint>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_info_multipoint fid="points.3">
<ogr:geometryProperty><gml:MultiPoint srsName="EPSG:4326"><gml:pointMember><gml:Point><gml:coordinates>5,2</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>4,1</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint></ogr:geometryProperty>
<ogr:d>2</ogr:d>
<ogr:numparts>2</ogr:numparts>
</ogr:add_geometry_info_multipoint>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_info_multipoint fid="points.5">
<ogr:geometryProperty><gml:MultiPoint srsName="EPSG:4326"><gml:pointMember><gml:Point><gml:coordinates>0,-5</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>8,-1</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint></ogr:geometryProperty>
<ogr:d>3</ogr:d>
<ogr:numparts>2</ogr:numparts>
</ogr:add_geometry_info_multipoint>
</gml:featureMember>
<gml:featureMember>
<ogr:add_geometry_info_multipoint fid="points.7">
<ogr:geometryProperty><gml:MultiPoint srsName="EPSG:4326"><gml:pointMember><gml:Point><gml:coordinates>7,-1</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>0,-1</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint></ogr:geometryProperty>
<ogr:d>4</ogr:d>
<ogr:numparts>2</ogr:numparts>
</ogr:add_geometry_info_multipoint>
</gml:featureMember>
</ogr:FeatureCollection>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="add_geometry_info_multipoint" type="ogr:add_geometry_info_multipoint_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="add_geometry_info_multipoint_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:MultiPointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="d" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="numparts" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
12 changes: 12 additions & 0 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,18 @@ tests:
name: expected/export_multiline_info.gml
type: vector

- algorithm: qgis:exportaddgeometrycolumns
name: Export multipoint info
params:
CALC_METHOD: 0
INPUT:
name: multipoints.gml|layername=multipoints
type: vector
results:
OUTPUT:
name: expected/add_geometry_info_multipoint.gml
type: vector

- algorithm: qgis:texttofloat
name: Text to float
params:
Expand Down

0 comments on commit ec12183

Please sign in to comment.