Skip to content

Commit a888986

Browse files
authoredMay 24, 2019
[needs-docs][processing] Avoid field collision via optional prefix in overlay algorithms (#10092)
Makes for a more predictable collision avoidance, which can be neccessary for some models.
1 parent dc6780a commit a888986

20 files changed

+545
-65
lines changed
 

‎python/core/auto_generated/processing/qgsprocessingutils.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ The ``preferredFormat`` argument is used to specify to desired file extension to
244244
layer export is required. This defaults to shapefiles.
245245
%End
246246

247-
static QgsFields combineFields( const QgsFields &fieldsA, const QgsFields &fieldsB );
247+
static QgsFields combineFields( const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix = QString() );
248248
%Docstring
249249
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
250250

Binary file not shown.
Binary file not shown.
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+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ intersection1.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>1</gml:X><gml:Y>5</gml:Y></gml:coord>
10+
<gml:coord><gml:X>8</gml:X><gml:Y>8</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:intersection1 fid="intersection1.0">
16+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,6 2,5 1,5 1,6 2,6</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
17+
<ogr:id_a>A1</ogr:id_a>
18+
<ogr:pre_id_b>B2</ogr:pre_id_b>
19+
</ogr:intersection1>
20+
</gml:featureMember>
21+
<gml:featureMember>
22+
<ogr:intersection1 fid="intersection1.1">
23+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>4,5 3,5 3,6 4,6 4,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
24+
<ogr:id_a>A2</ogr:id_a>
25+
<ogr:pre_id_b>B2</ogr:pre_id_b>
26+
</ogr:intersection1>
27+
</gml:featureMember>
28+
<gml:featureMember>
29+
<ogr:intersection1 fid="intersection1.2">
30+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>8,7 7,7 7,8 8,8 8,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
31+
<ogr:id_a>A3</ogr:id_a>
32+
<ogr:pre_id_b>B1</ogr:pre_id_b>
33+
</ogr:intersection1>
34+
</gml:featureMember>
35+
<gml:featureMember>
36+
<ogr:intersection1 fid="intersection1.3">
37+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,7 5,7 5,8 6,8 6,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
38+
<ogr:id_a>A3</ogr:id_a>
39+
<ogr:pre_id_b>B3</ogr:pre_id_b>
40+
</ogr:intersection1>
41+
</gml:featureMember>
42+
</ogr:FeatureCollection>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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="intersection1" type="ogr:intersection1_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="intersection1_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:MultiPolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="id_a" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:string">
22+
<xs:maxLength value="255"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
<xs:element name="pre_id_b" nillable="true" minOccurs="0" maxOccurs="1">
27+
<xs:simpleType>
28+
<xs:restriction base="xs:string">
29+
<xs:maxLength value="255"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
</xs:sequence>
34+
</xs:extension>
35+
</xs:complexContent>
36+
</xs:complexType>
37+
</xs:schema>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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_all_fields.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>3</gml:X><gml:Y>-0.2208501518128248</gml:Y></gml:coord>
10+
<gml:coord><gml:X>9.220978076442222</gml:X><gml:Y>3.220978076442221</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:line_intersection_all_fields fid="lines.0">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>9.22097807644222,3.22097807644222</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
<ogr:name>lines.0</ogr:name>
18+
<ogr:pre_fid>3</ogr:pre_fid>
19+
<ogr:pre_name>f3</ogr:pre_name>
20+
<ogr:pre_int>3</ogr:pre_int>
21+
</ogr:line_intersection_all_fields>
22+
</gml:featureMember>
23+
<gml:featureMember>
24+
<ogr:line_intersection_all_fields fid="lines.2">
25+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.0,2.8034726769992</gml:coordinates></gml:Point></ogr:geometryProperty>
26+
<ogr:name>lines.2</ogr:name>
27+
<ogr:pre_fid>3</ogr:pre_fid>
28+
<ogr:pre_name>f3</ogr:pre_name>
29+
<ogr:pre_int>3</ogr:pre_int>
30+
</ogr:line_intersection_all_fields>
31+
</gml:featureMember>
32+
<gml:featureMember>
33+
<ogr:line_intersection_all_fields fid="lines.3">
34+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.15579567779961,1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
35+
<ogr:name>lines.3</ogr:name>
36+
<ogr:pre_fid>2</ogr:pre_fid>
37+
<ogr:pre_name>f2</ogr:pre_name>
38+
<ogr:pre_int>2</ogr:pre_int>
39+
</ogr:line_intersection_all_fields>
40+
</gml:featureMember>
41+
<gml:featureMember>
42+
<ogr:line_intersection_all_fields fid="lines.5">
43+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8.77914984818717,-0.220850151812825</gml:coordinates></gml:Point></ogr:geometryProperty>
44+
<ogr:name>lines.5</ogr:name>
45+
<ogr:pre_fid>2</ogr:pre_fid>
46+
<ogr:pre_name>f2</ogr:pre_name>
47+
<ogr:pre_int>2</ogr:pre_int>
48+
</ogr:line_intersection_all_fields>
49+
</gml:featureMember>
50+
</ogr:FeatureCollection>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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_all_fields" type="ogr:line_intersection_all_fields_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="line_intersection_all_fields_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="name" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:string">
22+
<xs:maxLength value="255"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
<xs:element name="pre_fid" nillable="true" minOccurs="0" maxOccurs="1">
27+
<xs:simpleType>
28+
<xs:restriction base="xs:string">
29+
<xs:maxLength value="255"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
<xs:element name="pre_name" nillable="true" minOccurs="0" maxOccurs="1">
34+
<xs:simpleType>
35+
<xs:restriction base="xs:string">
36+
<xs:maxLength value="255"/>
37+
</xs:restriction>
38+
</xs:simpleType>
39+
</xs:element>
40+
<xs:element name="pre_int" nillable="true" minOccurs="0" maxOccurs="1">
41+
<xs:simpleType>
42+
<xs:restriction base="xs:integer">
43+
<xs:totalDigits value="10"/>
44+
</xs:restriction>
45+
</xs:simpleType>
46+
</xs:element>
47+
</xs:sequence>
48+
</xs:extension>
49+
</xs:complexContent>
50+
</xs:complexType>
51+
</xs:schema>
Binary file not shown.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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/ symmetrical_difference1_b_a.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>0</gml:X><gml:Y>1</gml:Y></gml:coord>
10+
<gml:coord><gml:X>9</gml:X><gml:Y>11</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:symmetrical_difference1_b_a fid="symmetrical_difference1_b_a.0">
16+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>8,7 8,1 1,1 1,2 7,2 7,7 8,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>7,8 7,9 8,9 8,8 7,8</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
17+
<ogr:id_b>B1</ogr:id_b>
18+
<ogr:pre_id_a xsi:nil="true"/>
19+
</ogr:symmetrical_difference1_b_a>
20+
</gml:featureMember>
21+
<gml:featureMember>
22+
<ogr:symmetrical_difference1_b_a fid="symmetrical_difference1_b_a.1">
23+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>5,3 6,3 6,4 5,4 5,3</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
24+
<ogr:id_b>B4</ogr:id_b>
25+
<ogr:pre_id_a xsi:nil="true"/>
26+
</ogr:symmetrical_difference1_b_a>
27+
</gml:featureMember>
28+
<gml:featureMember>
29+
<ogr:symmetrical_difference1_b_a fid="symmetrical_difference1_b_a.2">
30+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1,5 0,5 0,6 1,6 1,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,5 2,5 2,6 3,6 3,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
31+
<ogr:id_b>B2</ogr:id_b>
32+
<ogr:pre_id_a xsi:nil="true"/>
33+
</ogr:symmetrical_difference1_b_a>
34+
</gml:featureMember>
35+
<gml:featureMember>
36+
<ogr:symmetrical_difference1_b_a fid="symmetrical_difference1_b_a.3">
37+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>5,7 3,7 3,8 5,8 5,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
38+
<ogr:id_b>B3</ogr:id_b>
39+
<ogr:pre_id_a xsi:nil="true"/>
40+
</ogr:symmetrical_difference1_b_a>
41+
</gml:featureMember>
42+
<gml:featureMember>
43+
<ogr:symmetrical_difference1_b_a fid="symmetrical_difference1_b_a.4">
44+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,5 2,3 1,3 1,5 2,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1,6 1,11 8,11 8,10 2,10 2,6 1,6</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
45+
<ogr:id_b xsi:nil="true"/>
46+
<ogr:pre_id_a>A1</ogr:pre_id_a>
47+
</ogr:symmetrical_difference1_b_a>
48+
</gml:featureMember>
49+
<gml:featureMember>
50+
<ogr:symmetrical_difference1_b_a fid="symmetrical_difference1_b_a.5">
51+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,3 3,4 4,4 4,3 3,3</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
52+
<ogr:id_b xsi:nil="true"/>
53+
<ogr:pre_id_a>A4</ogr:pre_id_a>
54+
</ogr:symmetrical_difference1_b_a>
55+
</gml:featureMember>
56+
<gml:featureMember>
57+
<ogr:symmetrical_difference1_b_a fid="symmetrical_difference1_b_a.6">
58+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>4,6 6,6 6,5 4,5 4,6</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
59+
<ogr:id_b xsi:nil="true"/>
60+
<ogr:pre_id_a>A2</ogr:pre_id_a>
61+
</ogr:symmetrical_difference1_b_a>
62+
</gml:featureMember>
63+
<gml:featureMember>
64+
<ogr:symmetrical_difference1_b_a fid="symmetrical_difference1_b_a.7">
65+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>7,7 6,7 6,8 7,8 7,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>8,8 9,8 9,7 8,7 8,8</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
66+
<ogr:id_b xsi:nil="true"/>
67+
<ogr:pre_id_a>A3</ogr:pre_id_a>
68+
</ogr:symmetrical_difference1_b_a>
69+
</gml:featureMember>
70+
</ogr:FeatureCollection>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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="symmetrical_difference1_b_a" type="ogr:symmetrical_difference1_b_a_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="symmetrical_difference1_b_a_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:MultiPolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="id_b" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:string">
22+
<xs:maxLength value="255"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
<xs:element name="pre_id_a" nillable="true" minOccurs="0" maxOccurs="1">
27+
<xs:simpleType>
28+
<xs:restriction base="xs:string">
29+
<xs:maxLength value="255"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
</xs:sequence>
34+
</xs:extension>
35+
</xs:complexContent>
36+
</xs:complexType>
37+
</xs:schema>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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/ union1.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>0</gml:X><gml:Y>1</gml:Y></gml:coord>
10+
<gml:coord><gml:X>9</gml:X><gml:Y>11</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:union1 fid="union1.0">
16+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,6 2,5 1,5 1,6 2,6</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
17+
<ogr:id_a>A1</ogr:id_a>
18+
<ogr:pre_id_b>B2</ogr:pre_id_b>
19+
</ogr:union1>
20+
</gml:featureMember>
21+
<gml:featureMember>
22+
<ogr:union1 fid="union1.1">
23+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>4,5 3,5 3,6 4,6 4,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
24+
<ogr:id_a>A2</ogr:id_a>
25+
<ogr:pre_id_b>B2</ogr:pre_id_b>
26+
</ogr:union1>
27+
</gml:featureMember>
28+
<gml:featureMember>
29+
<ogr:union1 fid="union1.2">
30+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>8,7 7,7 7,8 8,8 8,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
31+
<ogr:id_a>A3</ogr:id_a>
32+
<ogr:pre_id_b>B1</ogr:pre_id_b>
33+
</ogr:union1>
34+
</gml:featureMember>
35+
<gml:featureMember>
36+
<ogr:union1 fid="union1.3">
37+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,7 5,7 5,8 6,8 6,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
38+
<ogr:id_a>A3</ogr:id_a>
39+
<ogr:pre_id_b>B3</ogr:pre_id_b>
40+
</ogr:union1>
41+
</gml:featureMember>
42+
<gml:featureMember>
43+
<ogr:union1 fid="union1.4">
44+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,5 2,3 1,3 1,5 2,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1,6 1,11 8,11 8,10 2,10 2,6 1,6</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
45+
<ogr:id_a>A1</ogr:id_a>
46+
<ogr:pre_id_b xsi:nil="true"/>
47+
</ogr:union1>
48+
</gml:featureMember>
49+
<gml:featureMember>
50+
<ogr:union1 fid="union1.5">
51+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,3 3,4 4,4 4,3 3,3</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
52+
<ogr:id_a>A4</ogr:id_a>
53+
<ogr:pre_id_b xsi:nil="true"/>
54+
</ogr:union1>
55+
</gml:featureMember>
56+
<gml:featureMember>
57+
<ogr:union1 fid="union1.6">
58+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>4,6 6,6 6,5 4,5 4,6</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
59+
<ogr:id_a>A2</ogr:id_a>
60+
<ogr:pre_id_b xsi:nil="true"/>
61+
</ogr:union1>
62+
</gml:featureMember>
63+
<gml:featureMember>
64+
<ogr:union1 fid="union1.7">
65+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>7,7 6,7 6,8 7,8 7,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>8,8 9,8 9,7 8,7 8,8</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
66+
<ogr:id_a>A3</ogr:id_a>
67+
<ogr:pre_id_b xsi:nil="true"/>
68+
</ogr:union1>
69+
</gml:featureMember>
70+
<gml:featureMember>
71+
<ogr:union1 fid="union1.8">
72+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>8,7 8,1 1,1 1,2 7,2 7,7 8,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>7,8 7,9 8,9 8,8 7,8</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
73+
<ogr:id_a xsi:nil="true"/>
74+
<ogr:pre_id_b>B1</ogr:pre_id_b>
75+
</ogr:union1>
76+
</gml:featureMember>
77+
<gml:featureMember>
78+
<ogr:union1 fid="union1.9">
79+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>5,3 6,3 6,4 5,4 5,3</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
80+
<ogr:id_a xsi:nil="true"/>
81+
<ogr:pre_id_b>B4</ogr:pre_id_b>
82+
</ogr:union1>
83+
</gml:featureMember>
84+
<gml:featureMember>
85+
<ogr:union1 fid="union1.10">
86+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1,5 0,5 0,6 1,6 1,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,5 2,5 2,6 3,6 3,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
87+
<ogr:id_a xsi:nil="true"/>
88+
<ogr:pre_id_b>B2</ogr:pre_id_b>
89+
</ogr:union1>
90+
</gml:featureMember>
91+
<gml:featureMember>
92+
<ogr:union1 fid="union1.11">
93+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3857"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>5,7 3,7 3,8 5,8 5,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
94+
<ogr:id_a xsi:nil="true"/>
95+
<ogr:pre_id_b>B3</ogr:pre_id_b>
96+
</ogr:union1>
97+
</gml:featureMember>
98+
</ogr:FeatureCollection>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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="union1" type="ogr:union1_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="union1_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:MultiPolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="id_a" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:string">
22+
<xs:maxLength value="255"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
<xs:element name="pre_id_b" nillable="true" minOccurs="0" maxOccurs="1">
27+
<xs:simpleType>
28+
<xs:restriction base="xs:string">
29+
<xs:maxLength value="255"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
</xs:sequence>
34+
</xs:extension>
35+
</xs:complexContent>
36+
</xs:complexType>
37+
</xs:schema>

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,26 @@ tests:
17391739
fid: skip
17401740
fid_2: skip
17411741

1742+
- algorithm: native:lineintersections
1743+
name: Line intersections all fields (custom prefix)
1744+
params:
1745+
INPUT:
1746+
name: custom/line_intersection1.gml
1747+
type: vector
1748+
INTERSECT:
1749+
name: custom/line_intersection2.gml
1750+
type: vector
1751+
INTERSECT_FIELDS_PREFIX: pre_
1752+
results:
1753+
OUTPUT:
1754+
name: expected/line_intersection_prefix.gml
1755+
type: vector
1756+
pk: [ name, pre_name ]
1757+
compare:
1758+
fields:
1759+
fid: skip
1760+
pre_fid: skip
1761+
17421762
- algorithm: native:lineintersections
17431763
name: Line intersections some fields
17441764
params:

‎python/plugins/processing/tests/testdata/qgis_algorithm_tests4.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ tests:
315315
fields:
316316
fid: skip
317317

318+
- algorithm: native:intersection
319+
name: Test Intersection (custom prefix)
320+
params:
321+
INPUT:
322+
name: custom/overlay1_a.geojson
323+
type: vector
324+
OVERLAY:
325+
name: custom/overlay1_b.geojson
326+
type: vector
327+
OVERLAY_FIELDS_PREFIX: pre_
328+
results:
329+
OUTPUT:
330+
name: expected/intersection_prefix.gml
331+
type: vector
332+
pk: [id_a, pre_id_b]
333+
compare:
334+
fields:
335+
fid: skip
336+
318337
- algorithm: native:wedgebuffers
319338
name: Wedge buffers
320339
params:
@@ -383,6 +402,7 @@ tests:
383402
compare:
384403
fields:
385404
fid: skip
405+
386406
- algorithm: native:symmetricaldifference
387407
name: Test Symmetrical Difference B - A (basic)
388408
params:
@@ -401,6 +421,25 @@ tests:
401421
fields:
402422
fid: skip
403423

424+
- algorithm: native:symmetricaldifference
425+
name: Test Symmetrical Difference B - A (custom prefix)
426+
params:
427+
INPUT:
428+
name: custom/overlay1_b.geojson
429+
type: vector
430+
OVERLAY:
431+
name: custom/overlay1_a.geojson
432+
type: vector
433+
OVERLAY_FIELDS_PREFIX: pre_
434+
results:
435+
OUTPUT:
436+
name: expected/symmetrical_difference_prefix.gml
437+
type: vector
438+
pk: [pre_id_a, id_b]
439+
compare:
440+
fields:
441+
fid: skip
442+
404443
- algorithm: native:union
405444
name: Test Union of single layer
406445
params:
@@ -434,6 +473,25 @@ tests:
434473
fields:
435474
fid: skip
436475

476+
- algorithm: native:union
477+
name: Test Union (custom prefix)
478+
params:
479+
INPUT:
480+
name: custom/overlay1_a.geojson
481+
type: vector
482+
OVERLAY:
483+
name: custom/overlay1_b.geojson
484+
type: vector
485+
OVERLAY_FIELDS_PREFIX: pre_
486+
results:
487+
OUTPUT:
488+
name: expected/union_prefix.gml
489+
type: vector
490+
pk: [id_a, pre_id_b]
491+
compare:
492+
fields:
493+
fid: skip
494+
437495
- algorithm: native:union
438496
name: Test Union (geom types)
439497
params:

‎src/analysis/processing/qgsalgorithmintersection.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ void QgsIntersectionAlgorithm::initAlgorithm( const QVariantMap & )
6868
QObject::tr( "Overlay fields to keep (leave empty to keep all fields)" ), QVariant(),
6969
QStringLiteral( "OVERLAY" ), QgsProcessingParameterField::Any, true, true ) );
7070

