mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-03 00:14:12 -05:00 
			
		
		
		
	Port of Densify Geometries by Count algorithm to C++
This commit is contained in:
		
							parent
							
								
									d76835fec5
								
							
						
					
					
						commit
						ccc7566bf1
					
				@ -57,7 +57,6 @@ from .DefineProjection import DefineProjection
 | 
			
		||||
from .Delaunay import Delaunay
 | 
			
		||||
from .DeleteColumn import DeleteColumn
 | 
			
		||||
from .DeleteDuplicateGeometries import DeleteDuplicateGeometries
 | 
			
		||||
from .DensifyGeometries import DensifyGeometries
 | 
			
		||||
from .EliminateSelection import EliminateSelection
 | 
			
		||||
from .ExecuteSQL import ExecuteSQL
 | 
			
		||||
from .ExportGeometryInfo import ExportGeometryInfo
 | 
			
		||||
@ -167,7 +166,6 @@ class QgisAlgorithmProvider(QgsProcessingProvider):
 | 
			
		||||
                Delaunay(),
 | 
			
		||||
                DeleteColumn(),
 | 
			
		||||
                DeleteDuplicateGeometries(),
 | 
			
		||||
                DensifyGeometries(),
 | 
			
		||||
                EliminateSelection(),
 | 
			
		||||
                ExecuteSQL(),
 | 
			
		||||
                ExportGeometryInfo(),
 | 
			
		||||
 | 
			
		||||
@ -342,7 +342,7 @@ tests:
 | 
			
		||||
        type: vector
 | 
			
		||||
 | 
			
		||||
  - name: Densify geometries
 | 
			
		||||
    algorithm: qgis:densifygeometries
 | 
			
		||||
    algorithm: native:densifygeometries
 | 
			
		||||
    params:
 | 
			
		||||
      INPUT:
 | 
			
		||||
        name: multipolys.gml
 | 
			
		||||
 | 
			
		||||
