/
qgsalgorithmsubdivide.cpp
99 lines (78 loc) · 3.44 KB
/
qgsalgorithmsubdivide.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/***************************************************************************
qgsalgorithmsubdivide.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 "qgsalgorithmsubdivide.h"
///@cond PRIVATE
void QgsSubdivideAlgorithm::initParameters( const QVariantMap & )
{
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "MAX_NODES" ), QObject::tr( "Maximum nodes in parts" ), QgsProcessingParameterNumber::Integer,
256, false, 8, 100000 ) );
}
QString QgsSubdivideAlgorithm::name() const
{
return QStringLiteral( "subdivide" );
}
QString QgsSubdivideAlgorithm::displayName() const
{
return QObject::tr( "Subdivide" );
}
QStringList QgsSubdivideAlgorithm::tags() const
{
return QObject::tr( "subdivide,segmentize,split,tessellate" ).split( ',' );
}
QString QgsSubdivideAlgorithm::group() const
{
return QObject::tr( "Vector geometry" );
}
QString QgsSubdivideAlgorithm::shortHelpString() const
{
return QObject::tr( "Subdivides the geometry. The returned geometry will be a collection containing subdivided parts "
"from the original geometry, where no part has more then the specified maximum number of nodes.\n\n"
"This is useful for dividing a complex geometry into less complex parts, which are better able to be spatially "
"indexed and faster to perform further operations such as intersects on. The returned geometry parts may "
"not be valid and may contain self-intersections.\n\n"
"Curved geometries will be segmentized before subdivision." );
}
QgsSubdivideAlgorithm *QgsSubdivideAlgorithm::createInstance() const
{
return new QgsSubdivideAlgorithm();
}
QString QgsSubdivideAlgorithm::outputName() const
{
return QObject::tr( "Subdivided" );
}
QgsWkbTypes::Type QgsSubdivideAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
{
return QgsWkbTypes::multiType( inputWkbType );
}
QgsFeature QgsSubdivideAlgorithm::processFeature( const QgsFeature &f, QgsProcessingFeedback *feedback )
{
QgsFeature feature = f;
if ( feature.hasGeometry() )
{
feature.setGeometry( feature.geometry().subdivide( mMaxNodes ) );
if ( !feature.geometry() )
{
feedback->reportError( QObject::tr( "Error calculating subdivision for feature %1" ).arg( feature.id() ) );
}
}
return feature;
}
bool QgsSubdivideAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mMaxNodes = parameterAsInt( parameters, QStringLiteral( "MAX_NODES" ), context );
return true;
}
///@endcond