71+
std::unique_ptr< QgsProcessingParameterString > prefix = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral( "OVERLAY_FIELDS_PREFIX" ), QObject::tr( "Overlay fields prefix" ), QString(), false, true );
72+
prefix->setFlags( prefix->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
73+
addParameter( prefix.release() );
74+
7175
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Intersection" ) ) );
7276

7377
}
@@ -91,9 +95,11 @@ QVariantMap QgsIntersectionAlgorithm::processAlgorithm( const QVariantMap &param
9195
QList<int> fieldIndicesA = QgsProcessingUtils::fieldNamesToIndices( fieldsA, sourceA->fields() );
9296
QList<int> fieldIndicesB = QgsProcessingUtils::fieldNamesToIndices( fieldsB, sourceB->fields() );
9397

98+
QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral( "OVERLAY_FIELDS_PREFIX" ), context );
9499
QgsFields outputFields = QgsProcessingUtils::combineFields(
95100
QgsProcessingUtils::indicesToFields( fieldIndicesA, sourceA->fields() ),
96-
QgsProcessingUtils::indicesToFields( fieldIndicesB, sourceB->fields() ) );
101+
QgsProcessingUtils::indicesToFields( fieldIndicesB, sourceB->fields() ),
102+
overlayFieldsPrefix );
97103

