Skip to content
Permalink
Browse files

Add native densify by interval algorithm

  • Loading branch information
m-kuhn committed Jan 21, 2019
1 parent 8db14d8 commit 9452667af3cf0e30535c938af2a4b95b164381b6

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/qgsalgorithmdensifygeometries.cpp
processing/qgsalgorithmdifference.cpp
processing/qgsalgorithmdissolve.cpp
processing/qgsalgorithmdrape.cpp
@@ -0,0 +1,98 @@
/***************************************************************************
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 "qgsalgorithmdensifygeometries.h"

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

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

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

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

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

QString QgsDensifyGeometriesAlgorithm::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 QgsDensifyGeometriesAlgorithm::shortDescription() const
{
return QObject::tr( "Creates a densified version of geometries." );
}

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

}

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

void QgsDensifyGeometriesAlgorithm::initParameters( const QVariantMap &configuration )
{
Q_UNUSED( configuration )
addParameter( new QgsProcessingParameterDistance( QStringLiteral( "INTERVAL" ),
QObject::tr( "Interval between vertices to add" ),
1, QStringLiteral( "INPUT" ), false, 0, 10000000 ) );
}

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

QgsFeatureList QgsDensifyGeometriesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
Q_UNUSED( context );
Q_UNUSED( feedback );
QgsFeature modifiedFeature = feature;
if ( feature.hasGeometry() )
modifiedFeature.setGeometry( feature.geometry().densifyByDistance( mInterval ) );

return QgsFeatureList() << modifiedFeature;
}

bool QgsDensifyGeometriesAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
Q_UNUSED( feedback );
mInterval = parameterAsDouble( parameters, QStringLiteral( "INTERVAL" ), context );
return true;
}
@@ -0,0 +1,55 @@
/***************************************************************************
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 QgsDensifyGeometriesAlgorithm : public QgsProcessingFeatureBasedAlgorithm
{
public:

QgsDensifyGeometriesAlgorithm() = 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;
QgsDensifyGeometriesAlgorithm *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;
};

///@endcond PRIVATE
#endif // QGSALGORITHMDENSIFYGEOMETRIES_H
@@ -27,6 +27,7 @@
#include "qgsalgorithmclip.h"
#include "qgsalgorithmconvexhull.h"
#include "qgsalgorithmdbscanclustering.h"
#include "qgsalgorithmdensifygeometries.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 QgsDensifyGeometriesAlgorithm() );
}


0 comments on commit 9452667

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