Skip to content

Commit

Permalink
[processing] Port point on surface to c++
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 3, 2018
1 parent 0a6024b commit 871132e
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 85 deletions.
4 changes: 0 additions & 4 deletions python/plugins/processing/algs/help/qgis.yaml
Expand Up @@ -317,10 +317,6 @@ qgis:orthogonalize: >

The algorithm is iterative. Setting a larger number for the maximum iterations will result in a more orthogonal geometry at the cost of extra processing time.

qgis:pointonsurface: >
Returns a point guaranteed to lie on the surface of a geometry.


qgis:pointsalonglines: >
Creates points at regular intervals along line or polygon geometries. Created points will have new attributes added for the distance along the geometry and the angle of the line at the point.

Expand Down
78 changes: 0 additions & 78 deletions python/plugins/processing/algs/qgis/PointOnSurface.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/plugins/processing/algs/qgis/QgisAlgorithmProvider.py
Expand Up @@ -89,7 +89,6 @@
from .OffsetLine import OffsetLine
from .Orthogonalize import Orthogonalize
from .PointDistance import PointDistance
from .PointOnSurface import PointOnSurface
from .PointsAlongGeometry import PointsAlongGeometry
from .PointsDisplacement import PointsDisplacement
from .PointsFromLines import PointsFromLines
Expand Down Expand Up @@ -211,7 +210,6 @@ def getAlgs(self):
OffsetLine(),
Orthogonalize(),
PointDistance(),
PointOnSurface(),
PointsAlongGeometry(),
PointsDisplacement(),
PointsFromLines(),
Expand Down
Expand Up @@ -870,7 +870,7 @@ tests:
name: expected/zm_dropped.shp
type: vector

- algorithm: qgis:pointonsurface
- algorithm: native:pointonsurface
name: Point on polygon surface
params:
INPUT:
Expand Down
1 change: 1 addition & 0 deletions src/analysis/CMakeLists.txt
Expand Up @@ -51,6 +51,7 @@ SET(QGIS_ANALYSIS_SRCS
processing/qgsalgorithmorderbyexpression.cpp
processing/qgsalgorithmorientedminimumboundingbox.cpp
processing/qgsalgorithmpackage.cpp
processing/qgsalgorithmpointonsurface.cpp
processing/qgsalgorithmprojectpointcartesian.cpp
processing/qgsalgorithmpromotetomultipart.cpp
processing/qgsalgorithmrasterlayeruniquevalues.cpp
Expand Down
77 changes: 77 additions & 0 deletions src/analysis/processing/qgsalgorithmpointonsurface.cpp
@@ -0,0 +1,77 @@
/***************************************************************************
qgsalgorithmpointonsurface.cpp
------------------------
begin : March 2018
copyright : (C) 2018 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 "qgsalgorithmpointonsurface.h"

///@cond PRIVATE

QString QgsPointOnSurfaceAlgorithm::name() const
{
return QStringLiteral( "pointonsurface" );
}

QString QgsPointOnSurfaceAlgorithm::displayName() const
{
return QObject::tr( "Point on surface" );
}

QStringList QgsPointOnSurfaceAlgorithm::tags() const
{
return QObject::tr( "centroid,inside,within" ).split( ',' );
}

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

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

QString QgsPointOnSurfaceAlgorithm::outputName() const
{
return QObject::tr( "Point" );
}

QString QgsPointOnSurfaceAlgorithm::shortHelpString() const
{
return QObject::tr( "Returns a point guaranteed to lie on the surface of a geometry." );
}

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

QgsFeatureList QgsPointOnSurfaceAlgorithm::processFeature( const QgsFeature &f, QgsProcessingContext &, QgsProcessingFeedback *feedback )
{
QgsFeature feature = f;
if ( feature.hasGeometry() )
{
QgsGeometry outputGeometry = feature.geometry().pointOnSurface();
if ( !outputGeometry )
{
feedback->pushInfo( QObject::tr( "Error calculating point on surface for feature %1: %2" ).arg( feature.id() ).arg( outputGeometry.lastError() ) );
}
feature.setGeometry( outputGeometry );
}
return QgsFeatureList() << feature;
}

///@endcond
58 changes: 58 additions & 0 deletions src/analysis/processing/qgsalgorithmpointonsurface.h
@@ -0,0 +1,58 @@
/***************************************************************************
qgsalgorithmpointonsurface.h
----------------------
begin : March 2018
copyright : (C) 2018 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 QGSALGORITHMPOINTONSURFACE_H
#define QGSALGORITHMPOINTONSURFACE_H

#define SIP_NO_FILE

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

///@cond PRIVATE

/**
* Native centroid algorithm.
*/
class QgsPointOnSurfaceAlgorithm : public QgsProcessingFeatureBasedAlgorithm
{

public:

QgsPointOnSurfaceAlgorithm() = 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;
QgsPointOnSurfaceAlgorithm *createInstance() const override SIP_FACTORY;

protected:

QString outputName() const override;
QgsProcessing::SourceType outputLayerType() const override { return QgsProcessing::TypeVectorPoint; }
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override { Q_UNUSED( inputWkbType ); return QgsWkbTypes::Point; }

QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
};

///@endcond PRIVATE

#endif // QGSALGORITHMPOINTONSURFACE_H


2 changes: 2 additions & 0 deletions src/analysis/processing/qgsnativealgorithms.cpp
Expand Up @@ -48,6 +48,7 @@
#include "qgsalgorithmorderbyexpression.h"
#include "qgsalgorithmorientedminimumboundingbox.h"
#include "qgsalgorithmpackage.h"
#include "qgsalgorithmpointonsurface.h"
#include "qgsalgorithmprojectpointcartesian.h"
#include "qgsalgorithmpromotetomultipart.h"
#include "qgsalgorithmrasterlayeruniquevalues.h"
Expand Down Expand Up @@ -139,6 +140,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
addAlgorithm( new QgsOrderByExpressionAlgorithm() );
addAlgorithm( new QgsOrientedMinimumBoundingBoxAlgorithm() );
addAlgorithm( new QgsPackageAlgorithm() );
addAlgorithm( new QgsPointOnSurfaceAlgorithm() );
addAlgorithm( new QgsProjectPointCartesianAlgorithm() );
addAlgorithm( new QgsPromoteToMultipartAlgorithm() );
addAlgorithm( new QgsRasterLayerUniqueValuesReportAlgorithm() );
Expand Down

0 comments on commit 871132e

Please sign in to comment.