Skip to content

Commit

Permalink
Move native c++ processing algorithms from core library to analysis
Browse files Browse the repository at this point in the history
And split into separate files for each algorithm
  • Loading branch information
nyalldawson committed Oct 16, 2017
1 parent 8dd8a9b commit e92e20e
Show file tree
Hide file tree
Showing 83 changed files with 7,268 additions and 4,407 deletions.
1 change: 1 addition & 0 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ IF(WITH_APIDOC)
${CMAKE_SOURCE_DIR}/src/analysis
${CMAKE_SOURCE_DIR}/src/analysis/interpolation
${CMAKE_SOURCE_DIR}/src/analysis/network
${CMAKE_SOURCE_DIR}/src/analysis/processing
${CMAKE_SOURCE_DIR}/src/analysis/raster
${CMAKE_SOURCE_DIR}/src/analysis/vector
${CMAKE_SOURCE_DIR}/src/3d
Expand Down
2 changes: 2 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,13 @@ ENDIF (WITH_SERVER AND WITH_SERVER_PLUGINS)

# additional analysis includes
INCLUDE_DIRECTORIES(BEFORE
../src/analysis/processing
../src/analysis/vector
../src/analysis/raster
../src/analysis/network
../src/analysis/interpolation
../src/analysis/openstreetmap
${CMAKE_BINARY_DIR}/src/analysis/processing
${CMAKE_BINARY_DIR}/src/analysis/vector
${CMAKE_BINARY_DIR}/src/analysis/raster
${CMAKE_BINARY_DIR}/src/analysis/network
Expand Down
1 change: 1 addition & 0 deletions python/analysis/analysis_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
%Include network/qgsnetworkdistancestrategy.sip
%Include network/qgsgraphanalyzer.sip
%Include network/qgsvectorlayerdirector.sip
%Include processing/qgsnativealgorithms.sip
%Include network/qgsgraphdirector.sip
55 changes: 55 additions & 0 deletions python/analysis/processing/qgsnativealgorithms.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/processing/qgsnativealgorithms.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsNativeAlgorithms: QgsProcessingProvider
{
%Docstring
.. versionadded:: 3.0
Native c++ processing algorithm provider.
%End

%TypeHeaderCode
#include "qgsnativealgorithms.h"
%End
public:

QgsNativeAlgorithms( QObject *parent = 0 );
%Docstring
Constructor for QgsNativeAlgorithms.
%End

virtual QIcon icon() const;

virtual QString svgIconPath() const;

virtual QString id() const;

virtual QString name() const;

virtual bool supportsNonFileBasedOutput() const;


protected:

virtual void loadAlgorithms();


};



/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/processing/qgsnativealgorithms.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
5 changes: 4 additions & 1 deletion python/plugins/processing/tests/QgisAlgorithmsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import nose2
import shutil

from qgis.core import (QgsProcessingAlgorithm,
from qgis.core import (QgsApplication,
QgsProcessingAlgorithm,
QgsProcessingFeedback,
QgsProcessingException)
from qgis.analysis import (QgsNativeAlgorithms)
from qgis.testing import start_app, unittest
from processing.tools.dataobjects import createContext

Expand Down Expand Up @@ -64,6 +66,7 @@ class TestQgisAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
@classmethod
def setUpClass(cls):
start_app()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
from processing.core.Processing import Processing
Processing.initialize()
cls.cleanup_paths = []
Expand Down
39 changes: 39 additions & 0 deletions src/analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,42 @@ SET(QGIS_ANALYSIS_SRCS
interpolation/TriDecorator.cpp
interpolation/Vector3D.cpp

processing/qgsalgorithmaddincrementalfield.cpp
processing/qgsalgorithmassignprojection.cpp
processing/qgsalgorithmboundary.cpp
processing/qgsalgorithmboundingbox.cpp
processing/qgsalgorithmbuffer.cpp
processing/qgsalgorithmcentroid.cpp
processing/qgsalgorithmclip.cpp
processing/qgsalgorithmconvexhull.cpp
processing/qgsalgorithmdissolve.cpp
processing/qgsalgorithmdropgeometry.cpp
processing/qgsalgorithmdropmzvalues.cpp
processing/qgsalgorithmextenttolayer.cpp
processing/qgsalgorithmextractbyattribute.cpp
processing/qgsalgorithmextractbyexpression.cpp
processing/qgsalgorithmextractbyextent.cpp
processing/qgsalgorithmextractbylocation.cpp
processing/qgsalgorithmfixgeometries.cpp
processing/qgsalgorithmjoinbyattribute.cpp
processing/qgsalgorithmjoinwithlines.cpp
processing/qgsalgorithmlineintersection.cpp
processing/qgsalgorithmmeancoordinates.cpp
processing/qgsalgorithmmergelines.cpp
processing/qgsalgorithmminimumenclosingcircle.cpp
processing/qgsalgorithmmultiparttosinglepart.cpp
processing/qgsalgorithmorientedminimumboundingbox.cpp
processing/qgsalgorithmrasterlayeruniquevalues.cpp
processing/qgsalgorithmremovenullgeometry.cpp
processing/qgsalgorithmpromotetomultipart.cpp
processing/qgsalgorithmsaveselectedfeatures.cpp
processing/qgsalgorithmsimplify.cpp
processing/qgsalgorithmsmooth.cpp
processing/qgsalgorithmsplitwithlines.cpp
processing/qgsalgorithmsubdivide.cpp
processing/qgsalgorithmtransform.cpp
processing/qgsnativealgorithms.cpp

raster/qgsalignraster.cpp
raster/qgsninecellfilter.cpp
raster/qgsruggednessfilter.cpp
Expand All @@ -47,6 +83,8 @@ SET(QGIS_ANALYSIS_SRCS
)

SET(QGIS_ANALYSIS_MOC_HDRS
processing/qgsnativealgorithms.h

vector/qgsgeometrysnapper.h

network/qgsgraphdirector.h
Expand Down Expand Up @@ -142,6 +180,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core/
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/processing
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/metadata
Expand Down
96 changes: 96 additions & 0 deletions src/analysis/processing/qgsalgorithmaddincrementalfield.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/***************************************************************************
qgsalgorithmaddincrementalfield.cpp
-----------------------------------
begin : April 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson 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 "qgsalgorithmaddincrementalfield.h"

///@cond PRIVATE

QString QgsAddIncrementalFieldAlgorithm::name() const
{
return QStringLiteral( "addautoincrementalfield" );
}

QString QgsAddIncrementalFieldAlgorithm::displayName() const
{
return QObject::tr( "Add autoincremental field" );
}

QString QgsAddIncrementalFieldAlgorithm::shortHelpString() const
{
return QObject::tr( "This algorithm adds a new integer field to a vector layer, with a sequential value for each feature.\n\n"
"This field can be used as a unique ID for features in the layer. The new attribute "
"is not added to the input layer but a new layer is generated instead.\n\n"
"The initial starting value for the incremental series can be specified." );
}

QStringList QgsAddIncrementalFieldAlgorithm::tags() const
{
return QObject::tr( "add,create,serial,primary,key,unique,field" ).split( ',' );
}

QString QgsAddIncrementalFieldAlgorithm::group() const
{
return QObject::tr( "Vector table" );
}

QString QgsAddIncrementalFieldAlgorithm::outputName() const
{
return QObject::tr( "Incremented" );
}

QList<int> QgsAddIncrementalFieldAlgorithm::inputLayerTypes() const
{
return QList<int>() << QgsProcessing::TypeVector;
}

QgsAddIncrementalFieldAlgorithm *QgsAddIncrementalFieldAlgorithm::createInstance() const
{
return new QgsAddIncrementalFieldAlgorithm();
}

void QgsAddIncrementalFieldAlgorithm::initParameters( const QVariantMap & )
{
addParameter( new QgsProcessingParameterString( QStringLiteral( "FIELD_NAME" ), QObject::tr( "Field name" ), QStringLiteral( "AUTO" ) ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "START" ), QObject::tr( "Start values at" ),
QgsProcessingParameterNumber::Integer, 0, true ) );
}

QgsFields QgsAddIncrementalFieldAlgorithm::outputFields( const QgsFields &inputFields ) const
{
QgsFields outFields = inputFields;
outFields.append( QgsField( mFieldName, QVariant::LongLong ) );
return outFields;
}

bool QgsAddIncrementalFieldAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mValue = parameterAsInt( parameters, QStringLiteral( "START" ), context );
mFieldName = parameterAsString( parameters, QStringLiteral( "FIELD_NAME" ), context );
return true;
}

QgsFeature QgsAddIncrementalFieldAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingFeedback * )
{
QgsFeature f = feature;
QgsAttributes attributes = f.attributes();
attributes.append( mValue );
mValue++;
f.setAttributes( attributes );
return f;
}

///@endcond
65 changes: 65 additions & 0 deletions src/analysis/processing/qgsalgorithmaddincrementalfield.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/***************************************************************************
qgsalgorithmaddincrementalfield.h
---------------------------------
begin : April 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson 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 QGSALGORITHMADDINCREMENTALFIELD_H
#define QGSALGORITHMADDINCREMENTALFIELD_H

#define SIP_NO_FILE

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

///@cond PRIVATE

/**
* Native add incremental field algorithm.
*/
class QgsAddIncrementalFieldAlgorithm : public QgsProcessingFeatureBasedAlgorithm
{

public:

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

protected:

void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
QString outputName() const override;
QgsFields outputFields( const QgsFields &inputFields ) const override;

bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeature processFeature( const QgsFeature &feature, QgsProcessingFeedback *feedback ) override;

private:

long long mValue = 0;
QString mFieldName;

};

///@endcond PRIVATE

#endif // QGSNATIVEALGORITHMS_H


Loading

0 comments on commit e92e20e

Please sign in to comment.