mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Use vertex iterator
This commit is contained in:
parent
7cb15c08b9
commit
66b27dcd50
@ -66,6 +66,9 @@ class ExtractSpecificNodes(QgisAlgorithm):
|
||||
def displayName(self):
|
||||
return self.tr('Extract specific nodes')
|
||||
|
||||
def tags(self):
|
||||
return self.tr('points,vertex,vertices').split(',')
|
||||
|
||||
def processAlgorithm(self, parameters, context, feedback):
|
||||
source = self.parameterAsSource(parameters, self.INPUT, context)
|
||||
fields = source.fields()
|
||||
|
@ -17,6 +17,9 @@
|
||||
|
||||
#include "qgsalgorithmextractnodes.h"
|
||||
|
||||
#include "qgsabstractgeometry.h"
|
||||
#include "qgsgeometryutils.h"
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
QString QgsExtractNodesAlgorithm::name() const
|
||||
@ -76,8 +79,8 @@ QVariantMap QgsExtractNodesAlgorithm::processAlgorithm( const QVariantMap ¶m
|
||||
|
||||
QgsFields outputFields = featureSource->fields();
|
||||
outputFields.append( QgsField( QStringLiteral( "node_index" ), QVariant::Int, QString(), 10, 0 ) );
|
||||
outputFields.append( QgsField( QStringLiteral( "distance" ), QVariant::Double, QString(), 20, 6 ) );
|
||||
outputFields.append( QgsField( QStringLiteral( "angle" ), QVariant::Double, QString(), 20, 6 ) );
|
||||
outputFields.append( QgsField( QStringLiteral( "distance" ), QVariant::Double, QString(), 20, 14 ) );
|
||||
outputFields.append( QgsField( QStringLiteral( "angle" ), QVariant::Double, QString(), 20, 14 ) );
|
||||
|
||||
QString dest;
|
||||
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, outputFields, outputWkbType, featureSource->sourceCrs() ) );
|
||||
@ -85,10 +88,10 @@ QVariantMap QgsExtractNodesAlgorithm::processAlgorithm( const QVariantMap ¶m
|
||||
return QVariantMap();
|
||||
|
||||
double step = featureSource->featureCount() > 0 ? 100.0 / featureSource->featureCount() : 1;
|
||||
QgsFeatureIterator it = featureSource->getFeatures( QgsFeatureRequest() );
|
||||
QgsFeatureIterator fi = featureSource->getFeatures( QgsFeatureRequest() );
|
||||
QgsFeature f;
|
||||
int i = -1;
|
||||
while ( it.nextFeature( f ) )
|
||||
while ( fi.nextFeature( f ) )
|
||||
{
|
||||
i++;
|
||||
if ( feedback->isCanceled() )
|
||||
@ -103,27 +106,24 @@ QVariantMap QgsExtractNodesAlgorithm::processAlgorithm( const QVariantMap ¶m
|
||||
}
|
||||
else
|
||||
{
|
||||
const QgsCoordinateSequence sequence = inputGeom.constGet()->coordinateSequence();
|
||||
for ( const QgsRingSequence &part : sequence )
|
||||
QgsAbstractGeometry::vertex_iterator vi = inputGeom.constGet()->vertices_begin();
|
||||
QgsPoint vertex;
|
||||
int vertexPos = 0;
|
||||
while ( vi != inputGeom.constGet()->vertices_end() )
|
||||
{
|
||||
int vertexPos = 0;
|
||||
for ( const QgsPointSequence &ring : part )
|
||||
{
|
||||
for ( int j = 0; j < ring.count(); ++ j )
|
||||
{
|
||||
double distance = inputGeom.distanceToVertex( vertexPos );
|
||||
double angle = inputGeom.angleAtVertex( vertexPos ) * 180 / M_PI_2;
|
||||
QgsAttributes attrs = f.attributes();
|
||||
attrs << vertexPos
|
||||
<< distance
|
||||
<< angle;
|
||||
QgsFeature outputFeature = QgsFeature();
|
||||
outputFeature.setAttributes( attrs );
|
||||
outputFeature.setGeometry( QgsGeometry( ring.at( j ).clone() ) );
|
||||
sink->addFeature( outputFeature, QgsFeatureSink::FastInsert );
|
||||
vertexPos++;
|
||||
}
|
||||
}
|
||||
QgsVertexId vertexId = vi.vertexId();
|
||||
double distance = QgsGeometryUtils::distanceToVertex( *( inputGeom.constGet() ), vertexId );
|
||||
double angle = inputGeom.constGet()->vertexAngle( vertexId ) * 180 / M_PI;
|
||||
QgsAttributes attrs = f.attributes();
|
||||
attrs << vertexPos
|
||||
<< distance
|
||||
<< angle;
|
||||
QgsFeature outputFeature = QgsFeature();
|
||||
outputFeature.setAttributes( attrs );
|
||||
outputFeature.setGeometry( QgsGeometry( ( *vi ).clone() ) );
|
||||
sink->addFeature( outputFeature, QgsFeatureSink::FastInsert );
|
||||
vi++;
|
||||
vertexPos++;
|
||||
}
|
||||
}
|
||||
feedback->setProgress( i * step );
|
||||
|
Loading…
x
Reference in New Issue
Block a user