Skip to content

Commit

Permalink
Merge pull request #8923 from m-kuhn/native_densify_by_interval
Browse files Browse the repository at this point in the history
Add native densify by interval algorithm
  • Loading branch information
m-kuhn authored Jan 21, 2019
2 parents b6f7176 + 25acd79 commit b391c08
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 83 deletions.
77 changes: 0 additions & 77 deletions python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/plugins/processing/algs/qgis/QgisAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -172,7 +171,6 @@ def getAlgs(self):
DeleteColumn(),
DeleteDuplicateGeometries(),
DensifyGeometries(),
DensifyGeometriesInterval(),
EliminateSelection(),
ExecuteSQL(),
ExportGeometryInfo(),
Expand Down
1 change: 1 addition & 0 deletions src/analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
116 changes: 116 additions & 0 deletions src/analysis/processing/qgsalgorithmdensifygeometriesbyinterval.cpp
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions src/analysis/processing/qgsalgorithmdensifygeometriesbyinterval.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/analysis/processing/qgsnativealgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -246,6 +247,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
addAlgorithm( new QgsWedgeBuffersAlgorithm() );
addAlgorithm( new QgsZonalHistogramAlgorithm() );
addAlgorithm( new QgsPolygonsToLinesAlgorithm() );
addAlgorithm( new QgsDensifyGeometriesByIntervalAlgorithm() );
}


Expand Down
Loading

0 comments on commit b391c08

Please sign in to comment.