Skip to content
Permalink
Browse files

[processing] Make split with lines output single part features

instead of keeping parts collected into a single multipart feature
  • Loading branch information
nyalldawson committed Nov 29, 2017
1 parent 38a66e5 commit f8bad4977d462aa90e974ca54eb391ebf4a1024d
@@ -6,7 +6,7 @@
<GeometryType>5</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>7</FeatureCount>
<FeatureCount>11</FeatureCount>
<ExtentXMin>-1.00000</ExtentXMin>
<ExtentXMax>11.00000</ExtentXMax>
<ExtentYMin>-3.00000</ExtentYMin>
@@ -23,26 +23,46 @@
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines fid="lines.2">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>2.0,1.86331771490359 2,2 3,2 3,3</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>2,0 2.0,1.86331771490359</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>2,0 2.0,1.86331771490359</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines fid="lines.3">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>4.21601489757914,1.0 5,1</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>3,1 4.21601489757914,1.0</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>2.0,1.86331771490359 2,2 3,2 3,3</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines fid="lines.4">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>8.5655671605538,-3.0 10,-3</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>7,-3 8.5655671605538,-3.0</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>3,1 4.21601489757914,1.0</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines fid="lines.5">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>6.91202704418487,-2.08797295581513 10,1</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>6,-3 6.91202704418487,-2.08797295581513</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>4.21601489757914,1.0 5,1</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines fid="lines.6">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>7,-3 8.5655671605538,-3.0</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines fid="lines.7">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>8.5655671605538,-3.0 10,-3</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines fid="lines.8">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>6,-3 6.91202704418487,-2.08797295581513</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines fid="lines.9">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>6.91202704418487,-2.08797295581513 10,1</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines fid="lines.10">
</ogr:split_lines_with_lines>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -6,11 +6,11 @@
<GeometryType>5</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>
<FeatureCount>4</FeatureCount>
<ExtentXMin>0.77654</ExtentXMin>
<ExtentXMax>8.57235</ExtentXMax>
<ExtentYMin>-4.24413</ExtentYMin>
<ExtentYMax>2.17905</ExtentYMax>
</DatasetSpecificInfo>
</GMLFeatureClass>
</GMLFeatureClassList>
@@ -6,43 +6,29 @@
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:coord><gml:X>0.776536312849161</gml:X><gml:Y>-4.244134078212291</gml:Y></gml:coord>
<gml:coord><gml:X>8.572346368715085</gml:X><gml:Y>2.179050279329609</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:split_lines_with_lines_same fid="lines.0">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>6,2 9,2 9,3 11,5</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
<ogr:split_lines_with_lines_same fid="lines2.0">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>5.44573945756429,-1.47253129614036 5.70391061452514,-1.99162011173184 8.57234636871508,-2.22039106145251 8.55474860335196,-4.24413407821229</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines_same>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines_same 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:split_lines_with_lines_same fid="lines2.1">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>0.776536312849161,2.17905027932961 4.04972067039106,1.33435754189944 5.44573945756429,-1.47253129614035</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines_same>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines_same fid="lines.2">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>2,0 2,2 3,2 3,3</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
<ogr:split_lines_with_lines_same fid="lines2.2">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>7.95642458100559,0.683240223463688 5.44573945756429,-1.47253129614036</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines_same>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines_same fid="lines.3">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>3,1 5,1</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines_same>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines_same fid="lines.4">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>7,-3 10,-3</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines_same>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines_same fid="lines.5">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>6,-3 10,1</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines_same>
</gml:featureMember>
<gml:featureMember>
<ogr:split_lines_with_lines_same fid="lines.6">
<ogr:split_lines_with_lines_same fid="lines2.3">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>5.44573945756429,-1.47253129614036 4.59525139664804,-2.20279329608939</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:split_lines_with_lines_same>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,32 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>split_polys_with_lines</Name>
<ElementPath>split_polys_with_lines</ElementPath>
<!--MULTIPOLYGON-->
<GeometryType>6</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>7</FeatureCount>
<ExtentXMin>-1.00000</ExtentXMin>
<ExtentXMax>10.00000</ExtentXMax>
<ExtentYMin>-3.00000</ExtentYMin>
<ExtentYMax>6.00000</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>name</Name>
<ElementPath>name</ElementPath>
<Type>String</Type>
<Width>5</Width>
</PropertyDefn>
<PropertyDefn>
<Name>intval</Name>
<ElementPath>intval</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>floatval</Name>
<ElementPath>floatval</ElementPath>
<Type>Real</Type>
</PropertyDefn>
</GMLFeatureClass>
</GMLFeatureClassList>
@@ -36,19 +36,26 @@
</gml:featureMember>
<gml:featureMember>
<ogr:split_polys_with_lines fid="polys.3">
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,-3 7,-2 9,-2 9,0 10,1 10,-3 6,-3</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>7,-2 6,-3 6,1 10,1 9,0 7,0 7,-2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,-3 7,-2 9,-2 9,0 10,1 10,-3 6,-3</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:name>ASDF</ogr:name>
<ogr:intval>0</ogr:intval>
</ogr:split_polys_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_polys_with_lines fid="polys.4">
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>7,-2 6,-3 6,1 10,1 9,0 7,0 7,-2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:name>ASDF</ogr:name>
<ogr:intval>0</ogr:intval>
</ogr:split_polys_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_polys_with_lines fid="polys.5">
<ogr:intval>120</ogr:intval>
<ogr:floatval>-100291.43213</ogr:floatval>
</ogr:split_polys_with_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:split_polys_with_lines fid="polys.5">
<ogr:split_polys_with_lines fid="polys.6">
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,2 6,1 6,-3 2,-1 2,2 3,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:name>elim</ogr:name>
<ogr:intval>2</ogr:intval>

This file was deleted.

@@ -1991,6 +1991,8 @@ tests:
compare:
geometry:
precision: 7
fields:
fid: skip

- algorithm: native:splitwithlines
name: Split lines with same lines
@@ -2008,7 +2010,8 @@ tests:
compare:
geometry:
precision: 7

fields:
fid: skip

# Split lines with lines considers two cases
# case 1: two different layers
@@ -2028,6 +2031,8 @@ tests:
compare:
geometry:
precision: 7
fields:
fid: skip

# case 2 split line layer with iself
- algorithm: native:splitwithlines
@@ -2046,6 +2051,8 @@ tests:
compare:
geometry:
precision: 7
fields:
fid: skip

- algorithm: native:dropgeometries
name: Drop geometries
@@ -52,8 +52,7 @@ void QgsSplitWithLinesAlgorithm::initAlgorithm( const QVariantMap & )
QString QgsSplitWithLinesAlgorithm::shortHelpString() const
{
return QObject::tr( "This algorithm splits the lines or polygons in one layer using the lines in another layer to define the breaking points. "
"Intersection between geometries in both layers are considered as split points.\n\n"
"Output will contain multi geometries for split features." );
"Intersection between geometries in both layers are considered as split points." );
}

QgsSplitWithLinesAlgorithm *QgsSplitWithLinesAlgorithm::createInstance() const
@@ -252,9 +251,9 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par
parts.append( aGeom );
}

if ( !parts.empty() )
for ( const QgsGeometry &g : parts )
{
outFeat.setGeometry( QgsGeometry::collectGeometry( parts ) );
outFeat.setGeometry( g );
sink->addFeature( outFeat, QgsFeatureSink::FastInsert );
}

0 comments on commit f8bad49

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