98104
QString dest;
99105
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, outputFields, geomType, sourceA->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );

‎src/analysis/processing/qgsalgorithmlineintersection.cpp

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ void QgsLineIntersectionAlgorithm::initAlgorithm( const QVariantMap & )
6363
QStringLiteral( "INTERSECT" ), QgsProcessingParameterField::Any,
6464
true, true ) );
6565

66+
std::unique_ptr< QgsProcessingParameterString > prefix = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral( "INTERSECT_FIELDS_PREFIX" ), QObject::tr( "Intersect fields prefix" ), QString(), false, true );
67+
prefix->setFlags( prefix->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
68+
addParameter( prefix.release() );
69+
6670
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Intersections" ), QgsProcessing::TypeVectorPoint ) );
6771
}
6872

@@ -89,55 +93,14 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p
8993
const QStringList fieldsA = parameterAsFields( parameters, QStringLiteral( "INPUT_FIELDS" ), context );
9094
const QStringList fieldsB = parameterAsFields( parameters, QStringLiteral( "INTERSECT_FIELDS" ), context );
9195

92-
QgsFields outFieldsA;
93-
QgsAttributeList fieldsAIndices;
94-
95-
if ( fieldsA.empty() )
96-
{
97-
outFieldsA = sourceA->fields();
98-
for ( int i = 0; i < outFieldsA.count(); ++i )
99-
{
100-
fieldsAIndices << i;
101-
}
102-
}
103-
else
104-
{
105-
for ( const QString &field : fieldsA )
106-
{
107-
int index = sourceA->fields().lookupField( field );
108-
if ( index >= 0 )
109-
{
110-
fieldsAIndices << index;
111-
outFieldsA.append( sourceA->fields().at( index ) );
112-
}
113-
}
114-
}
115-
116-
QgsFields outFieldsB;
117-
QgsAttributeList fieldsBIndices;
118-
119-
if ( fieldsB.empty() )
120-
{
121-
outFieldsB = sourceB->fields();
122-
for ( int i = 0; i < outFieldsB.count(); ++i )
123-
{
124-
fieldsBIndices << i;
125-
}
126-
}
127-
else
128-
{
129-
for ( const QString &field : fieldsB )
130-
{
131-
int index = sourceB->fields().lookupField( field );
132-
if ( index >= 0 )
133-
{
134-
fieldsBIndices << index;
135-
outFieldsB.append( sourceB->fields().at( index ) );
136-
}
137-
}
138-
}
96+
QgsAttributeList fieldIndicesA = QgsProcessingUtils::fieldNamesToIndices( fieldsA, sourceA->fields() );
97+
QgsAttributeList fieldIndicesB = QgsProcessingUtils::fieldNamesToIndices( fieldsB, sourceB->fields() );
13998

