Skip to content

Commit 3e2694a

Browse files
authored
Merge pull request #6848 from gacarrillor/line_intersection_with_geometry_collections
[processing] Make line intersection alg able to handle collections
2 parents 2d4b482 + ac34868 commit 3e2694a

8 files changed

+217
-8
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ line_intersection_collection1.xsd"
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>963795.9543288001</gml:X><gml:Y>1077577.066142281</gml:Y></gml:coord>
10+
<gml:coord><gml:X>964309.9869270925</gml:X><gml:Y>1077925.530188314</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:line_intersection_collection1 fid="line_intersection_collection1.0">
16+
<ogr:geometryProperty><gml:LineString srsName="EPSG:3116"><gml:coordinates>963795.9543288,1077590.54265235 963905.691625065,1077713.75645868 963926.868998028,1077925.53018831 963980.775038299,1077802.31638198 964219.501788067,1077867.7737166 964059.761477611,1077699.94219859 964144.709036072,1077671.41702938 964211.234771022,1077618.29701916 964261.241936687,1077648.19439743 964309.986927093,1077617.49567248 964144.418374834,1077577.06614228 963905.691625065,1077713.75645868</gml:coordinates></gml:LineString></ogr:geometryProperty>
17+
<ogr:longitud>1804.4</ogr:longitud>
18+
</ogr:line_intersection_collection1>
19+
</gml:featureMember>
20+
</ogr:FeatureCollection>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="line_intersection_collection1" type="ogr:line_intersection_collection1_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="line_intersection_collection1_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:LineStringPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="longitud" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:decimal">
22+
</xs:restriction>
23+
</xs:simpleType>
24+
</xs:element>
25+
</xs:sequence>
26+
</xs:extension>
27+
</xs:complexContent>
28+
</xs:complexType>
29+
</xs:schema>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ line_intersection_collection2.xsd"
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>963718.9456998424</gml:X><gml:Y>1077618.297019162</gml:Y></gml:coord>
10+
<gml:coord><gml:X>964257.4287541196</gml:X><gml:Y>1077989.062307205</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:line_intersection_collection2 fid="line_intersection_collection2.0">
16+
<ogr:geometryProperty><gml:LineString srsName="EPSG:3116"><gml:coordinates>964257.42875412,1077702.09075594 964211.234771022,1077618.29701916 963980.775038299,1077802.31638198 963926.868998028,1077925.53018831 963718.945699842,1077989.0623072</gml:coordinates></gml:LineString></ogr:geometryProperty>
17+
<ogr:longitud>672.7</ogr:longitud>
18+
</ogr:line_intersection_collection2>
19+
</gml:featureMember>
20+
</ogr:FeatureCollection>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="line_intersection_collection2" type="ogr:line_intersection_collection2_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="line_intersection_collection2_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:LineStringPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="longitud" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:decimal">
22+
</xs:restriction>
23+
</xs:simpleType>
24+
</xs:element>
25+
</xs:sequence>
26+
</xs:extension>
27+
</xs:complexContent>
28+
</xs:complexType>
29+
</xs:schema>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ line_intersection_collection.xsd"
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>964081.0170018662</gml:X><gml:Y>1077618.29701916</gml:Y></gml:coord>
10+
<gml:coord><gml:X>964211.234771022</gml:X><gml:Y>1077722.274363162</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:line_intersection_collection fid="line_intersection_collection1.0">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:3116"><gml:coordinates>964081.017001866,1077722.27436316</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
<ogr:longitud>1804.4</ogr:longitud>
18+
<ogr:fid_2>line_intersection_collection2.0</ogr:fid_2>
19+
<ogr:longitud_2>672.7</ogr:longitud_2>
20+
</ogr:line_intersection_collection>
21+
</gml:featureMember>
22+
<gml:featureMember>
23+
<ogr:line_intersection_collection fid="line_intersection_collection1.0">
24+
<ogr:geometryProperty><gml:Point srsName="EPSG:3116"><gml:coordinates>964144.709036063,1077671.41702938</gml:coordinates></gml:Point></ogr:geometryProperty>
25+
<ogr:longitud>1804.4</ogr:longitud>
26+
<ogr:fid_2>line_intersection_collection2.0</ogr:fid_2>
27+
<ogr:longitud_2>672.7</ogr:longitud_2>
28+
</ogr:line_intersection_collection>
29+
</gml:featureMember>
30+
<gml:featureMember>
31+
<ogr:line_intersection_collection fid="line_intersection_collection1.0">
32+
<ogr:geometryProperty><gml:Point srsName="EPSG:3116"><gml:coordinates>964211.234771022,1077618.29701916</gml:coordinates></gml:Point></ogr:geometryProperty>
33+
<ogr:longitud>1804.4</ogr:longitud>
34+
<ogr:fid_2>line_intersection_collection2.0</ogr:fid_2>
35+
<ogr:longitud_2>672.7</ogr:longitud_2>
36+
</ogr:line_intersection_collection>
37+
</gml:featureMember>
38+
</ogr:FeatureCollection>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="line_intersection_collection" type="ogr:line_intersection_collection_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="line_intersection_collection_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="longitud" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:decimal">
22+
</xs:restriction>
23+
</xs:simpleType>
24+
</xs:element>
25+
<xs:element name="fid_2" nillable="true" minOccurs="0" maxOccurs="1">
26+
<xs:simpleType>
27+
<xs:restriction base="xs:string">
28+
<xs:maxLength value="255"/>
29+
</xs:restriction>
30+
</xs:simpleType>
31+
</xs:element>
32+
<xs:element name="longitud_2" nillable="true" minOccurs="0" maxOccurs="1">
33+
<xs:simpleType>
34+
<xs:restriction base="xs:decimal">
35+
</xs:restriction>
36+
</xs:simpleType>
37+
</xs:element>
38+
</xs:sequence>
39+
</xs:extension>
40+
</xs:complexContent>
41+
</xs:complexType>
42+
</xs:schema>

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,20 @@ tests:
16811681
fields:
16821682
fid: skip
16831683