@ -34,6 +34,7 @@ SET(QGIS_ANALYSIS_SRCS
 | 
			
		||||
  processing/qgsalgorithmclip.cpp
 | 
			
		||||
  processing/qgsalgorithmconvexhull.cpp
 | 
			
		||||
  processing/qgsalgorithmdbscanclustering.cpp
 | 
			
		||||
  processing/qgsalgorithmdensifygeometriesbycount.cpp
 | 
			
		||||
  processing/qgsalgorithmdensifygeometriesbyinterval.cpp
 | 
			
		||||
  processing/qgsalgorithmdifference.cpp
 | 
			
		||||
  processing/qgsalgorithmdissolve.cpp
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										124
									
								
								src/analysis/processing/qgsalgorithmdensifygeometriesbycount.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								src/analysis/processing/qgsalgorithmdensifygeometriesbycount.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,124 @@
 | 
			
		||||
/***************************************************************************
 | 
			
		||||
                         qgsalgorithmdensifygeometries.cpp
 | 
			
		||||
                         ---------------------
 | 
			
		||||
    begin                : October 2019
 | 
			
		||||
    copyright            : (C) 2019 by Clemens Raffler
 | 
			
		||||
    email                : clemens dot raffler 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 "qgsalgorithmdensifygeometriesbycount.h"
 | 
			
		||||
 | 
			
		||||
///@cond PRIVATE
 | 
			
		||||
 | 
			
		||||
QString QgsDensifyGeometriesByCountAlgorithm::name() const
 | 
			
		||||
{
 | 
			
		||||
  return QStringLiteral( "densifygeometries" );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsDensifyGeometriesByCountAlgorithm::displayName() const
 | 
			
		||||
{
 | 
			
		||||
  return QObject::tr( "Densify by count" );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QStringList QgsDensifyGeometriesByCountAlgorithm::tags() const
 | 
			
		||||
{
 | 
			
		||||
  return QObject::tr( "add,vertex,vertices,points,nodes" ).split( ',' );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsDensifyGeometriesByCountAlgorithm::group() const
 | 
			
		||||
{
 | 
			
		||||
  return QObject::tr( "Vector geometry" );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsDensifyGeometriesByCountAlgorithm::groupId() const
 | 
			
		||||
{
 | 
			
		||||
  return QStringLiteral( "vectorgeometry" );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsDensifyGeometriesByCountAlgorithm::shortHelpString() const
 | 
			
		||||
{
 | 
			
		||||
  return QObject::tr( "This algorithm takes a polygon or line layer"
 | 
			
		||||
                      "and generates a new one in which the geometries"
 | 
			
		||||
                      "have a larger number of vertices than the "
 | 
			
		||||
                      "original one. If the geometries have z or m values"
 | 
			
		||||
                      "present then these will be linearly interpolated"
 | 
			
		||||
                      "at the added nodes. The number of new vertices to"
 | 
			
		||||
                      "add to each feature geometry is specified "
 | 
			
		||||
                      "as an input parameter." );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsDensifyGeometriesByCountAlgorithm::shortDescription() const
 | 
			
		||||
{
 | 
			
		||||
  return QObject::tr( "Creates a densified version of geometries." );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QgsDensifyGeometriesByCountAlgorithm *QgsDensifyGeometriesByCountAlgorithm::createInstance() const
 | 
			
		||||
{
 | 
			
		||||
  return new QgsDensifyGeometriesByCountAlgorithm;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QList<int> QgsDensifyGeometriesByCountAlgorithm::inputLayerTypes() const
 | 
			
		||||
{
 | 
			
		||||
  return QList<int>() << QgsProcessing::TypeVectorLine << QgsProcessing::TypeVectorPolygon;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void QgsDensifyGeometriesByCountAlgorithm::initParameters( const QVariantMap &configuration )
 | 
			
		||||
{
 | 
			
		||||
  Q_UNUSED( configuration )
 | 
			
		||||
  std::unique_ptr<QgsProcessingParameterNumber> verticesCnt = qgis::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "VERTICES" ),
 | 
			
		||||
      QObject::tr( "Number of vertices to add" ),
 | 
			
		||||
      QgsProcessingParameterNumber::Integer,
 | 
			
		||||
      1, false, 1, 10000000 );
 | 
			
		||||
  verticesCnt->setIsDynamic( true );
 | 
			
		||||
  verticesCnt->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "VerticesCount" ), QObject::tr( "Vertices count" ), QgsPropertyDefinition::IntegerPositiveGreaterZero ) );
 | 
			
		||||
  verticesCnt->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
 | 
			
		||||
  addParameter( verticesCnt.release() );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsDensifyGeometriesByCountAlgorithm::outputName() const
 | 
			
		||||
{
 | 
			
		||||
  return QObject::tr( "Densified" );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool QgsDensifyGeometriesByCountAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
 | 
			
		||||
{
 | 
			
		||||
  Q_UNUSED( feedback )
 | 
			
		||||
  mVerticesCnt = parameterAsInt( parameters, QStringLiteral( "VERTICES" ), context );
 | 
			
		||||
 | 
			
		||||
  mDynamicVerticesCnt = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "VERTICES" ) );
 | 
			
		||||
  if ( mDynamicVerticesCnt )
 | 
			
		||||
    mVerticesCntProperty = parameters.value( QStringLiteral( "VERTICES" ) ).value< QgsProperty >();
 | 
			
		||||
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QgsFeatureList QgsDensifyGeometriesByCountAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
 | 
			
		||||
{
 | 
			
		||||
  Q_UNUSED( context )
 | 
			
		||||
  Q_UNUSED( feedback )
 | 
			
		||||
  QgsFeature densifiedFeature = feature;
 | 
			
		||||
 | 
			
		||||
  int verticesCnt = mVerticesCnt;
 | 
			
		||||
  if ( mDynamicVerticesCnt )
 | 
			
		||||
    verticesCnt = mVerticesCntProperty.valueAsInt( context.expressionContext(), verticesCnt );
 | 
			
		||||
 | 
			
		||||
  if ( feature.hasGeometry() )
 | 
			
		||||
    densifiedFeature.setGeometry( feature.geometry().densifyByCount( verticesCnt ) );
 | 
			
		||||
 | 
			
		||||
  return QgsFeatureList() << densifiedFeature;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
///@endcond PRIVATE
 | 
			
		||||
@ -0,0 +1,57 @@
 | 
			
		||||
/***************************************************************************
 | 
			
		||||
                         qgsalgorithmdensifygeometries.h
 | 
			
		||||
                         ---------------------
 | 
			
		||||
    begin                : October 2019
 | 
			
		||||
    copyright            : (C) 2019 by Clemens Raffler
 | 
			
		||||
    email                : clemens dot raffler 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.                                   *
 | 
			
		||||
 *                                                                         *
 | 
			
		||||
 ***************************************************************************/
 | 
			
		||||
 | 
			
		||||
#ifndef QGSALGORITHMDENSIFYGEOMETRIESBYCOUNT_H
 | 
			
		||||
#define QGSALGORITHMDENSIFYGEOMETRIESBYCOUNT_H
 | 
			
		||||
 | 
			
		||||
#define SIP_NO_FILE
 | 
			
		||||
 | 
			
		||||
#include "qgis_sip.h"
 | 
			
		||||
#include "qgsprocessingalgorithm.h"
 | 
			
		||||
 | 
			
		||||
///@cond PRIVATE
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class QgsDensifyGeometriesByCountAlgorithm : public QgsProcessingFeatureBasedAlgorithm
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
 | 
			
		||||
    QgsDensifyGeometriesByCountAlgorithm() = 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;
 | 
			
		||||
    QgsDensifyGeometriesByCountAlgorithm *createInstance() const override SIP_FACTORY;
 | 
			
		||||
    QList<int> inputLayerTypes() const override;
 | 
			
		||||
 | 
			
		||||
  protected:
 | 
			
		||||
    void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
 | 
			
		||||
    QString outputName() const override;
 | 
			
		||||
    bool prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
 | 
			
		||||
    QgsFeatureList processFeature( const QgsFeature &feature,  QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    int mVerticesCnt = 0;
 | 
			
		||||
    bool mDynamicVerticesCnt = false;
 | 
			
		||||
    QgsProperty mVerticesCntProperty;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
///@endcond PRIVATE
 | 
			
		||||
#endif // QGSALGORITHMDENSIFYGEOMETRIESBYCOUNT_H
 | 
			
		||||
@ -29,6 +29,7 @@
 | 
			
		||||
#include "qgsalgorithmclip.h"
 | 
			
		||||
#include "qgsalgorithmconvexhull.h"
 | 
			
		||||
#include "qgsalgorithmdbscanclustering.h"
 | 
			
		||||
#include "qgsalgorithmdensifygeometriesbycount.h"
 | 
			
		||||
#include "qgsalgorithmdensifygeometriesbyinterval.h"
 | 
			
		||||
#include "qgsalgorithmdifference.h"
 | 
			
		||||
#include "qgsalgorithmdissolve.h"
 | 
			
		||||
@ -274,6 +275,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
 | 
			
		||||
  addAlgorithm( new QgsZonalHistogramAlgorithm() );
 | 
			
		||||
  addAlgorithm( new QgsPolygonsToLinesAlgorithm() );
 | 
			
		||||
  addAlgorithm( new QgsDensifyGeometriesByIntervalAlgorithm() );
 | 
			
		||||
  addAlgorithm( new QgsDensifyGeometriesByCountAlgorithm() );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user