Skip to content

Commit 55110ff

Browse files
github-actions[bot]nyalldawson
authored andcommittedMay 4, 2020
[processing] Set distanceArea CRS properly in SumLineLengths algorithm
1 parent 3d534f5 commit 55110ff

File tree

6 files changed

+115
-2
lines changed

6 files changed

+115
-2
lines changed
 
Binary file not shown.

‎python/plugins/processing/tests/testdata/expected/sum_line_length_projected_crs.gml

Lines changed: 26 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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="sum_line_length_projected_crs" type="ogr:sum_line_length_projected_crs_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="sum_line_length_projected_crs_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="Codigo" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:integer">
22+
<xs:totalDigits value="10"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
<xs:element name="Nombre" nillable="true" minOccurs="0" maxOccurs="1">
27+
<xs:simpleType>
28+
<xs:restriction base="xs:string">
29+
<xs:maxLength value="32"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
<xs:element name="AreaOficial_km2" nillable="true" minOccurs="0" maxOccurs="1">
34+
<xs:simpleType>
35+
<xs:restriction base="xs:integer">
36+
<xs:totalDigits value="10"/>
37+
</xs:restriction>
38+
</xs:simpleType>
39+
</xs:element>
40+
<xs:element name="AreaReal_km2" 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:element name="Vias" nillable="true" minOccurs="0" maxOccurs="1">
48+
<xs:simpleType>
49+
<xs:restriction base="xs:decimal">
50+
</xs:restriction>
51+
</xs:simpleType>
52+
</xs:element>
53+
<xs:element name="line_len" nillable="true" minOccurs="0" maxOccurs="1">
54+
<xs:simpleType>
55+
<xs:restriction base="xs:decimal">
56+
</xs:restriction>
57+
</xs:simpleType>
58+
</xs:element>
59+
<xs:element name="line_count" nillable="true" minOccurs="0" maxOccurs="1">
60+
<xs:simpleType>
61+
<xs:restriction base="xs:decimal">
62+
</xs:restriction>
63+
</xs:simpleType>
64+
</xs:element>
65+
</xs:sequence>
66+
</xs:extension>
67+
</xs:complexContent>
68+
</xs:complexType>
69+
</xs:schema>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,22 @@ tests:
17971797
name: expected/sum_line_length.gml
17981798
type: vector
17991799

1800+
- algorithm: native:sumlinelengths
1801+
name: Sum line lengths (projected CRS)
1802+
params:
1803+
COUNT_FIELD: line_count
1804+
LEN_FIELD: line_len
1805+
LINES:
1806+
name: custom/sumlinelengths.gpkg|layername=roads
1807+
type: vector
1808+
POLYGONS:
1809+
name: custom/sumlinelengths.gpkg|layername=polygons
1810+
type: vector
1811+
results:
1812+
OUTPUT:
1813+
name: expected/sum_line_length_projected_crs.gml
1814+
type: vector
1815+
18001816
- algorithm: qgis:delaunaytriangulation
18011817
name: Delaunay triangulation (multipoint data)
18021818
params:

‎src/analysis/processing/qgsalgorithmsumlinelength.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ QgsProcessing::SourceType QgsSumLineLengthAlgorithm::outputLayerType() const
8787
QgsCoordinateReferenceSystem QgsSumLineLengthAlgorithm::outputCrs( const QgsCoordinateReferenceSystem &inputCrs ) const
8888
{
8989
mCrs = inputCrs;
90+
mDa.setSourceCrs( mCrs, mTransformContext );
9091
return mCrs;
9192
}
9293

@@ -131,7 +132,7 @@ bool QgsSumLineLengthAlgorithm::prepareAlgorithm( const QVariantMap &parameters,
131132
{
132133
mDa.setEllipsoid( context.project()->ellipsoid() );
133134
}
134-
mDa.setSourceCrs( mCrs, context.transformContext() );
135+
mTransformContext = context.transformContext();
135136

136137
return true;
137138
}

‎src/analysis/processing/qgsalgorithmsumlinelength.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class QgsSumLineLengthAlgorithm : public QgsProcessingFeatureBasedAlgorithm
5454
QString inputParameterDescription() const override;
5555
QString outputName() const override;
5656
bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
57-
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
57+
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
5858
QgsFields outputFields( const QgsFields &inputFields ) const override;
5959

6060
private:
@@ -66,6 +66,7 @@ class QgsSumLineLengthAlgorithm : public QgsProcessingFeatureBasedAlgorithm
6666
mutable QgsFields mFields;
6767
mutable QgsCoordinateReferenceSystem mCrs;
6868
mutable QgsDistanceArea mDa;
69+
QgsCoordinateTransformContext mTransformContext;
6970
std::unique_ptr< QgsProcessingFeatureSource > mLinesSource;
7071
};
7172

0 commit comments

Comments
 (0)
Please sign in to comment.