-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] Make translate algorithm native
And add option to translate z/m values
- Loading branch information
1 parent
dd223d9
commit ff900c0
Showing
13 changed files
with
326 additions
and
80 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
python/plugins/processing/tests/testdata/expected/buffer_polys.gfs
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,32 @@ | ||
<GMLFeatureClassList> | ||
<GMLFeatureClass> | ||
<Name>buffer_polys</Name> | ||
<ElementPath>buffer_polys</ElementPath> | ||
<!--POLYGON--> | ||
<GeometryType>3</GeometryType> | ||
<SRSName>EPSG:4326</SRSName> | ||
<DatasetSpecificInfo> | ||
<FeatureCount>6</FeatureCount> | ||
<ExtentXMin>-1.50000</ExtentXMin> | ||
<ExtentXMax>10.50000</ExtentXMax> | ||
<ExtentYMin>-3.50000</ExtentYMin> | ||
<ExtentYMax>6.50000</ExtentYMax> | ||
</DatasetSpecificInfo> | ||
<PropertyDefn> | ||
<Name>name</Name> | ||
<ElementPath>name</ElementPath> | ||
<Type>String</Type> | ||
<Width>5</Width> | ||
</PropertyDefn> | ||
<PropertyDefn> | ||
<Name>intval</Name> | ||
<ElementPath>intval</ElementPath> | ||
<Type>Integer</Type> | ||
</PropertyDefn> | ||
<PropertyDefn> | ||
<Name>floatval</Name> | ||
<ElementPath>floatval</ElementPath> | ||
<Type>Real</Type> | ||
</PropertyDefn> | ||
</GMLFeatureClass> | ||
</GMLFeatureClassList> |
16 changes: 16 additions & 0 deletions
16
python/plugins/processing/tests/testdata/expected/gridify_lines.gfs
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,16 @@ | ||
<GMLFeatureClassList> | ||
<GMLFeatureClass> | ||
<Name>gridify_lines</Name> | ||
<ElementPath>gridify_lines</ElementPath> | ||
<!--LINESTRING--> | ||
<GeometryType>2</GeometryType> | ||
<SRSName>EPSG:4326</SRSName> | ||
<DatasetSpecificInfo> | ||
<FeatureCount>7</FeatureCount> | ||
<ExtentXMin>-2.00000</ExtentXMin> | ||
<ExtentXMax>12.00000</ExtentXMax> | ||
<ExtentYMin>-4.00000</ExtentYMin> | ||
<ExtentYMax>6.00000</ExtentYMax> | ||
</DatasetSpecificInfo> | ||
</GMLFeatureClass> | ||
</GMLFeatureClassList> |
32 changes: 32 additions & 0 deletions
32
python/plugins/processing/tests/testdata/expected/gridify_polys.gfs
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,32 @@ | ||
<GMLFeatureClassList> | ||
<GMLFeatureClass> | ||
<Name>gridify_polys</Name> | ||
<ElementPath>gridify_polys</ElementPath> | ||
<!--POLYGON--> | ||
<GeometryType>3</GeometryType> | ||
<SRSName>EPSG:4326</SRSName> | ||
<DatasetSpecificInfo> | ||
<FeatureCount>6</FeatureCount> | ||
<ExtentXMin>-2.00000</ExtentXMin> | ||
<ExtentXMax>10.00000</ExtentXMax> | ||
<ExtentYMin>-4.00000</ExtentYMin> | ||
<ExtentYMax>6.00000</ExtentYMax> | ||
</DatasetSpecificInfo> | ||
<PropertyDefn> | ||
<Name>name</Name> | ||
<ElementPath>name</ElementPath> | ||
<Type>String</Type> | ||
<Width>5</Width> | ||
</PropertyDefn> | ||
<PropertyDefn> | ||
<Name>intval</Name> | ||
<ElementPath>intval</ElementPath> | ||
<Type>Integer</Type> | ||
</PropertyDefn> | ||
<PropertyDefn> | ||
<Name>floatval</Name> | ||
<ElementPath>floatval</ElementPath> | ||
<Type>Real</Type> | ||
</PropertyDefn> | ||
</GMLFeatureClass> | ||
</GMLFeatureClassList> |
16 changes: 16 additions & 0 deletions
16
python/plugins/processing/tests/testdata/expected/lines_bounds.gfs
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,16 @@ | ||
<GMLFeatureClassList> | ||
<GMLFeatureClass> | ||
<Name>lines_bounds</Name> | ||
<ElementPath>lines_bounds</ElementPath> | ||
<!--POLYGON--> | ||
<GeometryType>3</GeometryType> | ||
<SRSName>EPSG:4326</SRSName> | ||
<DatasetSpecificInfo> | ||
<FeatureCount>7</FeatureCount> | ||
<ExtentXMin>-1.00000</ExtentXMin> | ||
<ExtentXMax>11.00000</ExtentXMax> | ||
<ExtentYMin>-3.00000</ExtentYMin> | ||
<ExtentYMax>5.00000</ExtentYMax> | ||
</DatasetSpecificInfo> | ||
</GMLFeatureClass> | ||
</GMLFeatureClassList> |
16 changes: 16 additions & 0 deletions
16
python/plugins/processing/tests/testdata/expected/multiline_offset.gfs
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,16 @@ | ||
<GMLFeatureClassList> | ||
<GMLFeatureClass> | ||
<Name>multiline_offset</Name> | ||
<ElementPath>multiline_offset</ElementPath> | ||
<!--MULTILINESTRING--> | ||
<GeometryType>5</GeometryType> | ||
<SRSName>EPSG:4326</SRSName> | ||
<DatasetSpecificInfo> | ||
<FeatureCount>4</FeatureCount> | ||
<ExtentXMin>-1.00000</ExtentXMin> | ||
<ExtentXMax>6.02404</ExtentXMax> | ||
<ExtentYMin>0.00000</ExtentYMin> | ||
<ExtentYMax>5.11935</ExtentYMax> | ||
</DatasetSpecificInfo> | ||
</GMLFeatureClass> | ||
</GMLFeatureClassList> |
31 changes: 31 additions & 0 deletions
31
python/plugins/processing/tests/testdata/expected/variable_buffer_points.gfs
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,31 @@ | ||
<GMLFeatureClassList> | ||
<GMLFeatureClass> | ||
<Name>variable_buffer_points</Name> | ||
<ElementPath>variable_buffer_points</ElementPath> | ||
<!--POLYGON--> | ||
<GeometryType>3</GeometryType> | ||
<SRSName>EPSG:3857</SRSName> | ||
<DatasetSpecificInfo> | ||
<FeatureCount>9</FeatureCount> | ||
<ExtentXMin>-50000.00000</ExtentXMin> | ||
<ExtentXMax>990555.92635</ExtentXMax> | ||
<ExtentYMin>-607305.25727</ExtentYMin> | ||
<ExtentYMax>384111.17140</ExtentYMax> | ||
</DatasetSpecificInfo> | ||
<PropertyDefn> | ||
<Name>id</Name> | ||
<ElementPath>id</ElementPath> | ||
<Type>Integer</Type> | ||
</PropertyDefn> | ||
<PropertyDefn> | ||
<Name>id2</Name> | ||
<ElementPath>id2</ElementPath> | ||
<Type>Integer</Type> | ||
</PropertyDefn> | ||
<PropertyDefn> | ||
<Name>buffer</Name> | ||
<ElementPath>buffer</ElementPath> | ||
<Type>Integer</Type> | ||
</PropertyDefn> | ||
</GMLFeatureClass> | ||
</GMLFeatureClassList> |
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
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,114 @@ | ||
/*************************************************************************** | ||
qgsalgorithmtranslate.cpp | ||
--------------------- | ||
begin : November 2017 | ||
copyright : (C) 2017 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 "qgsalgorithmtranslate.h" | ||
|
||
///@cond PRIVATE | ||
|
||
QString QgsTranslateAlgorithm::name() const | ||
{ | ||
return QStringLiteral( "translategeometry" ); | ||
} | ||
|
||
QString QgsTranslateAlgorithm::displayName() const | ||
{ | ||
return QObject::tr( "Translate geometry" ); | ||
} | ||
|
||
QStringList QgsTranslateAlgorithm::tags() const | ||
{ | ||
return QObject::tr( "move,shift,transform,z,m,values,add" ).split( ',' ); | ||
} | ||
|
||
QString QgsTranslateAlgorithm::group() const | ||
{ | ||
return QObject::tr( "Vector geometry" ); | ||
} | ||
|
||
QString QgsTranslateAlgorithm::outputName() const | ||
{ | ||
return QObject::tr( "Translated" ); | ||
} | ||
|
||
QString QgsTranslateAlgorithm::shortHelpString() const | ||
{ | ||
return QObject::tr( "This algorithm moves the geometries within a layer, by offsetting them with a specified x and y displacement." ) | ||
+ QStringLiteral( "\n\n" ) | ||
+ QObject::tr( "Z and M values present in the geometry can also be translated." ); | ||
} | ||
|
||
QgsTranslateAlgorithm *QgsTranslateAlgorithm::createInstance() const | ||
{ | ||
return new QgsTranslateAlgorithm(); | ||
} | ||
|
||
void QgsTranslateAlgorithm::initParameters( const QVariantMap & ) | ||
{ | ||
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "DELTA_X" ), | ||
QObject::tr( "Offset distance (x-axis)" ), QgsProcessingParameterNumber::Double, | ||
0.0 ) ); | ||
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "DELTA_Y" ), | ||
QObject::tr( "Offset distance (y-axis)" ), QgsProcessingParameterNumber::Double, | ||
0.0 ) ); | ||
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "DELTA_Z" ), | ||
QObject::tr( "Offset distance (z-axis)" ), QgsProcessingParameterNumber::Double, | ||
0.0 ) ); | ||
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "DELTA_M" ), | ||
QObject::tr( "Offset distance (m values)" ), QgsProcessingParameterNumber::Double, | ||
0.0 ) ); | ||
} | ||
|
||
bool QgsTranslateAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback * ) | ||
{ | ||
mDeltaX = parameterAsDouble( parameters, QStringLiteral( "DELTA_X" ), context ); | ||
mDeltaY = parameterAsDouble( parameters, QStringLiteral( "DELTA_Y" ), context ); | ||
mDeltaZ = parameterAsDouble( parameters, QStringLiteral( "DELTA_Z" ), context ); | ||
mDeltaM = parameterAsDouble( parameters, QStringLiteral( "DELTA_M" ), context ); | ||
|
||
return true; | ||
} | ||
|
||
QgsFeature QgsTranslateAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingFeedback * ) | ||
{ | ||
QgsFeature f = feature; | ||
if ( f.hasGeometry() ) | ||
{ | ||
QgsGeometry geometry = f.geometry(); | ||
if ( mDeltaZ != 0 && !geometry.constGet()->is3D() ) | ||
geometry.get()->addZValue( 0 ); | ||
if ( mDeltaM != 0 && !geometry.constGet()->isMeasure() ) | ||
geometry.get()->addMValue( 0 ); | ||
|
||
geometry.translate( mDeltaX, mDeltaY, mDeltaZ, mDeltaM ); | ||
f.setGeometry( geometry ); | ||
} | ||
return f; | ||
} | ||
|
||
QgsWkbTypes::Type QgsTranslateAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const | ||
{ | ||
QgsWkbTypes::Type wkb = inputWkbType; | ||
if ( mDeltaZ != 0 ) | ||
wkb = QgsWkbTypes::addZ( wkb ); | ||
if ( mDeltaM != 0 ) | ||
wkb = QgsWkbTypes::addM( wkb ); | ||
return wkb; | ||
} | ||
|
||
///@endcond | ||
|
||
|
Oops, something went wrong.