140-
QgsFields outFields = QgsProcessingUtils::combineFields( outFieldsA, outFieldsB );
99+
QString intersectFieldsPrefix = parameterAsString( parameters, QStringLiteral( "INTERSECT_FIELDS_PREFIX" ), context );
100+
QgsFields outFields = QgsProcessingUtils::combineFields(
101+
QgsProcessingUtils::indicesToFields( fieldIndicesA, sourceA->fields() ),
102+
QgsProcessingUtils::indicesToFields( fieldIndicesB, sourceB->fields() ),
103+
intersectFieldsPrefix );
141104

142105
QString dest;
143106
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, outFields, QgsWkbTypes::Point, sourceA->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
@@ -146,7 +109,7 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p
146109

147110
QgsSpatialIndex spatialIndex( sourceB->getFeatures( QgsFeatureRequest().setNoAttributes().setDestinationCrs( sourceA->sourceCrs(), context.transformContext() ) ), feedback );
148111
QgsFeature outFeature;
149-
QgsFeatureIterator features = sourceA->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( fieldsAIndices ) );
112+
QgsFeatureIterator features = sourceA->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( fieldIndicesA ) );
150113
double step = sourceA->featureCount() > 0 ? 100.0 / sourceA->featureCount() : 1;
151114
int i = 0;
152115
QgsFeature inFeatureA;
@@ -171,7 +134,7 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p
171134