1684+
- algorithm: native:lineintersections
1685+
name: Line intersections with geometry collection
1686+
params:
1687+
INPUT:
1688+
name: custom/line_intersection_collection1.gml
1689+
type: vector
1690+
INTERSECT:
1691+
name: custom/line_intersection_collection2.gml
1692+
type: vector
1693+
results:
1694+
OUTPUT:
1695+
name: expected/line_intersection_collection.gml
1696+
type: vector
1697+
16841698
- algorithm: qgis:sumlinelengths
16851699
name: Sum line lengths
16861700
params:

src/analysis/processing/qgsalgorithmlineintersection.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,25 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p
196196
{
197197
outAttributes.append( inFeatureB.attribute( b ) );
198198
}
199-
if ( intersectGeom.type() == QgsWkbTypes::PointGeometry )
199+
if ( QgsWkbTypes::flatType( intersectGeom.wkbType() ) == QgsWkbTypes::GeometryCollection )
200+
{
201+
const QVector<QgsGeometry> geomCollection = intersectGeom.asGeometryCollection();
202+
for ( const QgsGeometry &part : geomCollection )
203+
{
204+
if ( part.type() == QgsWkbTypes::PointGeometry )
205+
{
206+
if ( part.isMultipart() )
207+
{
208+
points = part.asMultiPoint();
209+
}
210+
else
211+
{
212+
points.append( part.asPoint() );
213+
}
214+
}
215+
}
216+
}
217+
else if ( intersectGeom.type() == QgsWkbTypes::PointGeometry )
200218
{
201219
if ( intersectGeom.isMultipart() )
202220
{
@@ -206,13 +224,12 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p
206224
{
207225
points.append( intersectGeom.asPoint() );
208226
}
209-
210-
for ( const QgsPointXY &j : qgis::as_const( points ) )
211-
{
212-
outFeature.setGeometry( QgsGeometry::fromPointXY( j ) );
213-
outFeature.setAttributes( outAttributes );
214-
sink->addFeature( outFeature, QgsFeatureSink::FastInsert );
215-
}
227+
}
228+
for ( const QgsPointXY &j : qgis::as_const( points ) )
229+
{
230+
outFeature.setGeometry( QgsGeometry::fromPointXY( j ) );
231+
outFeature.setAttributes( outAttributes );
232+
sink->addFeature( outFeature, QgsFeatureSink::FastInsert );
216233
}
217234
}
218235
}

0 commit comments

Comments
 (0)