20#include <nlohmann/json.hpp>
54 std::unique_ptr< QgsAbstractGeometry >
geometry;
64 if ( !d->
ref.deref() )
82 mLastError = other.mLastError;
90 if ( !d->
ref.deref() )
95 mLastError = other.mLastError;
102void QgsGeometry::detach()
107 std::unique_ptr< QgsAbstractGeometry > cGeom;
109 cGeom.reset( d->
geometry->clone() );
111 reset( std::move( cGeom ) );
114void QgsGeometry::reset( std::unique_ptr<QgsAbstractGeometry> newGeometry )
118 ( void )d->
ref.deref();
121 d->
geometry = std::move( newGeometry );
137 if ( d->
geometry.get() == geometry )
142 reset( std::unique_ptr< QgsAbstractGeometry >( geometry ) );
156 QMutexLocker lock( sWktMutex() );
157 if (
const QgsGeometry *cached = sWktCache()->
object( wkt ) )
160 sWktCache()->insert( wkt,
new QgsGeometry( result ), 1 );
191 return QgsGeometry( std::make_unique< QgsLineString >( polyline ) );
239 std::unique_ptr< QgsLineString > ext = std::make_unique< QgsLineString >(
240 QVector< double >() << rect.
xMinimum()
245 QVector< double >() << rect.
yMinimum()
250 std::unique_ptr< QgsPolygon > polygon = std::make_unique< QgsPolygon >();
251 polygon->setExteriorRing( ext.release() );
262 std::unique_ptr< QgsMultiPolygon > multiPolygon = std::make_unique< QgsMultiPolygon >();
264 std::unique_ptr< QgsLineString > ext1 = std::make_unique< QgsLineString >(
265 QVector< double >() << box.
xMinimum()
270 QVector< double >() << box.
yMinimum()
275 QVector< double >() << box.
zMinimum()
280 std::unique_ptr< QgsPolygon > polygon1 = std::make_unique< QgsPolygon >( ext1.release() );
281 multiPolygon->addGeometry( polygon1.release() );
283 std::unique_ptr< QgsLineString > ext2 = std::make_unique< QgsLineString >(
284 QVector< double >() << box.
xMinimum()
289 QVector< double >() << box.
yMinimum()
294 QVector< double >() << box.
zMinimum()
299 std::unique_ptr< QgsPolygon > polygon2 = std::make_unique< QgsPolygon >( ext2.release() );
300 multiPolygon->addGeometry( polygon2.release() );
302 std::unique_ptr< QgsLineString > ext3 = std::make_unique< QgsLineString >(
303 QVector< double >() << box.
xMinimum()
308 QVector< double >() << box.
yMinimum()
313 QVector< double >() << box.
zMinimum()
318 std::unique_ptr< QgsPolygon > polygon3 = std::make_unique< QgsPolygon >( ext3.release() );
319 multiPolygon->addGeometry( polygon3.release() );
321 std::unique_ptr< QgsLineString > ext4 = std::make_unique< QgsLineString >(
322 QVector< double >() << box.
xMaximum()
327 QVector< double >() << box.
yMaximum()
332 QVector< double >() << box.
zMaximum()
337 std::unique_ptr< QgsPolygon > polygon4 = std::make_unique< QgsPolygon >( ext4.release() );
338 multiPolygon->addGeometry( polygon4.release() );
340 std::unique_ptr< QgsLineString > ext5 = std::make_unique< QgsLineString >(
341 QVector< double >() << box.
xMaximum()
346 QVector< double >() << box.
yMaximum()
351 QVector< double >() << box.
zMaximum()
356 std::unique_ptr< QgsPolygon > polygon5 = std::make_unique< QgsPolygon >( ext5.release() );
357 multiPolygon->addGeometry( polygon5.release() );
359 std::unique_ptr< QgsLineString > ext6 = std::make_unique< QgsLineString >(
360 QVector< double >() << box.
xMaximum()
365 QVector< double >() << box.
yMaximum()
370 QVector< double >() << box.
zMaximum()
375 std::unique_ptr< QgsPolygon > polygon6 = std::make_unique< QgsPolygon >( ext6.release() );
376 multiPolygon->addGeometry( polygon6.release() );
394 if ( g.isMultipart() )
396 for (
auto p = g.const_parts_begin(); p != g.const_parts_end(); ++p )
398 collected.
addPart( ( *p )->clone() );
412 if ( std::abs( angularWidth ) >= 360.0 )
414 std::unique_ptr< QgsCompoundCurve > outerCc = std::make_unique< QgsCompoundCurve >();
419 std::unique_ptr< QgsCurvePolygon > cp = std::make_unique< QgsCurvePolygon >();
420 cp->setExteriorRing( outerCc.release() );
424 std::unique_ptr< QgsCompoundCurve > innerCc = std::make_unique< QgsCompoundCurve >();
429 cp->setInteriorRings( { innerCc.release() } );
435 std::unique_ptr< QgsCompoundCurve > wedge = std::make_unique< QgsCompoundCurve >();
437 const double startAngle = azimuth - angularWidth * 0.5;
438 const double endAngle = azimuth + angularWidth * 0.5;
443 const bool useShortestArc = angularWidth <= 180.0;
461 std::unique_ptr< QgsCurvePolygon > cp = std::make_unique< QgsCurvePolygon >();
462 cp->setExteriorRing( wedge.release() );
540 d->
geometry->adjacentVertices(
id, prevVertex, nextVertex );
576 return d->
geometry->vertexAngle( v2 );
595 d->
geometry->adjacentVertices(
id, beforeVertexId, afterVertexId );
633 return d->
geometry->moveVertex(
id, p );
666 return d->
geometry->deleteVertex(
id );
686 if ( owningCollection !=
nullptr )
687 part = owningCollection->
geometryN(
id.part );
693 QgsCurvePolygon *owningPolygon = qgsgeometry_cast<QgsCurvePolygon *>( part );
694 if ( owningPolygon !=
nullptr )
700 QgsCurve *curve = qgsgeometry_cast<QgsCurve *>( ring );
701 if ( curve ==
nullptr )
704 bool success =
false;
706 if ( cpdCurve !=
nullptr )
715 std::unique_ptr<QgsCompoundCurve> cpdCurve = std::make_unique<QgsCompoundCurve>();
716 cpdCurve->addCurve( curve->
clone() );
717 success = cpdCurve->toggleCircularAtVertex(
QgsVertexId( -1, -1,
id.vertex ) );
722 if ( owningPolygon ==
nullptr && owningCollection ==
nullptr )
725 reset( std::make_unique<QgsCompoundCurve>( *cpdCurve ) );
727 else if ( owningPolygon !=
nullptr )
740 else if ( owningCollection !=
nullptr )
801 return d->
geometry->insertVertex(
id, point );
811 const double sqrSnappingTolerance = snappingTolerance * snappingTolerance;
812 int segmentAfterVertex;
814 const double sqrDistSegmentSnap =
closestSegmentWithContext( point, snappedPoint, segmentAfterVertex,
nullptr, segmentSearchEpsilon );
816 if ( sqrDistSegmentSnap > sqrSnappingTolerance )
819 int atVertex, beforeVertex, afterVertex;
820 double sqrDistVertexSnap;
821 closestVertex( point, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
823 if ( sqrDistVertexSnap < sqrSnappingTolerance )
828 QgsDebugError( QStringLiteral(
"failed to insert topo point" ) );
848 return d->
geometry->vertexAt( vId );
868 result.mLastError = mLastError;
877 return QgsGeometry( std::make_unique< QgsLineString >( *qgsgeometry_cast< const QgsPoint * >( d->
geometry.get() ), *qgsgeometry_cast< const QgsPoint * >( other.
constGet() ) ) );
883 result.mLastError = mLastError;
905 int &nextVertexIndex,
906 int *leftOrRightOfSegment,
907 double epsilon )
const
917 double sqrDist = d->
geometry->closestSegment(
QgsPoint( point ), segmentPt, vertexAfter, leftOrRightOfSegment, epsilon );
921 minDistPoint.
setX( segmentPt.
x() );
922 minDistPoint.
setY( segmentPt.
y() );
929 std::unique_ptr< QgsLineString > ringLine = std::make_unique< QgsLineString >( ring );
930 return addRing( ringLine.release() );
935 std::unique_ptr< QgsCurve > r( ring );
955 std::unique_ptr< QgsAbstractGeometry > partGeom;
956 if ( points.size() == 1 )
958 partGeom = std::make_unique< QgsPoint >( points[0] );
960 else if ( points.size() > 1 )
962 std::unique_ptr< QgsLineString > ringLine = std::make_unique< QgsLineString >();
963 ringLine->setPoints( points );
964 partGeom = std::move( ringLine );
966 return addPart( partGeom.release(), geomType );
971 std::unique_ptr< QgsAbstractGeometry > p( part );
977 reset( std::make_unique< QgsMultiPoint >() );
980 reset( std::make_unique< QgsMultiLineString >() );
983 reset( std::make_unique< QgsMultiPolygon >() );
1023 QVector<QgsGeometry> results;
1024 results.reserve(
parts.count() );
1031 if ( results.isEmpty() )
1035 for (
const QgsGeometry &result : std::as_const( results ) )
1044 newPoly->removeInteriorRings( minimumRingArea );
1058 d->
geometry->transform( QTransform::fromTranslate( dx, dy ), dz, 1.0, dm );
1071 QTransform t = QTransform::fromTranslate( center.
x(), center.
y() );
1072 t.rotate( -rotation );
1073 t.translate( -center.
x(), -center.
y() );
1097 for (
const QgsPoint &v : splitLine )
1102 QVector<QgsGeometry > newGeoms;
1112 *
this = newGeoms.takeAt( 0 );
1113 newGeometries = newGeoms;
1142 std::unique_ptr<QgsLineString> segmentizedLine( curve->
curveToLine() );
1144 segmentizedLine->points( points );
1149 if ( preserveCircular )
1151 for (
int i = 0; i < newGeometries.count(); ++i )
1170 std::unique_ptr< QgsAbstractGeometry > geom(
geos.reshapeGeometry( reshapeLineString, &errorCode, &mLastError ) );
1173 reset( std::move( geom ) );
1177 switch ( errorCode )
1209 std::unique_ptr< QgsAbstractGeometry > diffGeom(
geos.intersection( other.
constGet(), &mLastError ) );
1215 reset( std::move( diffGeom ) );
1229 std::unique_ptr< QgsAbstractGeometry > diffGeom(
geos.intersection( other.
constGet(), &mLastError ) );
1233 result.mLastError = mLastError;
1253 return d->
geometry->boundingBox3D();
1277 auto l_boundary = boundary.length();
1279 if ( ( points.length() == 0 ) || ( l_boundary == 3 ) )
1281 switch ( l_boundary )
1288 boundary.pop_back();
1293 boundary.pop_back();
1295 boundary.pop_back();
1312 circ_mec = __recMinimalEnclosingCircle( points, boundary );
1316 boundary.append( pxy );
1317 circ_mec = __recMinimalEnclosingCircle( points, boundary );
1341 QgsCircle circ = __recMinimalEnclosingCircle( P, R );
1362 return engine.
orthogonalize( tolerance, maxIterations, angleThreshold );
1368 return engine.
triangularWaves( wavelength, amplitude, strictWavelength );
1374 return engine.
triangularWavesRandomized( minimumWavelength, maximumWavelength, minimumAmplitude, maximumAmplitude, seed );
1380 return engine.
squareWaves( wavelength, amplitude, strictWavelength );
1386 return engine.
squareWavesRandomized( minimumWavelength, maximumWavelength, minimumAmplitude, maximumAmplitude, seed );
1392 return engine.
roundWaves( wavelength, amplitude, strictWavelength );
1398 return engine.
roundWavesRandomized( minimumWavelength, maximumWavelength, minimumAmplitude, maximumAmplitude, seed );
1404 return engine.
applyDashPattern( pattern, startRule, endRule, adjustment, patternOffset );
1413 return QgsGeometry( d->
geometry->snappedToGrid( hSpacing, vSpacing, dSpacing, mSpacing ) );
1422 return d->
geometry->removeDuplicateNodes( epsilon, useZValues );
1459 return geos.intersects( geometry.d->
geometry.get(), &mLastError );
1469 return d->
geometry->boundingBoxIntersects( rectangle );
1492 return geos.contains( &pt, &mLastError );
1504 return geos.contains( geometry.d->
geometry.get(), &mLastError );
1516 return geos.disjoint( geometry.d->
geometry.get(), &mLastError );
1527 if ( d == geometry.d )
1547 return geos.touches( geometry.d->
geometry.get(), &mLastError );
1559 return geos.overlaps( geometry.d->
geometry.get(), &mLastError );
1571 return geos.within( geometry.d->
geometry.get(), &mLastError );
1583 return geos.crosses( geometry.d->
geometry.get(), &mLastError );
1612 QVector< QgsGeometry > res;
1650 std::unique_ptr< QgsAbstractGeometry > exterior( ( *part )->clone() );
1651 if (
QgsCurve *curve = qgsgeometry_cast< QgsCurve * >( exterior.get() ) )
1655 std::unique_ptr< QgsCurvePolygon > cp = std::make_unique< QgsCurvePolygon >();
1656 cp->setExteriorRing( curve );
1658 gc->addGeometry( cp.release() );
1662 std::unique_ptr< QgsPolygon > p = std::make_unique< QgsPolygon >();
1663 p->setExteriorRing( qgsgeometry_cast< QgsLineString * >( curve ) );
1665 gc->addGeometry( p.release() );
1678 std::unique_ptr< QgsMultiPoint > mp = std::make_unique< QgsMultiPoint >();
1680 QSet< QgsPoint > added;
1683 if ( added.contains( *vertex ) )
1685 mp->addGeometry( ( *vertex ).clone() );
1686 added.insert( *vertex );
1725 res.reserve(
parts->partCount() );
1726 for (
int i = 0; i <
parts->partCount( ); i++ )
1743 return convertToPoint( destMultipart );
1746 return convertToLine( destMultipart );
1749 return convertToPolygon( destMultipart );
1816 if ( sourceMultiGeom )
1818 for (
int i = 0; i < sourceMultiGeom->
numGeometries(); ++i )
1830 reset( std::move( geom ) );
1847 if ( !multiGeom || multiGeom->
partCount() < 1 )
1850 std::unique_ptr< QgsAbstractGeometry > firstPart( multiGeom->
geometryN( 0 )->
clone() );
1851 reset( std::move( firstPart ) );
1862 std::unique_ptr<QgsGeometryCollection> resGeom;
1866 resGeom = std::make_unique<QgsMultiPoint>();
1869 resGeom = std::make_unique<QgsMultiLineString>();
1872 resGeom = std::make_unique<QgsMultiPolygon>();
1885 resGeom->addGeometry( g->
clone() );
1888 set( resGeom.release() );
1899 if (
QgsPoint *pt = qgsgeometry_cast<QgsPoint *>( d->
geometry->simplifiedTypeRef() ) )
1919 std::unique_ptr< QgsLineString > segmentizedLine;
1921 if ( doSegmentation )
1929 line = segmentizedLine.get();
1933 line = qgsgeometry_cast<QgsLineString *>( d->
geometry.get() );
1941 polyLine.resize( nVertices );
1943 const double *xData = line->
xData();
1944 const double *yData = line->
yData();
1945 for (
int i = 0; i < nVertices; ++i )
1947 data->
setX( *xData++ );
1948 data->
setY( *yData++ );
1963 std::unique_ptr< QgsPolygon > segmentized;
1964 if ( doSegmentation )
1971 segmentized.reset( curvePoly->
toPolygon() );
1972 p = segmentized.get();
1976 p = qgsgeometry_cast<QgsPolygon *>( d->
geometry.get() );
1985 convertPolygon( *p, polygon );
2005 for (
int i = 0; i < nPoints; ++i )
2008 multiPoint[i].
setX( pt->
x() );
2009 multiPoint[i].setY( pt->
y() );
2022 if ( !geomCollection )
2034 mpl.reserve( nLines );
2035 for (
int i = 0; i < nLines; ++i )
2038 std::unique_ptr< QgsLineString > segmentized;
2041 const QgsCurve *curve = qgsgeometry_cast<const QgsCurve *>( geomCollection->
geometryN( i ) );
2047 line = segmentized.get();
2052 polyLine.resize( nVertices );
2054 const double *xData = line->
xData();
2055 const double *yData = line->
yData();
2056 for (
int i = 0; i < nVertices; ++i )
2058 data->
setX( *xData++ );
2059 data->
setY( *yData++ );
2062 mpl.append( polyLine );
2075 if ( !geomCollection )
2081 if ( nPolygons < 1 )
2087 mp.reserve( nPolygons );
2088 for (
int i = 0; i < nPolygons; ++i )
2090 const QgsPolygon *polygon = qgsgeometry_cast<const QgsPolygon *>( geomCollection->
geometryN( i ) );
2105 convertPolygon( *polygon, poly );
2106 mp.push_back( poly );
2156 return qgsgeometry_cast< const QgsPoint * >( d->
geometry.get() )->distance( *qgsgeometry_cast< const QgsPoint * >( geom.
constGet() ) );
2217 return d->
geometry->vertices_begin();
2224 return d->
geometry->vertices_end();
2254 return d->
geometry->const_parts_begin();
2261 return d->
geometry->const_parts_end();
2290 std::unique_ptr<QgsAbstractGeometry> geom( g.
buffer(
distance, segments, &mLastError ) );
2294 result.mLastError = mLastError;
2313 result.mLastError = mLastError;
2329 QVector<QgsGeometry> results;
2330 results.reserve(
parts.count() );
2337 if ( results.isEmpty() )
2341 for (
const QgsGeometry &result : std::as_const( results ) )
2355 std::unique_ptr< QgsAbstractGeometry > offsetGeom(
geos.offsetCurve(
distance, segments, joinStyle, miterLimit, &mLastError ) );
2359 result.mLastError = mLastError;
2363 if (
const QgsCurve *
offsetCurve = qgsgeometry_cast< const QgsCurve * >( offsetGeom.get() ) )
2366 if ( newOrientation != prevOrientation )
2369 std::unique_ptr< QgsAbstractGeometry > flipped(
offsetCurve->reversed() );
2370 offsetGeom = std::move( flipped );
2387 QVector<QgsGeometry> results;
2388 results.reserve(
parts.count() );
2395 if ( results.isEmpty() )
2399 for (
const QgsGeometry &result : std::as_const( results ) )
2409 std::unique_ptr< QgsAbstractGeometry > bufferGeom =
geos.singleSidedBuffer(
distance, segments, side,
2410 joinStyle, miterLimit, &mLastError );
2414 result.mLastError = mLastError;
2425 return engine.
taperedBuffer( startWidth, endWidth, segments );
2445 QVector<QgsGeometry> results;
2446 results.reserve(
parts.count() );
2453 if ( results.isEmpty() )
2457 for (
const QgsGeometry &result : std::as_const( results ) )
2469 std::unique_ptr< QgsLineString > newLine( line->
clone() );
2470 newLine->extend( startDistance, endDistance );
2484 std::unique_ptr< QgsAbstractGeometry > simplifiedGeom(
geos.simplify( tolerance, &mLastError ) );
2485 if ( !simplifiedGeom )
2488 result.mLastError = mLastError;
2491 return QgsGeometry( std::move( simplifiedGeom ) );
2526 c.get()->dropZValue();
2527 c.get()->dropMValue();
2535 result.mLastError = mLastError;
2550 result.mLastError = mLastError;
2572 result.mLastError = mLastError;
2587 result.mLastError = mLastError;
2595 return std::numeric_limits< double >::quiet_NaN();
2601 return geos.minimumClearance( &mLastError );
2615 result.mLastError = mLastError;
2627 std::unique_ptr< QgsAbstractGeometry > cHull(
geos.convexHull( &mLastError ) );
2631 geom.mLastError = mLastError;
2645 std::unique_ptr< QgsAbstractGeometry >
concaveHull(
geos.concaveHull( targetPercent, allowHoles, &mLastError ) );
2649 geom.mLastError = mLastError;
2665 result.mLastError = mLastError;
2678 QgsGeometry result =
geos.delaunayTriangulation( tolerance, edgesOnly );
2679 result.mLastError = mLastError;
2693 result.mLastError = mLastError;
2712 result.mLastError = mLastError;
2725 std::unique_ptr< QgsAbstractGeometry > invalidEdgesGeom;
2729 if ( invalidEdges && invalidEdgesGeom )
2730 *invalidEdges =
QgsGeometry( std::move( invalidEdgesGeom ) );
2744 QgsGeometry result(
geos.simplifyCoverageVW( tolerance, preserveBoundary, &mLastError ) );
2745 result.mLastError = mLastError;
2759 result.mLastError = mLastError;
2773 result.mLastError = mLastError;
2785 std::unique_ptr< QgsAbstractGeometry > segmentizedCopy;
2788 segmentizedCopy.reset( d->
geometry->segmentize() );
2789 geom = segmentizedCopy.get();
2794 std::unique_ptr< QgsAbstractGeometry > result(
geos.subdivide( maxNodes, &mLastError, parameters ) );
2798 geom.mLastError = mLastError;
2824 for (
int part = 0; part < collection->
numGeometries(); ++part )
2826 const QgsCurve *candidate = qgsgeometry_cast< const QgsCurve * >( collection->
geometryN( part ) );
2829 const double candidateLength = candidate->
length();
2841 curve = qgsgeometry_cast< const QgsCurve * >( line.
constGet() );
2870 return geos.lineLocatePoint( *(
static_cast< QgsPoint *
>( point.d->
geometry.get() ) ), &mLastError );
2894 if ( previous == next )
2941 std::unique_ptr< QgsAbstractGeometry > resultGeom(
geos.intersection( geometry.d->
geometry.get(), &mLastError, parameters ) );
2946 geom.mLastError = mLastError;
2962 std::unique_ptr< QgsAbstractGeometry > resultGeom(
geos.combine( geometry.d->
geometry.get(), &mLastError, parameters ) );
2966 geom.mLastError = mLastError;
2988 result.mLastError = mLastError;
3002 std::unique_ptr< QgsAbstractGeometry > resultGeom(
geos.difference( geometry.d->
geometry.get(), &mLastError, parameters ) );
3006 geom.mLastError = mLastError;
3022 std::unique_ptr< QgsAbstractGeometry > resultGeom(
geos.symDifference( geometry.d->
geometry.get(), &mLastError, parameters ) );
3026 geom.mLastError = mLastError;
3036 return engine.
extrude( x, y );
3044 return QVector< QgsPointXY >();
3047 const QVector<QgsPointXY> res = engine.randomPointsInPolygon( count, acceptPoint, seed, feedback, maxTriesPerPoint );
3048 mLastError = engine.lastError();
3055 return QVector< QgsPointXY >();
3058 const QVector<QgsPointXY> res = engine.randomPointsInPolygon( count, [](
const QgsPointXY & ) {
return true; }, seed, feedback, 0 );
3059 mLastError = engine.lastError();
3076 QVector<QgsGeometry> geometryList;
3079 return geometryList;
3086 geometryList.reserve( numGeom );
3087 for (
int i = 0; i < numGeom; ++i )
3094 geometryList.append( *
this );
3097 return geometryList;
3111 if (
const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection *>( part ) )
3113 if ( collection->numGeometries() > 0 )
3114 part = collection->geometryN( 0 );
3119 if (
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( part ) )
3120 return curve->asQPolygonF();
3121 else if (
const QgsCurvePolygon *polygon = qgsgeometry_cast< const QgsCurvePolygon * >( part ) )
3122 return polygon->exteriorRing() ? polygon->exteriorRing()->asQPolygonF() : QPolygonF();
3165 bool haveInvalidGeometry =
false;
3166 bool geomModified =
false;
3171 reset( std::move( diffGeom ) );
3172 geomModified =
true;
3175 if ( geomTypeBeforeModification !=
wkbType() )
3177 if ( haveInvalidGeometry )
3179 if ( !geomModified )
3224 std::unique_ptr< QgsAbstractGeometry > g(
geos.makeValid( method, keepCollapsed, &mLastError ) );
3227 result.mLastError = mLastError;
3247 if (
const QgsCurvePolygon *cp = qgsgeometry_cast< const QgsCurvePolygon * >( g ) )
3277 if (
const QgsCurvePolygon *cp = qgsgeometry_cast< const QgsCurvePolygon * >( g ) )
3279 std::unique_ptr< QgsCurvePolygon > corrected( cp->clone() );
3280 corrected->forceClockwise();
3281 newCollection->addGeometry( corrected.release() );
3285 newCollection->addGeometry( g->
clone() );
3294 std::unique_ptr< QgsCurvePolygon > corrected( cp->clone() );
3295 corrected->forceClockwise();
3319 if (
const QgsCurvePolygon *cp = qgsgeometry_cast< const QgsCurvePolygon * >( g ) )
3321 std::unique_ptr< QgsCurvePolygon > corrected( cp->clone() );
3322 corrected->forceCounterClockwise();
3323 newCollection->addGeometry( corrected.release() );
3327 newCollection->addGeometry( g->
clone() );
3336 std::unique_ptr< QgsCurvePolygon > corrected( cp->clone() );
3337 corrected->forceCounterClockwise();
3407 return d->
geometry->isValid( mLastError, flags );
3417 return geos.isSimple( &mLastError );
3457 return geos.isEqual( g.d->
geometry.get(), &mLastError );
3465 std::unique_ptr< QgsAbstractGeometry > geom(
geos.combine( geometries, &error, parameters ) );
3467 result.mLastError = error;
3473 QVector<const QgsAbstractGeometry *> geomV2List;
3476 if ( !( g.isNull() ) )
3478 geomV2List.append( g.constGet() );
3484 result.mLastError = error;
3495 std::unique_ptr< QgsAbstractGeometry > straightGeom( d->
geometry->segmentize( tolerance, toleranceType ) );
3496 reset( std::move( straightGeom ) );
3506 return d->
geometry->hasCurvedSegments();
3517 d->
geometry->transform( ct, direction, transformZ );
3529 d->
geometry->transform( ct, zTranslate, zScale, mTranslate, mScale );
3551 std::unique_ptr< QgsAbstractGeometry > resultGeom =
geos.clip( rectangle, &mLastError );
3555 result.mLastError = mLastError;
3569static bool vertexIndexInfo(
const QgsAbstractGeometry *g,
int vertexIndex,
int &partIndex,
int &ringIndex,
int &vertex )
3571 if ( vertexIndex < 0 )
3574 if (
const QgsGeometryCollection *geomCollection = qgsgeometry_cast<const QgsGeometryCollection *>( g ) )
3577 for (
int i = 0; i < geomCollection->numGeometries(); ++i )
3583 for (
int k = 0; k < part->
ringCount(); ++k )
3586 if ( vertexIndex < numPoints )
3589 return vertexIndexInfo( part, vertexIndex, nothing, ringIndex, vertex );
3591 vertexIndex -= numPoints;
3595 else if (
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast<const QgsCurvePolygon *>( g ) )
3597 const QgsCurve *ring = curvePolygon->exteriorRing();
3598 if ( vertexIndex < ring->numPoints() )
3602 vertex = vertexIndex;
3607 for (
int i = 0; i < curvePolygon->numInteriorRings(); ++i )
3609 const QgsCurve *ring = curvePolygon->interiorRing( i );
3610 if ( vertexIndex < ring->numPoints() )
3613 vertex = vertexIndex;
3620 else if (
const QgsCurve *curve = qgsgeometry_cast<const QgsCurve *>( g ) )
3622 if ( vertexIndex < curve->numPoints() )
3626 vertex = vertexIndex;
3630 else if ( qgsgeometry_cast<const QgsPoint *>( g ) )
3632 if ( vertexIndex == 0 )
3653 bool res = vertexIndexInfo( d->
geometry.get(), nr,
id.part,
id.ring,
id.vertex );
3659 if (
const QgsGeometryCollection *geomCollection = qgsgeometry_cast<const QgsGeometryCollection *>( g ) )
3661 g = geomCollection->geometryN(
id.part );
3664 if (
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast<const QgsCurvePolygon *>( g ) )
3666 g =
id.ring == 0 ? curvePolygon->exteriorRing() : curvePolygon->interiorRing(
id.ring - 1 );
3669 if (
const QgsCurve *curve = qgsgeometry_cast<const QgsCurve *>( g ) )
3672 res = curve->pointAt(
id.vertex, p,
id.
type );
3686 return d->
geometry->vertexNumberFromVertexId(
id );
3701 d->
geometry->filterVertices( filter );
3741 std::unique_ptr< QgsLineString > segmentizedLine;
3743 if ( doSegmentation )
3746 line = segmentizedLine.get();
3750 line = qgsgeometry_cast<const QgsLineString *>( ring );
3758 res.resize( nVertices );
3760 const double *xData = line->
xData();
3761 const double *yData = line->
yData();
3762 for (
int i = 0; i < nVertices; ++i )
3764 data->
setX( *xData++ );
3765 data->
setY( *yData++ );
3773 output.push_back( convertRing( exterior ) );
3777 output.reserve( output.size() + interiorRingCount );
3778 for (
int n = 0; n < interiorRingCount; ++n )
3780 output.push_back( convertRing( input.
interiorRing( n ) ) );
3786 return QgsGeometry( std::make_unique< QgsPoint >( point.x(), point.y() ) );
3793 if ( polygon.isClosed() )
3795 std::unique_ptr< QgsPolygon > poly = std::make_unique< QgsPolygon >();
3796 poly->setExteriorRing( ring.release() );
3817 result.reserve( polygon.count() );
3818 for (
const QPointF &p : polygon )
3827 if ( p1.count() != p2.count() )
3830 for (
int i = 0; i < p1.count(); ++i )
3832 if ( !p1.at( i ).compare( p2.at( i ), epsilon ) )
3840 if ( p1.count() != p2.count() )
3843 for (
int i = 0; i < p1.count(); ++i )
3854 if ( p1.count() != p2.count() )
3857 for (
int i = 0; i < p1.count(); ++i )
3884 return QgsGeometry( smoothLine( *lineString, iterations, offset, minimumDistance, maxAngle ) );
3891 std::unique_ptr< QgsMultiLineString > resultMultiline = std::make_unique< QgsMultiLineString> ();
3895 resultMultiline->addGeometry( smoothLine( *( multiLine->
lineStringN( i ) ), iterations, offset, minimumDistance, maxAngle ).release() );
3897 return QgsGeometry( std::move( resultMultiline ) );
3903 return QgsGeometry( smoothPolygon( *poly, iterations, offset, minimumDistance, maxAngle ) );
3910 std::unique_ptr< QgsMultiPolygon > resultMultiPoly = std::make_unique< QgsMultiPolygon >();
3914 resultMultiPoly->addGeometry( smoothPolygon( *( multiPoly->
polygonN( i ) ), iterations, offset, minimumDistance, maxAngle ).release() );
3916 return QgsGeometry( std::move( resultMultiPoly ) );
3926 const double offset,
double squareDistThreshold,
double maxAngleRads,
3929 std::unique_ptr< QgsLineString > result = std::make_unique< QgsLineString >( line );
3931 for (
unsigned int iteration = 0; iteration < iterations; ++iteration )
3933 outputLine.resize( 0 );
3934 outputLine.reserve( 2 * ( result->numPoints() - 1 ) );
3935 bool skipFirst =
false;
3936 bool skipLast =
false;
3939 QgsPoint p1 = result->pointN( result->numPoints() - 2 );
3945 skipFirst =
angle > maxAngleRads;
3947 for (
int i = 0; i < result->numPoints() - 1; i++ )
3950 QgsPoint p2 = result->pointN( i + 1 );
3952 double angle = M_PI;
3953 if ( i == 0 && isRing )
3955 QgsPoint p3 = result->pointN( result->numPoints() - 2 );
3959 else if ( i < result->numPoints() - 2 )
3961 QgsPoint p3 = result->pointN( i + 2 );
3965 else if ( i == result->numPoints() - 2 && isRing )
3972 skipLast =
angle < M_PI - maxAngleRads ||
angle > M_PI + maxAngleRads;
3975 if ( i == 0 || i >= result->numPoints() - 2
4000 skipFirst = skipLast;
4003 if ( isRing && outputLine.at( 0 ) != outputLine.at( outputLine.count() - 1 ) )
4004 outputLine << outputLine.at( 0 );
4006 result->setPoints( outputLine );
4011std::unique_ptr<QgsLineString> QgsGeometry::smoothLine(
const QgsLineString &line,
const unsigned int iterations,
const double offset,
double minimumDistance,
double maxAngle )
const
4013 double maxAngleRads = maxAngle * M_PI / 180.0;
4014 double squareDistThreshold = minimumDistance > 0 ? minimumDistance * minimumDistance : -1;
4015 return smoothCurve( line, iterations, offset, squareDistThreshold, maxAngleRads,
false );
4018std::unique_ptr<QgsPolygon> QgsGeometry::smoothPolygon(
const QgsPolygon &polygon,
const unsigned int iterations,
const double offset,
double minimumDistance,
double maxAngle )
const
4020 double maxAngleRads = maxAngle * M_PI / 180.0;
4021 double squareDistThreshold = minimumDistance > 0 ? minimumDistance * minimumDistance : -1;
4022 std::unique_ptr< QgsPolygon > resultPoly = std::make_unique< QgsPolygon >();
4025 squareDistThreshold, maxAngleRads,
true ).release() );
4030 squareDistThreshold, maxAngleRads,
true ).release() );
4035QgsGeometry QgsGeometry::convertToPoint(
bool destMultipart )
const
4043 if ( ( destMultipart && srcIsMultipart ) ||
4044 ( !destMultipart && !srcIsMultipart ) )
4049 if ( destMultipart )
4058 if ( multiPoint.count() == 1 )
4069 if ( !destMultipart )
4086 if ( !line.isEmpty() )
4095 if ( !destMultipart )
4126QgsGeometry QgsGeometry::convertToLine(
bool destMultipart )
const
4136 if ( multiPoint.count() < 2 )
4139 if ( destMultipart )
4149 if ( ( destMultipart && srcIsMultipart ) ||
4150 ( !destMultipart && ! srcIsMultipart ) )
4155 if ( destMultipart )
4159 if ( !line.isEmpty() )
4166 if ( multiLine.count() == 1 )
4183 if ( destMultipart )
4188 else if ( multiLine.count() == 1 )
4199 if ( polygon.count() > 1 )
4203 if ( destMultipart )
4207 multiLine.reserve( polygon.count() );
4214 else if ( polygon.count() == 1 )
4216 if ( destMultipart )
4234QgsGeometry QgsGeometry::convertToPolygon(
bool destMultipart )
const
4244 if ( multiPoint.count() < 3 )
4247 if ( multiPoint.last() != multiPoint.first() )
4248 multiPoint << multiPoint.first();
4251 if ( destMultipart )
4264 for ( QgsMultiPolylineXY::iterator multiLineIt = multiLine.begin(); multiLineIt != multiLine.end(); ++multiLineIt )
4267 if ( ( *multiLineIt ).count() < 3 )
4269 if ( ( *multiLineIt ).count() == 3 && ( *multiLineIt ).first() == ( *multiLineIt ).last() )
4273 if ( ( *multiLineIt ).first() != ( *multiLineIt ).last() )
4274 *multiLineIt << ( *multiLineIt ).first();
4278 if ( !multiPolygon.isEmpty() )
4280 if ( destMultipart )
4284 else if ( multiPolygon.count() == 1 )
4297 if ( line.count() < 3 )
4299 if ( line.count() == 3 && line.first() == line.last() )
4303 if ( line.first() != line.last() )
4304 line << line.first();
4307 if ( destMultipart )
4323 if ( ( destMultipart && srcIsMultipart ) ||
4324 ( !destMultipart && ! srcIsMultipart ) )
4329 if ( destMultipart )
4333 if ( !polygon.isEmpty() )
4339 if ( multiPolygon.count() == 1 )
4360 out << geometry.
asWkb();
4366 QByteArray byteArray;
4368 if ( byteArray.isEmpty() )
4370 geometry.
set(
nullptr );
4374 geometry.
fromWkb( byteArray );
4391 return mHasLocation;
@ AllowSelfTouchingHoles
Indicates that self-touching holes are permitted. OGC validity states that self-touching holes are NO...
BufferSide
Side of line to buffer.
DashPatternSizeAdjustment
Dash pattern size adjustment options.
AngularDirection
Angular directions.
@ NoOrientation
Unknown orientation or sentinel value.
GeometryOperationResult
Success or failure of a geometry operation.
@ AddPartSelectedGeometryNotFound
The selected geometry cannot be found.
@ InvalidInputGeometryType
The input geometry (ring, part, split line, etc.) has not the correct geometry type.
@ Success
Operation succeeded.
@ SelectionIsEmpty
No features were selected.
@ GeometryTypeHasChanged
Operation has changed geometry type.
@ AddRingNotInExistingFeature
The input ring doesn't have any existing ring to fit into.
@ AddRingCrossesExistingRings
The input ring crosses existing rings (it is not disjoint)
@ AddPartNotMultiGeometry
The source geometry is not multi.
@ AddRingNotClosed
The input ring is not closed.
@ SelectionIsGreaterThanOne
More than one features were selected.
@ SplitCannotSplitPoint
Cannot split points.
@ GeometryEngineError
Geometry engine misses a method implemented or an error occurred in the geometry engine.
@ NothingHappened
Nothing happened, without any error.
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
@ LayerNotEditable
Cannot edit layer.
@ AddRingNotValid
The input ring is not valid.
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
@ Segment
The actual start or end point of a segment.
GeometryValidationEngine
Available engines for validating geometries.
@ QgisInternal
Use internal QgsGeometryValidator method.
@ Geos
Use GEOS validation methods.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
JoinStyle
Join styles for buffers.
EndCapStyle
End cap styles for buffers.
CoverageValidityResult
Coverage validity results.
@ Error
An exception occurred while determining validity.
DashPatternLineEndingRule
Dash pattern line ending rules.
MakeValidMethod
Algorithms to use when repairing invalid geometries.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ CompoundCurve
CompoundCurve.
@ MultiPolygon
MultiPolygon.
@ MultiLineString
MultiLineString.
@ CircularString
CircularString.
@ GeometryCollection
GeometryCollection.
@ CurvePolygon
CurvePolygon.
@ MultiSurface
MultiSurface.
TransformDirection
Indicates the direction (forward or inverse) of a transform.
The part_iterator class provides STL-style iterator for const references to geometry parts.
The part_iterator class provides STL-style iterator for geometry parts.
The vertex_iterator class provides STL-style iterator for vertices.
Abstract base class for all geometries.
virtual int ringCount(int part=0) const =0
Returns the number of rings of which this geometry is built.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
bool isMeasure() const
Returns true if the geometry contains m values.
QFlags< WkbFlag > WkbFlags
virtual QgsRectangle boundingBox() const
Returns the minimal bounding box for the geometry.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const =0
Returns the vertices adjacent to a specified vertex within a geometry.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
A 3-dimensional box composed of x, y, z coordinates.
double yMaximum() const
Returns the maximum y value.
double xMinimum() const
Returns the minimum x value.
double zMaximum() const
Returns the maximum z value.
double xMaximum() const
Returns the maximum x value.
QgsRectangle toRectangle() const
Converts the box to a 2D rectangle.
bool is2d() const
Returns true if the box can be considered a 2-dimensional box, i.e.
double zMinimum() const
Returns the minimum z value.
double yMinimum() const
Returns the minimum y value.
static QgsCircle from2Points(const QgsPoint &pt1, const QgsPoint &pt2)
Constructs a circle by 2 points on the circle.
double radius() const
Returns the radius of the circle.
bool contains(const QgsPoint &point, double epsilon=1E-8) const
Returns true if the circle contains the point.
QgsCircularString * toCircularString(bool oriented=false) const
Returns a circular string from the circle.
static QgsCircle minimalCircleFrom3Points(const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double epsilon=1E-8)
Constructs the smallest circle from 3 points.
Circular string geometry type.
static QgsCircularString fromTwoPointsAndCenter(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint ¢er, bool useShortestArc=true)
Creates a circular string with a single arc representing the curve from p1 to p2 with the specified c...
Compound curve geometry type.
bool toggleCircularAtVertex(QgsVertexId position)
Converts the vertex at the given position from/to circular.
Curve polygon geometry type.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
virtual QgsPolygon * toPolygon(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a new polygon geometry corresponding to a segmentized approximation of the curve.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
virtual void setExteriorRing(QgsCurve *ring)
Sets the exterior ring of the polygon.
virtual void addInteriorRing(QgsCurve *ring)
Adds an interior ring to the geometry (takes ownership)
bool removeInteriorRing(int ringIndex)
Removes an interior ring from the polygon.
Abstract base class for curved geometry type.
virtual int numPoints() const =0
Returns the number of points in the curve.
QgsCurve * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
virtual QgsPoint * interpolatePoint(double distance) const =0
Returns an interpolated point on the curve at the specified distance.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
virtual QgsLineString * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve.
virtual QgsPolygon * toPolygon(unsigned int segments=36) const
Returns a segmented polygon.
QgsPoint center() const
Returns the center point.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
virtual bool insertGeometry(QgsAbstractGeometry *g, int index)
Inserts a geometry before a specified index and takes ownership.
virtual bool removeGeometry(int nr)
Removes a geometry from the collection.
QgsGeometryCollection * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
int partCount() const override
Returns count of parts contained in the geometry.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
Java-style iterator for const traversal of parts of a geometry.
static Qgis::GeometryOperationResult addRing(QgsAbstractGeometry *geometry, std::unique_ptr< QgsCurve > ring)
Add an interior ring to a geometry.
static std::unique_ptr< QgsAbstractGeometry > avoidIntersections(const QgsAbstractGeometry &geom, const QList< QgsVectorLayer * > &avoidIntersectionsLayers, bool &haveInvalidGeometry, const QHash< QgsVectorLayer *, QSet< QgsFeatureId > > &ignoreFeatures=(QHash< QgsVectorLayer *, QSet< QgsFeatureId > >()))
Alters a geometry so that it avoids intersections with features from all open vector layers.
static bool deletePart(QgsAbstractGeometry *geom, int partNum)
Deletes a part from a geometry.
static bool deleteRing(QgsAbstractGeometry *geom, int ringNum, int partNum=0)
Deletes a ring from a geometry.
static Qgis::GeometryOperationResult addPart(QgsAbstractGeometry *geometry, std::unique_ptr< QgsAbstractGeometry > part)
Add a part to multi type geometry.
A geometry engine is a low-level representation of a QgsAbstractGeometry object, optimised for use wi...
EngineOperationResult
Success or failure of a geometry operation.
@ NothingHappened
Nothing happened, without any error.
@ InvalidBaseGeometry
The geometry on which the operation occurs is not valid.
@ InvalidInput
The input is not valid.
@ NodedGeometryError
Error occurred while creating a noded geometry.
@ EngineError
Error occurred in the geometry engine.
@ SplitCannotSplitPoint
Points cannot be split.
@ Success
Operation succeeded.
@ MethodNotImplemented
Method not implemented in geometry engine.
static std::unique_ptr< QgsMultiPolygon > fromMultiPolygonXY(const QgsMultiPolygonXY &multipoly)
Construct geometry from a multipolygon.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkb(QgsConstWkbPtr &wkb)
Construct geometry from a WKB string.
static std::unique_ptr< QgsGeometryCollection > createCollectionOfType(Qgis::WkbType type)
Returns a new geometry collection matching a specified WKB type.
static std::unique_ptr< QgsAbstractGeometry > fromPolylineXY(const QgsPolylineXY &polyline)
Construct geometry from a polyline.
static std::unique_ptr< QgsMultiPoint > fromMultiPointXY(const QgsMultiPointXY &multipoint)
Construct geometry from a multipoint.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkt(const QString &text)
Construct geometry from a WKT string.
static std::unique_ptr< QgsMultiLineString > fromMultiPolylineXY(const QgsMultiPolylineXY &multiline)
Construct geometry from a multipolyline.
static std::unique_ptr< QgsAbstractGeometry > fromPointXY(const QgsPointXY &point)
Construct geometry from a point.
static std::unique_ptr< QgsPolygon > fromPolygonXY(const QgsPolygonXY &polygon)
Construct geometry from a polygon.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkbType(Qgis::WkbType t)
Returns empty geometry from wkb type.
Encapsulates parameters under which a geometry operation is performed.
Java-style iterator for traversal of parts of a geometry.
static double angleBetweenThreePoints(double x1, double y1, double x2, double y2, double x3, double y3)
Calculates the angle between the lines AB and BC, where AB and BC described by points a,...
static double lineAngle(double x1, double y1, double x2, double y2)
Calculates the direction of line joining two points in radians, clockwise from the north direction.
static double averageAngle(double x1, double y1, double x2, double y2, double x3, double y3)
Calculates the average angle (in radians) between the two linear segments from (x1,...
static QgsPointXY interpolatePointOnLine(double x1, double y1, double x2, double y2, double fraction)
Interpolates the position of a point a fraction of the way along the line from (x1,...
static bool verticesAtDistance(const QgsAbstractGeometry &geometry, double distance, QgsVertexId &previousVertex, QgsVertexId &nextVertex)
Retrieves the vertices which are before and after the interpolated point at a specified distance alon...
static double distanceToVertex(const QgsAbstractGeometry &geom, QgsVertexId id)
Returns the distance along a geometry from its first vertex to the specified vertex.
static QgsPoint closestVertex(const QgsAbstractGeometry &geom, const QgsPoint &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point.
static Q_DECL_DEPRECATED double sqrDistance2D(double x1, double y1, double x2, double y2)
Returns the squared 2D distance between (x1, y1) and (x2, y2).
static void validateGeometry(const QgsGeometry &geometry, QVector< QgsGeometry::Error > &errors, Qgis::GeometryValidationEngine method=Qgis::GeometryValidationEngine::QgisInternal)
Validate geometry and produce a list of geometry errors.
bool hasWhere() const
true if the location available from
QgsPointXY where() const
The coordinates at which the error is located and should be visualized.
QString what() const
A human readable error message containing details about the error.
A geometry is the spatial representation of a feature.
QPolygonF asQPolygonF() const
Returns contents of the geometry as a QPolygonF.
bool deleteRing(int ringNum, int partNum=0)
Deletes a ring in polygon or multipolygon.
QVector< QgsPointXY > randomPointsInPolygon(int count, const std::function< bool(const QgsPointXY &) > &acceptPoint, unsigned long seed=0, QgsFeedback *feedback=nullptr, int maxTriesPerPoint=0) const
Returns a list of count random points generated inside a (multi)polygon geometry (if acceptPoint is s...
double hausdorffDistanceDensify(const QgsGeometry &geom, double densifyFraction) const
Returns the Hausdorff distance between this geometry and geom.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
QgsGeometry clipped(const QgsRectangle &rectangle)
Clips the geometry using the specified rectangle.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
double lineLocatePoint(const QgsGeometry &point) const
Returns a distance representing the location along this linestring of the closest point on this lines...
QVector< QgsGeometry > coerceToType(Qgis::WkbType type, double defaultZ=0, double defaultM=0) const
Attempts to coerce this geometry into the specified destination type.
int makeDifferenceInPlace(const QgsGeometry &other)
Changes this geometry such that it does not intersect the other geometry.
void adjacentVertices(int atVertex, int &beforeVertex, int &afterVertex) const
Returns the indexes of the vertices before and after the given vertex index.
QgsMultiPolygonXY asMultiPolygon() const
Returns the contents of the geometry as a multi-polygon.
QgsGeometry difference(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points making up this geometry that do not make up other.
bool deleteVertex(int atVertex)
Deletes the vertex at the given position number and item (first number is index 0)
double length() const
Returns the planar, 2-dimensional length of geometry.
QgsGeometry offsetCurve(double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit) const
Returns an offset line at a given distance and side from an input line.
static bool compare(const QgsPolylineXY &p1, const QgsPolylineXY &p2, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compares two polylines for equality within a specified tolerance.
QgsVertexIterator vertices() const
Returns a read-only, Java-style iterator for traversal of vertices of all the geometry,...
QgsGeometry densifyByDistance(double distance) const
Densifies the geometry by adding regularly placed extra nodes inside each segment so that the maximum...
QgsGeometry poleOfInaccessibility(double precision, double *distanceToBoundary=nullptr) const
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal ...
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
QgsGeometry squareWaves(double wavelength, double amplitude, bool strictWavelength=false) const
Constructs square waves along the boundary of the geometry, with the specified wavelength and amplitu...
static QgsGeometry fromQPointF(QPointF point)
Construct geometry from a QPointF.
static QgsGeometry polygonize(const QVector< QgsGeometry > &geometries)
Creates a GeometryCollection geometry containing possible polygons formed from the constituent linewo...
bool addTopologicalPoint(const QgsPoint &point, double snappingTolerance=1e-8, double segmentSearchEpsilon=1e-12)
Adds a vertex to the segment which intersect point but don't already have a vertex there.
QgsGeometry triangularWaves(double wavelength, double amplitude, bool strictWavelength=false) const
Constructs triangular waves along the boundary of the geometry, with the specified wavelength and amp...
bool boundingBoxIntersects(const QgsRectangle &rectangle) const
Returns true if the bounding box of this geometry intersects with a rectangle.
bool vertexIdFromVertexNr(int number, QgsVertexId &id) const
Calculates the vertex ID from a vertex number.
QgsGeometry pointOnSurface() const
Returns a point guaranteed to lie on the surface of a geometry.
bool touches(const QgsGeometry &geometry) const
Returns true if the geometry touches another geometry.
void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform)
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
QgsGeometry minimumWidth() const
Returns a linestring geometry which represents the minimum diameter of the geometry.
QgsGeometry applyDashPattern(const QVector< double > &pattern, Qgis::DashPatternLineEndingRule startRule=Qgis::DashPatternLineEndingRule::NoRule, Qgis::DashPatternLineEndingRule endRule=Qgis::DashPatternLineEndingRule::NoRule, Qgis::DashPatternSizeAdjustment adjustment=Qgis::DashPatternSizeAdjustment::ScaleBothDashAndGap, double patternOffset=0) const
Applies a dash pattern to a geometry, returning a MultiLineString geometry which is the input geometr...
Qgis::CoverageValidityResult validateCoverage(double gapWidth, QgsGeometry *invalidEdges=nullptr) const
Analyze a coverage (represented as a collection of polygonal geometry with exactly matching edge geom...
QgsGeometry roundWaves(double wavelength, double amplitude, bool strictWavelength=false) const
Constructs rounded (sine-like) waves along the boundary of the geometry, with the specified wavelengt...
QgsGeometry nearestPoint(const QgsGeometry &other) const
Returns the nearest (closest) point on this geometry to another geometry.
QgsGeometry makeDifference(const QgsGeometry &other) const
Returns the geometry formed by modifying this geometry such that it does not intersect the other geom...
QgsGeometry simplifyCoverageVW(double tolerance, bool preserveBoundary) const
Operates on a coverage (represented as a list of polygonal geometry with exactly matching edge geomet...
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
static QgsGeometry fromMultiPolylineXY(const QgsMultiPolylineXY &multiline)
Creates a new geometry from a QgsMultiPolylineXY object.
QgsGeometry makeValid(Qgis::MakeValidMethod method=Qgis::MakeValidMethod::Linework, bool keepCollapsed=false) const
Attempts to make an invalid geometry valid without losing vertices.
double frechetDistance(const QgsGeometry &geom) const
Returns the Fréchet distance between this geometry and geom, restricted to discrete points for both g...
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
QgsGeometry convertToType(Qgis::GeometryType destType, bool destMultipart=false) const
Try to convert the geometry to the requested type.
QgsGeometry combine(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing all the points in this geometry and other (a union geometry operation...
bool isAxisParallelRectangle(double maximumDeviation, bool simpleRectanglesOnly=false) const
Returns true if the geometry is a polygon that is almost an axis-parallel rectangle.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
QgsGeometry variableWidthBufferByM(int segments) const
Calculates a variable width buffer for a (multi)linestring geometry, where the width at each node is ...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static QgsGeometry fromPolylineXY(const QgsPolylineXY &polyline)
Creates a new LineString geometry from a list of QgsPointXY points.
QgsMultiPointXY asMultiPoint() const
Returns the contents of the geometry as a multi-point.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
QgsPointXY closestVertex(const QgsPointXY &point, int &closestVertexIndex, int &previousVertexIndex, int &nextVertexIndex, double &sqrDist) const
Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap ...
void normalize()
Reorganizes the geometry into a normalized form (or "canonical" form).
int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const
Returns the length of the QByteArray returned by asWkb()
QgsPolygonXY asPolygon() const
Returns the contents of the geometry as a polygon.
bool disjoint(const QgsGeometry &geometry) const
Returns true if the geometry is disjoint of another geometry.
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
QgsGeometry roundWavesRandomized(double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed=0) const
Constructs randomized rounded (sine-like) waves along the boundary of the geometry,...
double distance(const QgsGeometry &geom) const
Returns the minimum distance between this geometry and another geometry.
QgsGeometry interpolate(double distance) const
Returns an interpolated point on the geometry at the specified distance.
QgsGeometry extrude(double x, double y)
Returns an extruded version of this geometry.
static Q_DECL_DEPRECATED QgsPolylineXY createPolylineFromQPolygonF(const QPolygonF &polygon)
Creates a QgsPolylineXY from a QPolygonF.
void mapToPixel(const QgsMapToPixel &mtp)
Transforms the geometry from map units to pixels in place.
static QgsGeometry fromMultiPointXY(const QgsMultiPointXY &multipoint)
Creates a new geometry from a QgsMultiPointXY object.
QgsGeometry singleSidedBuffer(double distance, int segments, Qgis::BufferSide side, Qgis::JoinStyle joinStyle=Qgis::JoinStyle::Round, double miterLimit=2.0) const
Returns a single sided buffer for a (multi)line geometry.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
QgsBox3D boundingBox3D() const
Returns the 3D bounding box of the geometry.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsGeometry subdivide(int maxNodes=256, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Subdivides the geometry.
bool contains(const QgsPointXY *p) const
Returns true if the geometry contains the point p.
QgsPolylineXY asPolyline() const
Returns the contents of the geometry as a polyline.
QgsAbstractGeometry::part_iterator parts_begin()
Returns STL-style iterator pointing to the first part of the geometry.
QgsGeometry forceRHR() const
Forces geometries to respect the Right-Hand-Rule, in which the area that is bounded by a polygon is t...
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
QgsGeometry snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const
Returns a new geometry with all points or vertices snapped to the closest point of the grid.
virtual json asJsonObject(int precision=17) const
Exports the geometry to a json object.
void filterVertices(const std::function< bool(const QgsPoint &) > &filter)
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
bool equals(const QgsGeometry &geometry) const
Test if this geometry is exactly equal to another geometry.
bool isGeosValid(Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const
Checks validity of the geometry using GEOS.
bool insertVertex(double x, double y, int beforeVertex)
Insert a new vertex before the given vertex index, ring and item (first number is index 0) If the req...
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
static Q_DECL_DEPRECATED QgsPolygonXY createPolygonFromQPolygonF(const QPolygonF &polygon)
Creates a QgsPolygonXYfrom a QPolygonF.
bool convertToSingleType()
Converts multi type geometry into single type geometry e.g.
Qgis::GeometryOperationResult addRing(const QVector< QgsPointXY > &ring)
Adds a new ring to this geometry.
bool requiresConversionToStraightSegments() const
Returns true if the geometry is a curved geometry type which requires conversion to display as straig...
bool isSimple() const
Determines whether the geometry is simple (according to OGC definition), i.e.
static QgsGeometry fromPolyline(const QgsPolyline &polyline)
Creates a new LineString geometry from a list of QgsPoint points.
void validateGeometry(QVector< QgsGeometry::Error > &errors, Qgis::GeometryValidationEngine method=Qgis::GeometryValidationEngine::QgisInternal, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const
Validates geometry and produces a list of geometry errors.
QgsMultiPolylineXY asMultiPolyline() const
Returns the contents of the geometry as a multi-linestring.
QgsGeometry taperedBuffer(double startWidth, double endWidth, int segments) const
Calculates a variable width buffer ("tapered buffer") for a (multi)curve geometry.
Qgis::GeometryOperationResult avoidIntersectionsV2(const QList< QgsVectorLayer * > &avoidIntersectionsLayers, const QHash< QgsVectorLayer *, QSet< QgsFeatureId > > &ignoreFeatures=(QHash< QgsVectorLayer *, QSet< QgsFeatureId > >()))
Modifies geometry to avoid intersections with the layers specified in project properties.
bool within(const QgsGeometry &geometry) const
Returns true if the geometry is completely within another geometry.
QPointF asQPointF() const
Returns contents of the geometry as a QPointF if wkbType is WKBPoint, otherwise returns a null QPoint...
void convertToStraightSegment(double tolerance=M_PI/180., QgsAbstractGeometry::SegmentationToleranceType toleranceType=QgsAbstractGeometry::MaximumAngle)
Converts the geometry to straight line segments, if it is a curved geometry type.
double area() const
Returns the planar, 2-dimensional area of the geometry.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
bool crosses(const QgsGeometry &geometry) const
Returns true if the geometry crosses another geometry.
QgsGeometry & operator=(QgsGeometry const &rhs)
Creates a deep copy of the object.
QgsGeometry orthogonalize(double tolerance=1.0E-8, int maxIterations=1000, double angleThreshold=15.0) const
Attempts to orthogonalize a line or polygon geometry by shifting vertices to make the geometries angl...
Qgis::AngularDirection polygonOrientation() const
Returns the orientation of the polygon.
double hausdorffDistance(const QgsGeometry &geom) const
Returns the Hausdorff distance between this geometry and geom.
QgsGeometry largestEmptyCircle(double tolerance, const QgsGeometry &boundary=QgsGeometry()) const
Constructs the Largest Empty Circle for a set of obstacle geometries, up to a specified tolerance.
Qgis::GeometryOperationResult addPart(const QVector< QgsPointXY > &points, Qgis::GeometryType geomType=Qgis::GeometryType::Unknown)
Adds a new part to a the geometry.
QgsGeometryPartIterator parts()
Returns Java-style iterator for traversal of parts of the geometry.
QgsGeometry convertToCurves(double distanceTolerance=1e-8, double angleTolerance=1e-8) const
Attempts to convert a non-curved geometry into a curved geometry type (e.g.
QgsGeometry concaveHull(double targetPercent, bool allowHoles=false) const
Returns a possibly concave polygon that contains all the points in the geometry.
QgsGeometry voronoiDiagram(const QgsGeometry &extent=QgsGeometry(), double tolerance=0.0, bool edgesOnly=false) const
Creates a Voronoi diagram for the nodes contained within the geometry.
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
QgsGeometry convexHull() const
Returns the smallest convex polygon that contains all the points in the geometry.
QgsGeometry minimumClearanceLine() const
Returns a LineString whose endpoints define the minimum clearance of a geometry.
QgsGeometry sharedPaths(const QgsGeometry &other) const
Find paths shared between the two given lineal geometries (this and other).
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygonXY.
double sqrDistToVertexAt(QgsPointXY &point, int atVertex) const
Returns the squared Cartesian distance between the given point to the given vertex index (vertex at t...
void fromWkb(unsigned char *wkb, int length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
QgsGeometry intersection(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points shared by this geometry and other.
QgsGeometry symDifference(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points making up this geometry that do not make up other.
QgsGeometry minimalEnclosingCircle(QgsPointXY ¢er, double &radius, unsigned int segments=36) const
Returns the minimal enclosing circle for the geometry.
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
static QgsGeometry fromMultiPolygonXY(const QgsMultiPolygonXY &multipoly)
Creates a new geometry from a QgsMultiPolygonXY.
QgsGeometry buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsGeometry node() const
Returns a (Multi)LineString representing the fully noded version of a collection of linestrings.
double distanceToVertex(int vertex) const
Returns the distance along this geometry from its first vertex to the specified vertex.
int vertexNrFromVertexId(QgsVertexId id) const
Returns the vertex number corresponding to a vertex id.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
bool removeDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false)
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
bool convertGeometryCollectionToSubclass(Qgis::GeometryType geomType)
Converts geometry collection to a the desired geometry type subclass (multi-point,...
QgsAbstractGeometry::part_iterator parts_end()
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
QgsGeometry forcePolygonClockwise() const
Forces geometries to respect the exterior ring is clockwise, interior rings are counter-clockwise con...
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
QString asJson(int precision=17) const
Exports the geometry to a GeoJSON string.
static QgsGeometry createWedgeBuffer(const QgsPoint ¢er, double azimuth, double angularWidth, double outerRadius, double innerRadius=0)
Creates a wedge shaped buffer from a center point.
double frechetDistanceDensify(const QgsGeometry &geom, double densifyFraction) const
Returns the Fréchet distance between this geometry and geom, restricted to discrete points for both g...
QByteArray asWkb(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const
Export the geometry to WKB.
QgsGeometry unionCoverage() const
Optimized union algorithm for polygonal inputs that are correctly noded and do not overlap.
QgsGeometry extendLine(double startDistance, double endDistance) const
Extends a (multi)line geometry by extrapolating out the start or end of the line by a specified dista...
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries, const QgsGeometryParameters ¶meters=QgsGeometryParameters())
Compute the unary union on a list of geometries.
bool convertToCurvedMultiType()
Converts a geometry into a multitype geometry of curve kind (when there is a corresponding curve type...
static void convertPointList(const QVector< QgsPointXY > &input, QgsPointSequence &output)
Upgrades a point list from QgsPointXY to QgsPoint.
QgsGeometry orientedMinimumBoundingBox() const
Returns the oriented minimum bounding box for the geometry, which is the smallest (by area) rotated r...
QgsGeometry triangularWavesRandomized(double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed=0) const
Constructs randomized triangular waves along the boundary of the geometry, with the specified wavelen...
QgsGeometry squareWavesRandomized(double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed=0) const
Constructs randomized square waves along the boundary of the geometry, with the specified wavelength ...
QgsGeometryConstPartIterator constParts() const
Returns Java-style iterator for traversal of parts of the geometry.
QgsGeometry simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
double minimumClearance() const
Computes the minimum clearance of a geometry.
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
Qgis::GeometryOperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
double interpolateAngle(double distance) const
Returns the angle parallel to the linestring or polygon boundary at the specified distance along the ...
double angleAtVertex(int vertex) const
Returns the bisector angle for this geometry at the specified vertex.
Qgis::GeometryOperationResult reshapeGeometry(const QgsLineString &reshapeLineString)
Replaces a part of this geometry with another line.
double closestVertexWithContext(const QgsPointXY &point, int &atVertex) const
Searches for the closest vertex in this geometry to the given point.
QgsGeometry delaunayTriangulation(double tolerance=0.0, bool edgesOnly=false) const
Returns the Delaunay triangulation for the vertices of the geometry.
void draw(QPainter &p) const
Draws the geometry onto a QPainter.
QgsGeometry smooth(unsigned int iterations=1, double offset=0.25, double minimumDistance=-1.0, double maxAngle=180.0) const
Smooths a geometry by rounding off corners using the Chaikin algorithm.
QgsGeometry forcePolygonCounterClockwise() const
Forces geometries to respect the exterior ring is counter-clockwise, interior rings are clockwise con...
QString asWkt(int precision=17) const
Exports the geometry to WKT.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry, double precision=0.0)
Creates and returns a new geometry engine representing the specified geometry using precision on a gr...
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitGeometry(const QVector< QgsPointXY > &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QVector< QgsPointXY > &topologyTestPoints, bool splitFeature=true)
Splits this geometry according to a given line.
bool toggleCircularAtVertex(int atVertex)
Converts the vertex at the given position from/to circular.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
bool moveVertex(double x, double y, int atVertex)
Moves the vertex at the given position number and item (first number is index 0) to the given coordin...
QgsGeometry()
Constructor.
QgsGeometry constrainedDelaunayTriangulation() const
Returns a constrained Delaunay triangulation for the vertices of the geometry.
bool isGeosEqual(const QgsGeometry &) const
Compares the geometry with another geometry using GEOS.
double closestSegmentWithContext(const QgsPointXY &point, QgsPointXY &minDistPoint, int &nextVertexIndex, int *leftOrRightOfSegment=nullptr, double epsilon=DEFAULT_SEGMENT_EPSILON) const
Searches for the closest segment of geometry to the given point.
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
static QgsGeometry fromBox3D(const QgsBox3D &box)
Creates a new geometry from a QgsBox3D object.
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
bool deletePart(int partNum)
Deletes part identified by the part number.
QgsGeometry removeInteriorRings(double minimumAllowedArea=-1) const
Removes the interior rings from a (multi)polygon geometry.
static QgsGeometry fromPoint(const QgsPoint &point)
Creates a new geometry from a QgsPoint object.
bool overlaps(const QgsGeometry &geometry) const
Returns true if the geometry overlaps another geometry.
Q_DECL_DEPRECATED int avoidIntersections(const QList< QgsVectorLayer * > &avoidIntersectionsLayers, const QHash< QgsVectorLayer *, QSet< QgsFeatureId > > &ignoreFeatures=(QHash< QgsVectorLayer *, QSet< QgsFeatureId > >()))
Modifies geometry to avoid intersections with the layers specified in project properties.
QgsGeometry shortestLine(const QgsGeometry &other) const
Returns the shortest line joining this geometry to another geometry.
Does vector analysis using the geos library and handles import, export, exception handling*.
double hausdorffDistanceDensify(const QgsAbstractGeometry *geom, double densifyFraction, QString *errorMsg=nullptr) const
Returns the Hausdorff distance between this geometry and geom.
double hausdorffDistance(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const
Returns the Hausdorff distance between this geometry and geom.
QgsAbstractGeometry * buffer(double distance, int segments, QString *errorMsg=nullptr) const override
double distance(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const override
Calculates the distance between this and geom.
static QgsGeometry polygonize(const QVector< const QgsAbstractGeometry * > &geometries, QString *errorMsg=nullptr)
Creates a GeometryCollection geometry containing possible polygons formed from the constituent linewo...
double frechetDistance(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const
Returns the Fréchet distance between this geometry and geom, restricted to discrete points for both g...
double frechetDistanceDensify(const QgsAbstractGeometry *geom, double densifyFraction, QString *errorMsg=nullptr) const
Returns the Fréchet distance between this geometry and geom, restricted to discrete points for both g...
This class offers geometry processing methods.
QgsGeometry triangularWavesRandomized(double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed=0) const
Constructs randomized triangular waves along the boundary of the geometry, with the specified wavelen...
QgsGeometry triangularWaves(double wavelength, double amplitude, bool strictWavelength=false) const
Constructs triangular waves along the boundary of the geometry, with the specified wavelength and amp...
QgsGeometry roundWaves(double wavelength, double amplitude, bool strictWavelength=false) const
Constructs rounded (sine-like) waves along the boundary of the geometry, with the specified wavelengt...
QgsGeometry poleOfInaccessibility(double precision, double *distanceFromBoundary=nullptr) const
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal ...
QgsGeometry squareWaves(double wavelength, double amplitude, bool strictWavelength=false) const
Constructs square waves along the boundary of the geometry, with the specified wavelength and amplitu...
QgsGeometry variableWidthBufferByM(int segments) const
Calculates a variable width buffer using the m-values from a (multi)line geometry.
QgsGeometry extrude(double x, double y) const
Will extrude a line or (segmentized) curve by a given offset and return a polygon representation of i...
QgsGeometry roundWavesRandomized(double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed=0) const
Constructs randomized rounded (sine-like) waves along the boundary of the geometry,...
QgsGeometry orthogonalize(double tolerance=1.0E-8, int maxIterations=1000, double angleThreshold=15.0) const
Attempts to orthogonalize a line or polygon geometry by shifting vertices to make the geometries angl...
QString lastError() const
Returns an error string referring to the last error encountered.
QgsGeometry orientedMinimumBoundingBox(double &area, double &angle, double &width, double &height) const
Returns the oriented minimum bounding box for the geometry, which is the smallest (by area) rotated r...
QgsGeometry densifyByDistance(double distance) const
Densifies the geometry by adding regularly placed extra nodes inside each segment so that the maximum...
QgsGeometry taperedBuffer(double startWidth, double endWidth, int segments) const
Calculates a tapered width buffer for a (multi)curve geometry.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Densifies the geometry by adding the specified number of extra nodes within each segment of the geome...
QgsGeometry applyDashPattern(const QVector< double > &pattern, Qgis::DashPatternLineEndingRule startRule=Qgis::DashPatternLineEndingRule::NoRule, Qgis::DashPatternLineEndingRule endRule=Qgis::DashPatternLineEndingRule::NoRule, Qgis::DashPatternSizeAdjustment adjustment=Qgis::DashPatternSizeAdjustment::ScaleBothDashAndGap, double patternOffset=0) const
Applies a dash pattern to a geometry, returning a MultiLineString geometry which is the input geometr...
QgsGeometry squareWavesRandomized(double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed=0) const
Constructs randomized square waves along the boundary of the geometry, with the specified wavelength ...
QgsGeometry convertToCurves(double distanceTolerance, double angleTolerance) const
Attempts to convert a non-curved geometry into a curved geometry type (e.g.
bool isAxisParallelRectangle(double maximumDeviation, bool simpleRectanglesOnly=false) const
Returns true if the geometry is a polygon that is almost an axis-parallel rectangle.
Line string geometry type, with support for z-dimension and m-values.
const double * yData() const
Returns a const pointer to the y vertex data.
const double * xData() const
Returns a const pointer to the x vertex data.
int numPoints() const override
Returns the number of points in the curve.
static QgsLineString * fromQPolygonF(const QPolygonF &polygon)
Returns a new linestring from a QPolygonF polygon input.
QgsLineString * clone() const override
Clones the geometry by performing a deep copy.
Perform transforms between map coordinates and device coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
Multi line string geometry collection.
QgsLineString * lineStringN(int index)
Returns the line string with the specified index.
Multi point geometry collection.
QgsPoint * pointN(int index)
Returns the point with the specified index.
Multi polygon geometry collection.
QgsPolygon * polygonN(int index)
Returns the polygon with the specified index.
A class to represent a 2D point.
void setY(double y)
Sets the y value of the point.
void setX(double x)
Sets the x value of the point.
QPointF toQPointF() const
Converts a point to a QPointF.
Point geometry type, with support for z-dimension and m-values.
void setX(double x)
Sets the point's x-coordinate.
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const
Returns a new point which corresponds to this point projected by a specified distance with specified ...
A rectangle specified with double values.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool isNull() const
Test if the rectangle is null (holding no spatial information).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
bool isEmpty() const
Returns true if the rectangle has no area.
Represents a vector layer which manages a vector based data sets.
Java-style iterator for traversal of vertices of a geometry.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
static bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
static Qgis::WkbType multiType(Qgis::WkbType type)
Returns the multi type for a WKB type.
static bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
static Qgis::WkbType curveType(Qgis::WkbType type)
Returns the curve type for a WKB type.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Contains geos related utilities and functions.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QVector< QgsPoint > QgsPointSequence
Q_GLOBAL_STATIC(QReadWriteLock, sDefinitionCacheLock)
QDataStream & operator<<(QDataStream &out, const QgsGeometry &geometry)
Writes the geometry to stream out. QGIS version compatibility is not guaranteed.
std::unique_ptr< QgsLineString > smoothCurve(const QgsLineString &line, const unsigned int iterations, const double offset, double squareDistThreshold, double maxAngleRads, bool isRing)
Q_GLOBAL_STATIC_WITH_ARGS(WktCache, sWktCache,(2000)) QgsGeometry QgsGeometry
QDataStream & operator>>(QDataStream &in, QgsGeometry &geometry)
Reads a geometry from stream in into geometry. QGIS version compatibility is not guaranteed.
QCache< QString, QgsGeometry > WktCache
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
#define QgsDebugError(str)
std::unique_ptr< QgsAbstractGeometry > geometry
QgsGeometryPrivate(std::unique_ptr< QgsAbstractGeometry > geometry)
Utility class for identifying a unique vertex within a geometry.
bool isValid() const
Returns true if the vertex id is valid.