Skip to content
Permalink
Browse files

[processing] Make translate algorithm native

And add option to translate z/m values
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent dd223d9 commit ff900c0b05d65aef612e22cdcbbb08cdb0b3c6b9
@@ -143,7 +143,6 @@
from .TextToFloat import TextToFloat
from .TinInterpolation import TinInterpolation
from .TopoColors import TopoColor
from .Translate import Translate
from .TruncateTable import TruncateTable
from .Union import Union
from .UniqueValues import UniqueValues
@@ -268,7 +267,6 @@ def getAlgs(self):
TextToFloat(),
TinInterpolation(),
TopoColor(),
Translate(),
TruncateTable(),
Union(),
UniqueValues(),

This file was deleted.

@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -1087,7 +1087,7 @@ tests:
geometry:
precision: 7

- algorithm: qgis:translategeometry
- algorithm: native:translategeometry
name: Lines translated
params:
DELTA_X: 0.1
@@ -59,6 +59,7 @@ SET(QGIS_ANALYSIS_SRCS
processing/qgsalgorithmsubdivide.cpp
processing/qgsalgorithmtransect.cpp
processing/qgsalgorithmtransform.cpp
processing/qgsalgorithmtranslate.cpp

processing/qgsnativealgorithms.cpp

@@ -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 &parameters, 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


0 comments on commit ff900c0

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