172135
QgsFeatureRequest request = QgsFeatureRequest().setFilterFids( lines );
173136
request.setDestinationCrs( sourceA->sourceCrs(), context.transformContext() );
174-
request.setSubsetOfAttributes( fieldsBIndices );
137+
request.setSubsetOfAttributes( fieldIndicesB );
175138

176139
QgsFeature inFeatureB;
177140
QgsFeatureIterator featuresB = sourceB->getFeatures( request );
@@ -188,11 +151,11 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p
188151
QgsMultiPointXY points;
189152
QgsGeometry intersectGeom = inGeom.intersection( tmpGeom );
190153
QgsAttributes outAttributes;
191-
for ( int a : qgis::as_const( fieldsAIndices ) )
154+
for ( int a : qgis::as_const( fieldIndicesA ) )
192155
{
193156
outAttributes.append( inFeatureA.attribute( a ) );
194157
}
195-
for ( int b : qgis::as_const( fieldsBIndices ) )
158+
for ( int b : qgis::as_const( fieldIndicesB ) )
196159
{
197160
outAttributes.append( inFeatureB.attribute( b ) );
198161
}

‎src/analysis/processing/qgsalgorithmsymmetricaldifference.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ void QgsSymmetricalDifferenceAlgorithm::initAlgorithm( const QVariantMap & )
5555
{
5656
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
5757
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "OVERLAY" ), QObject::tr( "Overlay layer" ) ) );
58+
59+
std::unique_ptr< QgsProcessingParameterString > prefix = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral( "OVERLAY_FIELDS_PREFIX" ), QObject::tr( "Overlay fields prefix" ), QString(), false, true );
60+
prefix->setFlags( prefix->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
61+
addParameter( prefix.release() );
62+
5863
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Symmetrical difference" ) ) );
5964
}
6065

