Skip to content
Permalink
Browse files

[FEATURE][processing] "Create parallel lines" algorithm

This algorithm creates copies of line features in a layer, by
creating multiple parallel versions of each feature. Each copy is offset
by a preset distance.
  • Loading branch information
nyalldawson committed Jul 27, 2018
1 parent b80ad5e commit 76c84f14d795ef88ad8dafb138890386ffb300d1
@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ create_parallel_lines.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>-3.6</gml:Y></gml:coord>
<gml:coord><gml:X>11.42426406871193</gml:X><gml:Y>5</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:create_parallel_lines fid="lines.0">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,2 9,2 9,3 11,5</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>0</ogr:instance>
<ogr:offset>0</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.0">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>11.1414213562373,4.85857864376269 9.2,2.91715728752538 9.2,1.8 6.0,1.8</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>1</ogr:instance>
<ogr:offset>-0.2</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.0">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>11.2828427124746,4.71715728752538 9.4,2.83431457505076 9.4,1.6 6.0,1.6</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>2</ogr:instance>
<ogr:offset>-0.4</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.0">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>11.4242640687119,4.57573593128807 9.6,2.75147186257614 9.6,1.4 6.0,1.4</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>3</ogr:instance>
<ogr:offset>-0.6</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.1">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>-1,-1 1,-1</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>0</ogr:instance>
<ogr:offset>0</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.1">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>1.0,-1.2 -1.0,-1.2</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>1</ogr:instance>
<ogr:offset>-0.2</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.1">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>1.0,-1.4 -1.0,-1.4</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>2</ogr:instance>
<ogr:offset>-0.4</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.1">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>1.0,-1.6 -1.0,-1.6</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>3</ogr:instance>
<ogr:offset>-0.6</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.2">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>2,0 2,2 3,2 3,3</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>0</ogr:instance>
<ogr:offset>0</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.2">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>3.2,3.0 3.2,1.8 2.8,1.8 2.2,1.8 2.2,0.0</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>1</ogr:instance>
<ogr:offset>-0.2</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.2">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>3.4,3.0 3.4,1.6 2.93333333333333,1.6 2.4,1.6 2.4,0.0</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>2</ogr:instance>
<ogr:offset>-0.4</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.2">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>3.6,3.0 3.6,1.4 3.06666666666667,1.4 2.6,1.4 2.6,0.0</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>3</ogr:instance>
<ogr:offset>-0.6</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.3">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>3,1 5,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>0</ogr:instance>
<ogr:offset>0</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.3">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>5.0,0.8 3.0,0.8</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>1</ogr:instance>
<ogr:offset>-0.2</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.3">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>5.0,0.6 3.0,0.6</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>2</ogr:instance>
<ogr:offset>-0.4</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.3">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>5.0,0.4 3.0,0.4</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>3</ogr:instance>
<ogr:offset>-0.6</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.4">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>7,-3 10,-3</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>0</ogr:instance>
<ogr:offset>0</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.4">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>10.0,-3.2 7.0,-3.2</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>1</ogr:instance>
<ogr:offset>-0.2</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.4">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>10.0,-3.4 7.0,-3.4</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>2</ogr:instance>
<ogr:offset>-0.4</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.4">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>10.0,-3.6 7.0,-3.6</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>3</ogr:instance>
<ogr:offset>-0.6</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.5">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,-3 10,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>0</ogr:instance>
<ogr:offset>0</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.5">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>10.1414213562373,0.858578643762691 6.14142135623731,-3.14142135623731</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>1</ogr:instance>
<ogr:offset>-0.2</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.5">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>10.2828427124746,0.717157287525381 6.28284271247462,-3.28284271247462</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>2</ogr:instance>
<ogr:offset>-0.4</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.5">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>10.4242640687119,0.575735931288071 6.42426406871193,-3.42426406871193</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:instance>3</ogr:instance>
<ogr:offset>-0.6</ogr:offset>
</ogr:create_parallel_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:create_parallel_lines fid="lines.6">
<ogr:instance xsi:nil="true"/>
<ogr:offset xsi:nil="true"/>
</ogr:create_parallel_lines>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,36 @@
<?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="create_parallel_lines" type="ogr:create_parallel_lines_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="create_parallel_lines_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:LineStringPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="instance" 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="offset" 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>
@@ -5908,5 +5908,20 @@ tests:
name: expected/feature_array.shp
type: vector

- algorithm: native:parallellines
name: Create parallel lines
params:
COUNT: 3
INPUT:
name: lines.gml
type: vector
JOIN_STYLE: 1
MITER_LIMIT: 2.0
OFFSET: -0.2
SEGMENTS: 8
results:
OUTPUT:
name: expected/create_parallel_lines.gml
type: vector

# See ../README.md for a description of the file format
@@ -61,6 +61,7 @@ SET(QGIS_ANALYSIS_SRCS
processing/qgsalgorithmorderbyexpression.cpp
processing/qgsalgorithmorientedminimumboundingbox.cpp
processing/qgsalgorithmpackage.cpp
processing/qgsalgorithmparallellines.cpp
processing/qgsalgorithmpointonsurface.cpp
processing/qgsalgorithmprojectpointcartesian.cpp
processing/qgsalgorithmpromotetomultipart.cpp
@@ -36,12 +36,12 @@ QStringList QgsArrayFeaturesAlgorithm::tags() const

QString QgsArrayFeaturesAlgorithm::group() const
{
return QObject::tr( "Vector geometry" );
return QObject::tr( "Vector creation" );
}

QString QgsArrayFeaturesAlgorithm::groupId() const
{
return QStringLiteral( "vectorgeometry" );
return QStringLiteral( "vectorcreation" );
}

QString QgsArrayFeaturesAlgorithm::outputName() const
@@ -69,7 +69,7 @@ void QgsArrayFeaturesAlgorithm::initParameters( const QVariantMap & )
{
std::unique_ptr< QgsProcessingParameterNumber > count = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "COUNT" ),
QObject::tr( "Number of features to create" ), QgsProcessingParameterNumber::Integer,
10, true, 1 );
10, false, 1 );
count->setIsDynamic( true );
count->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "COUNT" ), QObject::tr( "Number of features to create" ), QgsPropertyDefinition::IntegerPositiveGreaterZero ) );
count->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );

0 comments on commit 76c84f1

Please sign in to comment.
You can’t perform that action at this time.