Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE][processing] Interpolate point on line algorithm
This algorithm creates a point geometry interpolated at a set distance along line (or polygon boundary) geometries.
- Loading branch information
1 parent
7ef5631
commit 8365335
Showing
10 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
Binary file modified
BIN
+0 Bytes
(100%)
python/plugins/processing/tests/testdata/custom/circular_strings.gpkg
Binary file not shown.
48 changes: 48 additions & 0 deletions
48
python/plugins/processing/tests/testdata/expected/interpolate_point_lines.gml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ogr:FeatureCollection | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://ogr.maptools.org/ interpolate_point_lines.xsd" | ||
xmlns:ogr="http://ogr.maptools.org/" | ||
xmlns:gml="http://www.opengis.net/gml"> | ||
<gml:boundedBy> | ||
<gml:Box> | ||
<gml:coord><gml:X>0</gml:X><gml:Y>-3</gml:Y></gml:coord> | ||
<gml:coord><gml:X>8</gml:X><gml:Y>2</gml:Y></gml:coord> | ||
</gml:Box> | ||
</gml:boundedBy> | ||
|
||
<gml:featureMember> | ||
<ogr:interpolate_point_lines fid="lines.0"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7,2</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
</ogr:interpolate_point_lines> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_lines fid="lines.1"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
</ogr:interpolate_point_lines> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_lines fid="lines.2"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,1</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
</ogr:interpolate_point_lines> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_lines fid="lines.3"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
</ogr:interpolate_point_lines> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_lines fid="lines.4"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-3</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
</ogr:interpolate_point_lines> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_lines fid="lines.5"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>6.70710678118655,-2.29289321881345</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
</ogr:interpolate_point_lines> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_lines fid="lines.6"> | ||
</ogr:interpolate_point_lines> | ||
</gml:featureMember> | ||
</ogr:FeatureCollection> |
23 changes: 23 additions & 0 deletions
23
python/plugins/processing/tests/testdata/expected/interpolate_point_lines.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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="interpolate_point_lines" type="ogr:interpolate_point_lines_Type" substitutionGroup="gml:_Feature"/> | ||
<xs:complexType name="interpolate_point_lines_Type"> | ||
<xs:complexContent> | ||
<xs:extension base="gml:AbstractFeatureType"> | ||
<xs:sequence> | ||
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/> | ||
</xs:sequence> | ||
</xs:extension> | ||
</xs:complexContent> | ||
</xs:complexType> | ||
</xs:schema> |
61 changes: 61 additions & 0 deletions
61
python/plugins/processing/tests/testdata/expected/interpolate_point_polys.gml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ogr:FeatureCollection | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://ogr.maptools.org/ interpolate_point_polys.xsd" | ||
xmlns:ogr="http://ogr.maptools.org/" | ||
xmlns:gml="http://www.opengis.net/gml"> | ||
<gml:boundedBy> | ||
<gml:Box> | ||
<gml:coord><gml:X>-1</gml:X><gml:Y>1</gml:Y></gml:coord> | ||
<gml:coord><gml:X>8</gml:X><gml:Y>6</gml:Y></gml:coord> | ||
</gml:Box> | ||
</gml:boundedBy> | ||
|
||
<gml:featureMember> | ||
<ogr:interpolate_point_polys fid="polys.0"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>-1,1</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
<ogr:name>aaaaa</ogr:name> | ||
<ogr:intval>33</ogr:intval> | ||
<ogr:floatval>44.123456</ogr:floatval> | ||
</ogr:interpolate_point_polys> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_polys fid="polys.1"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.41421356237309,4.0</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
<ogr:name>Aaaaa</ogr:name> | ||
<ogr:intval>-33</ogr:intval> | ||
<ogr:floatval>0</ogr:floatval> | ||
</ogr:interpolate_point_polys> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_polys fid="polys.2"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,6</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
<ogr:name>bbaaa</ogr:name> | ||
<ogr:intval xsi:nil="true"/> | ||
<ogr:floatval>0.123</ogr:floatval> | ||
</ogr:interpolate_point_polys> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_polys fid="polys.3"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,1</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
<ogr:name>ASDF</ogr:name> | ||
<ogr:intval>0</ogr:intval> | ||
<ogr:floatval xsi:nil="true"/> | ||
</ogr:interpolate_point_polys> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_polys fid="polys.4"> | ||
<ogr:name xsi:nil="true"/> | ||
<ogr:intval>120</ogr:intval> | ||
<ogr:floatval>-100291.43213</ogr:floatval> | ||
</ogr:interpolate_point_polys> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:interpolate_point_polys fid="polys.5"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.89736659610103,1.36754446796632</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
<ogr:name>elim</ogr:name> | ||
<ogr:intval>2</ogr:intval> | ||
<ogr:floatval>3.33</ogr:floatval> | ||
</ogr:interpolate_point_polys> | ||
</gml:featureMember> | ||
</ogr:FeatureCollection> |
43 changes: 43 additions & 0 deletions
43
python/plugins/processing/tests/testdata/expected/interpolate_point_polys.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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="interpolate_point_polys" type="ogr:interpolate_point_polys_Type" substitutionGroup="gml:_Feature"/> | ||
<xs:complexType name="interpolate_point_polys_Type"> | ||
<xs:complexContent> | ||
<xs:extension base="gml:AbstractFeatureType"> | ||
<xs:sequence> | ||
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/> | ||
<xs:element name="name" nillable="true" minOccurs="0" maxOccurs="1"> | ||
<xs:simpleType> | ||
<xs:restriction base="xs:string"> | ||
<xs:maxLength value="5"/> | ||
</xs:restriction> | ||
</xs:simpleType> | ||
</xs:element> | ||
<xs:element name="intval" 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="floatval" 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/analysis/processing/qgsalgorithminterpolatepoint.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/*************************************************************************** | ||
qgsalgorithminterpolatepoint.cpp | ||
--------------------- | ||
begin : August 2018 | ||
copyright : (C) 2018 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsalgorithminterpolatepoint.h" | ||
#include "qgsgeometrycollection.h" | ||
#include "qgscurve.h" | ||
|
||
///@cond PRIVATE | ||
|
||
QString QgsInterpolatePointAlgorithm::name() const | ||
{ | ||
return QStringLiteral( "interpolatepoint" ); | ||
} | ||
|
||
QString QgsInterpolatePointAlgorithm::displayName() const | ||
{ | ||
return QObject::tr( "Interpolate point on line" ); | ||
} | ||
|
||
QStringList QgsInterpolatePointAlgorithm::tags() const | ||
{ | ||
return QObject::tr( "linestring,reference,referencing,distance,interpolate" ).split( ',' ); | ||
} | ||
|
||
QString QgsInterpolatePointAlgorithm::group() const | ||
{ | ||
return QObject::tr( "Vector geometry" ); | ||
} | ||
|
||
QString QgsInterpolatePointAlgorithm::groupId() const | ||
{ | ||
return QStringLiteral( "vectorgeometry" ); | ||
} | ||
|
||
QString QgsInterpolatePointAlgorithm::outputName() const | ||
{ | ||
return QObject::tr( "Interpolated points" ); | ||
} | ||
|
||
QString QgsInterpolatePointAlgorithm::shortHelpString() const | ||
{ | ||
return QObject::tr( "This algorithm creates a point geometry interpolated at a set distance along line geometries." ); | ||
} | ||
|
||
QString QgsInterpolatePointAlgorithm::shortDescription() const | ||
{ | ||
return QObject::tr( "Interpolates a point along lines at a set distance." ); | ||
} | ||
|
||
QList<int> QgsInterpolatePointAlgorithm::inputLayerTypes() const | ||
{ | ||
return QList<int>() << QgsProcessing::TypeVectorLine << QgsProcessing::TypeVectorPolygon; | ||
} | ||
|
||
QgsProcessing::SourceType QgsInterpolatePointAlgorithm::outputLayerType() const | ||
{ | ||
return QgsProcessing::TypeVectorPoint; | ||
} | ||
|
||
QgsWkbTypes::Type QgsInterpolatePointAlgorithm::outputWkbType( QgsWkbTypes::Type ) const | ||
{ | ||
return QgsWkbTypes::Point; | ||
} | ||
|
||
QgsInterpolatePointAlgorithm *QgsInterpolatePointAlgorithm::createInstance() const | ||
{ | ||
return new QgsInterpolatePointAlgorithm(); | ||
} | ||
|
||
void QgsInterpolatePointAlgorithm::initParameters( const QVariantMap & ) | ||
{ | ||
std::unique_ptr< QgsProcessingParameterDistance> distance = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral( "DISTANCE" ), | ||
QObject::tr( "Distance" ), 0.0, QStringLiteral( "INPUT" ), false, 0 ); | ||
distance->setIsDynamic( true ); | ||
distance->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "DISTANCE" ), QObject::tr( "Distance" ), QgsPropertyDefinition::DoublePositive ) ); | ||
distance->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) ); | ||
addParameter( distance.release() ); | ||
} | ||
|
||
QgsProcessingFeatureSource::Flag QgsInterpolatePointAlgorithm::sourceFlags() const | ||
{ | ||
// skip geometry checks - this algorithm doesn't care about invalid geometries | ||
return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks; | ||
} | ||
|
||
bool QgsInterpolatePointAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback * ) | ||
{ | ||
mDistance = parameterAsDouble( parameters, QStringLiteral( "DISTANCE" ), context ); | ||
mDynamicDistance = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "DISTANCE" ) ); | ||
if ( mDynamicDistance ) | ||
mDistanceProperty = parameters.value( QStringLiteral( "DISTANCE" ) ).value< QgsProperty >(); | ||
|
||
return true; | ||
} | ||
|
||
QgsFeatureList QgsInterpolatePointAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback * ) | ||
{ | ||
QgsFeature f = feature; | ||
if ( f.hasGeometry() ) | ||
{ | ||
const QgsGeometry geometry = f.geometry(); | ||
double distance = mDistance; | ||
if ( mDynamicDistance ) | ||
distance = mDistanceProperty.valueAsDouble( context.expressionContext(), distance ); | ||
|
||
f.setGeometry( geometry.interpolate( distance ) ); | ||
} | ||
return QgsFeatureList() << f; | ||
} | ||
|
||
///@endcond | ||
|
||
|
Oops, something went wrong.