@@ -71,7 +76,8 @@ QVariantMap QgsSymmetricalDifferenceAlgorithm::processAlgorithm( const QVariantM
7176

7277
QgsWkbTypes::Type geomType = QgsWkbTypes::multiType( sourceA->wkbType() );
7378

74-
QgsFields fields = QgsProcessingUtils::combineFields( sourceA->fields(), sourceB->fields() );
79+
QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral( "OVERLAY_FIELDS_PREFIX" ), context );
80+
QgsFields fields = QgsProcessingUtils::combineFields( sourceA->fields(), sourceB->fields(), overlayFieldsPrefix );
7581

7682
QString dest;
7783
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields, geomType, sourceA->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );

‎src/analysis/processing/qgsalgorithmunion.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ void QgsUnionAlgorithm::initAlgorithm( const QVariantMap & )
6262
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
6363
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "OVERLAY" ), QObject::tr( "Overlay layer" ), QList< int >(), QVariant(), true ) );
6464

65+
std::unique_ptr< QgsProcessingParameterString > prefix = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral( "OVERLAY_FIELDS_PREFIX" ), QObject::tr( "Overlay fields prefix" ), QString(), false, true );
66+
prefix->setFlags( prefix->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
67+
addParameter( prefix.release() );
68+
6569
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Union" ) ) );
6670
}
6771

