mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[processing] Fix simplify alg handling of null goemetry, add tests
This commit is contained in:
parent
f9e508c566
commit
5d97d03ad5
@ -74,16 +74,15 @@ class SimplifyGeometries(GeoAlgorithm):
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
for current, f in enumerate(features):
|
||||
featGeometry = f.geometry()
|
||||
attrs = f.attributes()
|
||||
pointsBefore += featGeometry.geometry().nCoordinates()
|
||||
newGeometry = featGeometry.simplify(tolerance)
|
||||
pointsAfter += newGeometry.geometry().nCoordinates()
|
||||
feature = QgsFeature()
|
||||
feature.setGeometry(newGeometry)
|
||||
feature.setAttributes(attrs)
|
||||
writer.addFeature(feature)
|
||||
for current, input_feature in enumerate(features):
|
||||
out_feature = input_feature
|
||||
if input_feature.geometry():
|
||||
input_geometry = input_feature.geometry()
|
||||
pointsBefore += input_geometry.geometry().nCoordinates()
|
||||
output_geometry = input_geometry.simplify(tolerance)
|
||||
pointsAfter += output_geometry.geometry().nCoordinates()
|
||||
out_feature.setGeometry(output_geometry)
|
||||
writer.addFeature(out_feature)
|
||||
progress.setPercentage(int(current * total))
|
||||
|
||||
del writer
|
||||
|
15
python/plugins/processing/tests/testdata/expected/simplify_lines.gfs
vendored
Normal file
15
python/plugins/processing/tests/testdata/expected/simplify_lines.gfs
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
<GMLFeatureClassList>
|
||||
<GMLFeatureClass>
|
||||
<Name>simplify_lines</Name>
|
||||
<ElementPath>simplify_lines</ElementPath>
|
||||
<GeometryType>2</GeometryType>
|
||||
<SRSName>EPSG:4326</SRSName>
|
||||
<DatasetSpecificInfo>
|
||||
<FeatureCount>7</FeatureCount>
|
||||
<ExtentXMin>-1.00000</ExtentXMin>
|
||||
<ExtentXMax>11.00000</ExtentXMax>
|
||||
<ExtentYMin>-3.00000</ExtentYMin>
|
||||
<ExtentYMax>5.00000</ExtentYMax>
|
||||
</DatasetSpecificInfo>
|
||||
</GMLFeatureClass>
|
||||
</GMLFeatureClassList>
|
48
python/plugins/processing/tests/testdata/expected/simplify_lines.gml
vendored
Normal file
48
python/plugins/processing/tests/testdata/expected/simplify_lines.gml
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
<?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>-1</gml:X><gml:Y>-3</gml:Y></gml:coord>
|
||||
<gml:coord><gml:X>11</gml:X><gml:Y>5</gml:Y></gml:coord>
|
||||
</gml:Box>
|
||||
</gml:boundedBy>
|
||||
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_lines fid="lines.0">
|
||||
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,2 9,2 11,5</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
</ogr:simplify_lines>
|
||||
</gml:featureMember>
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_lines fid="lines.1">
|
||||
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>-1,-1 1,-1</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
</ogr:simplify_lines>
|
||||
</gml:featureMember>
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_lines fid="lines.2">
|
||||
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>2,0 3,3</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
</ogr:simplify_lines>
|
||||
</gml:featureMember>
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_lines fid="lines.3">
|
||||
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>3,1 5,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
</ogr:simplify_lines>
|
||||
</gml:featureMember>
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_lines fid="lines.4">
|
||||
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>7,-3 10,-3</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
</ogr:simplify_lines>
|
||||
</gml:featureMember>
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_lines fid="lines.5">
|
||||
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,-3 10,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
</ogr:simplify_lines>
|
||||
</gml:featureMember>
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_lines fid="lines.6">
|
||||
</ogr:simplify_lines>
|
||||
</gml:featureMember>
|
||||
</ogr:FeatureCollection>
|
15
python/plugins/processing/tests/testdata/expected/simplify_multilines.gfs
vendored
Normal file
15
python/plugins/processing/tests/testdata/expected/simplify_multilines.gfs
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
<GMLFeatureClassList>
|
||||
<GMLFeatureClass>
|
||||
<Name>simplify_multilines</Name>
|
||||
<ElementPath>simplify_multilines</ElementPath>
|
||||
<GeometryType>5</GeometryType>
|
||||
<SRSName>EPSG:4326</SRSName>
|
||||
<DatasetSpecificInfo>
|
||||
<FeatureCount>4</FeatureCount>
|
||||
<ExtentXMin>-1.00000</ExtentXMin>
|
||||
<ExtentXMax>5.58042</ExtentXMax>
|
||||
<ExtentYMin>-1.00000</ExtentYMin>
|
||||
<ExtentYMax>4.11977</ExtentYMax>
|
||||
</DatasetSpecificInfo>
|
||||
</GMLFeatureClass>
|
||||
</GMLFeatureClassList>
|
33
python/plugins/processing/tests/testdata/expected/simplify_multilines.gml
vendored
Normal file
33
python/plugins/processing/tests/testdata/expected/simplify_multilines.gml
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
<?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>-1</gml:X><gml:Y>-1</gml:Y></gml:coord>
|
||||
<gml:coord><gml:X>5.58042226487524</gml:X><gml:Y>4.119769673704415</gml:Y></gml:coord>
|
||||
</gml:Box>
|
||||
</gml:boundedBy>
|
||||
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_multilines fid="lines.1">
|
||||
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>-1,-1 1,-1</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
|
||||
</ogr:simplify_multilines>
|
||||
</gml:featureMember>
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_multilines fid="lines.2">
|
||||
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>3,1 5,1</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>5.024184261036468,2.414779270633399 5,1</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
|
||||
</ogr:simplify_multilines>
|
||||
</gml:featureMember>
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_multilines fid="lines.3">
|
||||
</ogr:simplify_multilines>
|
||||
</gml:featureMember>
|
||||
<gml:featureMember>
|
||||
<ogr:simplify_multilines fid="lines.4">
|
||||
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>2,0 3,3</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>2.944337811900192,4.04721689059501 5.459500959692898,4.119769673704415</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>3,3 5.58042226487524,2.946833013435702</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
|
||||
</ogr:simplify_multilines>
|
||||
</gml:featureMember>
|
||||
</ogr:FeatureCollection>
|
@ -916,3 +916,26 @@ tests:
|
||||
name: expected/extract_nodes_lines.gml
|
||||
type: vector
|
||||
|
||||
- algorithm: qgis:simplifygeometries
|
||||
name: Simplify (lines)
|
||||
params:
|
||||
INPUT:
|
||||
name: lines.gml
|
||||
type: vector
|
||||
TOLERANCE: 1.0
|
||||
results:
|
||||
OUTPUT:
|
||||
name: expected/simplify_lines.gml
|
||||
type: vector
|
||||
|
||||
- algorithm: qgis:simplifygeometries
|
||||
name: Simplify (multilines)
|
||||
params:
|
||||
INPUT:
|
||||
name: multilines.gml
|
||||
type: vector
|
||||
TOLERANCE: 1.0
|
||||
results:
|
||||
OUTPUT:
|
||||
name: expected/simplify_multilines.gml
|
||||
type: vector
|
||||
|
Loading…
x
Reference in New Issue
Block a user