Skip to content
Permalink
Browse files

Merge pull request #8923 from m-kuhn/native_densify_by_interval

Add native densify by interval algorithm
  • Loading branch information
m-kuhn committed Jan 21, 2019
2 parents b6f7176 + 25acd79 commit b391c0876fee2dd1161dcf9136f097b96d2cd822

This file was deleted.

@@ -61,7 +61,6 @@
from .DeleteColumn import DeleteColumn
from .DeleteDuplicateGeometries import DeleteDuplicateGeometries
from .DensifyGeometries import DensifyGeometries
from .DensifyGeometriesInterval import DensifyGeometriesInterval
from .EliminateSelection import EliminateSelection
from .ExecuteSQL import ExecuteSQL
from .ExportGeometryInfo import ExportGeometryInfo
@@ -172,7 +171,6 @@ def getAlgs(self):
DeleteColumn(),
DeleteDuplicateGeometries(),
DensifyGeometries(),
DensifyGeometriesInterval(),
EliminateSelection(),
ExecuteSQL(),
ExportGeometryInfo(),
@@ -32,6 +32,7 @@ SET(QGIS_ANALYSIS_SRCS
processing/qgsalgorithmclip.cpp
processing/qgsalgorithmconvexhull.cpp
processing/qgsalgorithmdbscanclustering.cpp
processing/qgsalgorithmdensifygeometriesbyinterval.cpp
processing/qgsalgorithmdifference.cpp
processing/qgsalgorithmdissolve.cpp
processing/qgsalgorithmdrape.cpp
@@ -0,0 +1,116 @@
/***************************************************************************
qgsalgorithmdensifygeometries.cpp
---------------------
begin : January 2019
copyright : (C) 2019 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************/

/***************************************************************************
* *
* 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 "qgsalgorithmdensifygeometriesbyinterval.h"

///@cond PRIVATE

QString QgsDensifyGeometriesByIntervalAlgorithm::name() const
{
return QStringLiteral( "densifygeometriesgivenaninterval" );
}

QString QgsDensifyGeometriesByIntervalAlgorithm::displayName() const
{
return QObject::tr( "Densify by interval" );
}

QStringList QgsDensifyGeometriesByIntervalAlgorithm::tags() const
{
return QObject::tr( "add,vertex,vertices,points,nodes" ).split( ',' );
}

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

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

QString QgsDensifyGeometriesByIntervalAlgorithm::shortHelpString() const
{
return QObject::tr( "Geometries are densified by adding additional vertices on "
"edges that have a maximum distance of the interval parameter "
"in map units." );
}

QString QgsDensifyGeometriesByIntervalAlgorithm::shortDescription() const
{
return QObject::tr( "Creates a densified version of geometries." );
}

QgsDensifyGeometriesByIntervalAlgorithm *QgsDensifyGeometriesByIntervalAlgorithm::createInstance() const
{
return new QgsDensifyGeometriesByIntervalAlgorithm;

}

QList<int> QgsDensifyGeometriesByIntervalAlgorithm::inputLayerTypes() const
{
return QList<int>() << QgsProcessing::TypeVectorLine << QgsProcessing::TypeVectorPolygon;
}

void QgsDensifyGeometriesByIntervalAlgorithm::initParameters( const QVariantMap &configuration )
{
Q_UNUSED( configuration )
std::unique_ptr<QgsProcessingParameterDistance> interval = qgis::make_unique<QgsProcessingParameterDistance>( QStringLiteral( "INTERVAL" ),
QObject::tr( "Interval between vertices to add" ),
1, QStringLiteral( "INPUT" ), false, 0, 10000000 );
interval->setIsDynamic( true );
interval->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "Interval" ), QObject::tr( "Interval" ), QgsPropertyDefinition::DoublePositive ) );
interval->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
addParameter( interval.release() );
}

QString QgsDensifyGeometriesByIntervalAlgorithm::outputName() const
{
return QObject::tr( "Densified" );
}

QgsFeatureList QgsDensifyGeometriesByIntervalAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
Q_UNUSED( context );
Q_UNUSED( feedback );
QgsFeature modifiedFeature = feature;

double interval = mInterval;
if ( mDynamicInterval )
interval = mIntervalProperty.valueAsDouble( context.expressionContext(), interval );

if ( feature.hasGeometry() )
modifiedFeature.setGeometry( feature.geometry().densifyByDistance( mInterval ) );

return QgsFeatureList() << modifiedFeature;
}

bool QgsDensifyGeometriesByIntervalAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
Q_UNUSED( feedback );
mInterval = parameterAsDouble( parameters, QStringLiteral( "INTERVAL" ), context );

mDynamicInterval = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "INTERVAL" ) );
if ( mDynamicInterval )
mIntervalProperty = parameters.value( QStringLiteral( "INTERVAL" ) ).value< QgsProperty >();

return true;
}

///@endcond PRIVATE
@@ -0,0 +1,57 @@
/***************************************************************************
qgsalgorithmdensifygeometries.h
---------------------
begin : January 2019
copyright : (C) 2019 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************/

/***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#ifndef QGSALGORITHMDENSIFYGEOMETRIES_H
#define QGSALGORITHMDENSIFYGEOMETRIES_H

#define SIP_NO_FILE

#include "qgis.h"
#include "qgsprocessingalgorithm.h"

///@cond PRIVATE


class QgsDensifyGeometriesByIntervalAlgorithm : public QgsProcessingFeatureBasedAlgorithm
{
public:

QgsDensifyGeometriesByIntervalAlgorithm() = default;
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
QString group() const override;
QString groupId() const override;
QString shortHelpString() const override;
QString shortDescription() const override;
QgsDensifyGeometriesByIntervalAlgorithm *createInstance() const override SIP_FACTORY;
QList<int> inputLayerTypes() const override;

protected:
void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
QString outputName() const override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

private:
double mInterval = 0.0;
bool mDynamicInterval = false;
QgsProperty mIntervalProperty;
};

///@endcond PRIVATE
#endif // QGSALGORITHMDENSIFYGEOMETRIES_H
@@ -27,6 +27,7 @@
#include "qgsalgorithmclip.h"
#include "qgsalgorithmconvexhull.h"
#include "qgsalgorithmdbscanclustering.h"
#include "qgsalgorithmdensifygeometriesbyinterval.h"
#include "qgsalgorithmdifference.h"
#include "qgsalgorithmdissolve.h"
#include "qgsalgorithmdrape.h"
@@ -246,6 +247,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
addAlgorithm( new QgsWedgeBuffersAlgorithm() );
addAlgorithm( new QgsZonalHistogramAlgorithm() );
addAlgorithm( new QgsPolygonsToLinesAlgorithm() );
addAlgorithm( new QgsDensifyGeometriesByIntervalAlgorithm() );
}


0 comments on commit b391c08

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