@@ -77,7 +81,8 @@ QVariantMap QgsUnionAlgorithm::processAlgorithm( const QVariantMap &parameters,
7781

7882
QgsWkbTypes::Type geomType = QgsWkbTypes::multiType( sourceA->wkbType() );
7983

80-
QgsFields fields = sourceB ? QgsProcessingUtils::combineFields( sourceA->fields(), sourceB->fields() ) : sourceA->fields();
84+
QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral( "OVERLAY_FIELDS_PREFIX" ), context );
85+
QgsFields fields = sourceB ? QgsProcessingUtils::combineFields( sourceA->fields(), sourceB->fields(), overlayFieldsPrefix ) : sourceA->fields();
8186

8287
QString dest;
8388
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields, geomType, sourceA->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );

‎src/core/processing/qgsprocessingutils.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ QString QgsProcessingUtils::convertToCompatibleFormat( const QgsVectorLayer *vl,
839839
}
840840
}
841841

842-
QgsFields QgsProcessingUtils::combineFields( const QgsFields &fieldsA, const QgsFields &fieldsB )
842+
QgsFields QgsProcessingUtils::combineFields( const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix )
843843
{
844844
QgsFields outFields = fieldsA;
845845
QSet< QString > usedNames;
@@ -850,25 +850,25 @@ QgsFields QgsProcessingUtils::combineFields( const QgsFields &fieldsA, const Qgs
850850

851851
for ( const QgsField &f : fieldsB )
852852
{
853-
if ( usedNames.contains( f.name().toLower() ) )
853+
QgsField newField = f;
854+
newField.setName( fieldsBPrefix + f.name() );
855+
if ( usedNames.contains( newField.name().toLower() ) )
854856
{
855857
int idx = 2;
856-
QString newName = f.name() + '_' + QString::number( idx );
858+
QString newName = newField.name() + '_' + QString::number( idx );
857859
while ( usedNames.contains( newName.toLower() ) )
858860
{
859861
idx++;
860-
newName = f.name() + '_' + QString::number( idx );
862+
newName = newField.name() + '_' + QString::number( idx );
861863
}
862-
QgsField newField = f;
863864
newField.setName( newName );
864865
outFields.append( newField );
865-
usedNames.insert( newName.toLower() );
866866
}
867867
else
868868
{
869-
usedNames.insert( f.name().toLower() );
870-
outFields.append( f );
869+
outFields.append( newField );
871870
}
871+
usedNames.insert( newField.name() );
872872
}
873873

874874
return outFields;

‎src/core/processing/qgsprocessingutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class CORE_EXPORT QgsProcessingUtils
287287
* length of field names, so be aware that the results of calling this method may
288288
* be truncated when saving to these formats.
289289
*/
290-
static QgsFields combineFields( const QgsFields &fieldsA, const QgsFields &fieldsB );
290+
static QgsFields combineFields( const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix = QString() );
291291

292292
/**
293293
* Returns a list of field indices parsed from the given list of field names. Unknown field names are ignored.

0 commit comments

Comments
 (0)
Please sign in to comment.