-
-
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.
Merge pull request #8923 from m-kuhn/native_densify_by_interval
Add native densify by interval algorithm
- Loading branch information
Showing
7 changed files
with
268 additions
and
83 deletions.
There are no files selected for viewing
77 changes: 0 additions & 77 deletions
77
python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py
This file was deleted.
Oops, something went wrong.
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
116 changes: 116 additions & 0 deletions
116
src/analysis/processing/qgsalgorithmdensifygeometriesbyinterval.cpp
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,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 ¶meters, 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
57
src/analysis/processing/qgsalgorithmdensifygeometriesbyinterval.h
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,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 ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override; | ||
|
||
private: | ||
double mInterval = 0.0; | ||
bool mDynamicInterval = false; | ||
QgsProperty mIntervalProperty; | ||
}; | ||
|
||
///@endcond PRIVATE | ||
#endif // QGSALGORITHMDENSIFYGEOMETRIES_H |
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
Oops, something went wrong.