Skip to content

Commit

Permalink
[processing] Set distanceArea CRS properly in SumLineLengths algorithm
Browse files Browse the repository at this point in the history
Fix #36135
  • Loading branch information
gacarrillor committed May 3, 2020
1 parent 66a3b09 commit 5623229
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 2 deletions.
Binary file not shown.

Large diffs are not rendered by default.

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="sum_line_length_projected_crs" type="ogr:sum_line_length_projected_crs_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="sum_line_length_projected_crs_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:MultiPolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="Codigo" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Nombre" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="32"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="AreaOficial_km2" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="AreaReal_km2" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Vias" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="line_len" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="line_count" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Expand Up @@ -1785,6 +1785,22 @@ tests:
name: expected/sum_line_length.gml
type: vector

- algorithm: native:sumlinelengths
name: Sum line lengths (projected CRS)
params:
COUNT_FIELD: line_count
LEN_FIELD: line_len
LINES:
name: custom/sumlinelengths.gpkg|layername=roads
type: vector
POLYGONS:
name: custom/sumlinelengths.gpkg|layername=polygons
type: vector
results:
OUTPUT:
name: expected/sum_line_length_projected_crs.gml
type: vector

- algorithm: qgis:delaunaytriangulation
name: Delaunay triangulation (multipoint data)
params:
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/processing/qgsalgorithmsumlinelength.cpp
Expand Up @@ -87,6 +87,7 @@ QgsProcessing::SourceType QgsSumLineLengthAlgorithm::outputLayerType() const
QgsCoordinateReferenceSystem QgsSumLineLengthAlgorithm::outputCrs( const QgsCoordinateReferenceSystem &inputCrs ) const
{
mCrs = inputCrs;
mDa.setSourceCrs( mCrs, mTransformContext );
return mCrs;
}

Expand Down Expand Up @@ -131,7 +132,7 @@ bool QgsSumLineLengthAlgorithm::prepareAlgorithm( const QVariantMap &parameters,
{
mDa.setEllipsoid( context.project()->ellipsoid() );
}
mDa.setSourceCrs( mCrs, context.transformContext() );
mTransformContext = context.transformContext();

return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/processing/qgsalgorithmsumlinelength.h
Expand Up @@ -54,7 +54,7 @@ class QgsSumLineLengthAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QString inputParameterDescription() const override;
QString outputName() const override;
bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFields outputFields( const QgsFields &inputFields ) const override;

private:
Expand All @@ -66,6 +66,7 @@ class QgsSumLineLengthAlgorithm : public QgsProcessingFeatureBasedAlgorithm
mutable QgsFields mFields;
mutable QgsCoordinateReferenceSystem mCrs;
mutable QgsDistanceArea mDa;
QgsCoordinateTransformContext mTransformContext;
std::unique_ptr< QgsProcessingFeatureSource > mLinesSource;
};

Expand Down

0 comments on commit 5623229

Please sign in to comment.