QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
20 #include <nlohmann/json.hpp>
55 std::unique_ptr< QgsAbstractGeometry >
geometry;
65 if ( !d->
ref.deref() )
73 d->
ref = QAtomicInt( 1 );
80 d->
ref = QAtomicInt( 1 );
86 mLastError = other.mLastError;
94 if ( !d->
ref.deref() )
99 mLastError = other.mLastError;
106 void QgsGeometry::detach()
111 std::unique_ptr< QgsAbstractGeometry > cGeom;
113 cGeom.reset( d->
geometry->clone() );
115 reset( std::move( cGeom ) );
118 void QgsGeometry::reset( std::unique_ptr<QgsAbstractGeometry> newGeometry )
122 ( void )d->
ref.deref();
125 d->
geometry = std::move( newGeometry );
141 if ( d->
geometry.get() == geometry )
146 reset( std::unique_ptr< QgsAbstractGeometry >( geometry ) );
186 return QgsGeometry( qgis::make_unique< QgsLineString >( polyline ) );
231 std::unique_ptr< QgsLineString > ext = qgis::make_unique< QgsLineString >(
232 QVector< double >() << rect.
xMinimum()
237 QVector< double >() << rect.
yMinimum()
242 std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
243 polygon->setExteriorRing( ext.release() );
260 if ( g.isMultipart() )
262 for (
auto p = g.const_parts_begin(); p != g.const_parts_end(); ++p )
264 collected.
addPart( ( *p )->clone() );
278 if ( std::abs( angularWidth ) >= 360.0 )
280 std::unique_ptr< QgsCompoundCurve > outerCc = qgis::make_unique< QgsCompoundCurve >();
285 std::unique_ptr< QgsCurvePolygon > cp = qgis::make_unique< QgsCurvePolygon >();
286 cp->setExteriorRing( outerCc.release() );
290 std::unique_ptr< QgsCompoundCurve > innerCc = qgis::make_unique< QgsCompoundCurve >();
295 cp->setInteriorRings( { innerCc.release() } );
301 std::unique_ptr< QgsCompoundCurve > wedge = qgis::make_unique< QgsCompoundCurve >();
303 const double startAngle = azimuth - angularWidth * 0.5;
304 const double endAngle = azimuth + angularWidth * 0.5;
309 const bool useShortestArc = angularWidth <= 180.0;
327 std::unique_ptr< QgsCurvePolygon > cp = qgis::make_unique< QgsCurvePolygon >();
328 cp->setExteriorRing( wedge.release() );
407 d->
geometry->adjacentVertices(
id, prevVertex, nextVertex );
443 return d->
geometry->vertexAngle( v2 );
462 d->
geometry->adjacentVertices(
id, beforeVertexId, afterVertexId );
500 return d->
geometry->moveVertex(
id, p );
533 return d->
geometry->deleteVertex(
id );
585 return d->
geometry->insertVertex(
id, point );
601 return d->
geometry->vertexAt( vId );
615 result.mLastError = mLastError;
624 result.mLastError = mLastError;
648 double epsilon )
const
658 double sqrDist = d->
geometry->closestSegment(
QgsPoint( point ), segmentPt, vertexAfter,
leftOf, epsilon );
662 minDistPoint.
setX( segmentPt.
x() );
663 minDistPoint.
setY( segmentPt.
y() );
670 std::unique_ptr< QgsLineString > ringLine = qgis::make_unique< QgsLineString >( ring );
671 return addRing( ringLine.release() );
676 std::unique_ptr< QgsCurve > r( ring );
696 std::unique_ptr< QgsAbstractGeometry > partGeom;
697 if ( points.size() == 1 )
699 partGeom = qgis::make_unique< QgsPoint >( points[0] );
701 else if ( points.size() > 1 )
703 std::unique_ptr< QgsLineString > ringLine = qgis::make_unique< QgsLineString >();
704 ringLine->setPoints( points );
705 partGeom = std::move( ringLine );
707 return addPart( partGeom.release(), geomType );
712 std::unique_ptr< QgsAbstractGeometry > p( part );
718 reset( qgis::make_unique< QgsMultiPoint >() );
721 reset( qgis::make_unique< QgsMultiLineString >() );
724 reset( qgis::make_unique< QgsMultiPolygon >() );
728 return QgsGeometry::OperationResult::AddPartNotMultiGeometry;
764 QVector<QgsGeometry> results;
765 results.reserve(
parts.count() );
772 if ( results.isEmpty() )
776 for (
const QgsGeometry &result : qgis::as_const( results ) )
785 newPoly->removeInteriorRings( minimumRingArea );
799 d->
geometry->transform( QTransform::fromTranslate( dx, dy ), dz, 1.0, dm );
812 QTransform t = QTransform::fromTranslate( center.
x(), center.
y() );
813 t.rotate( -rotation );
814 t.translate( -center.
x(), -center.
y() );
824 return splitGeometry( split, newGeometries, topological, topology, splitFeature );
830 return QgsGeometry::OperationResult::InvalidBaseGeometry;
833 QVector<QgsGeometry > newGeoms;
854 *
this = newGeoms.takeAt( 0 );
855 newGeometries = newGeoms;
861 return QgsGeometry::OperationResult::Success;
865 return QgsGeometry::OperationResult::GeometryEngineError;
867 return QgsGeometry::OperationResult::InvalidBaseGeometry;
869 return QgsGeometry::OperationResult::InvalidInputGeometryType;
871 return QgsGeometry::OperationResult::SplitCannotSplitPoint;
873 return QgsGeometry::OperationResult::NothingHappened;
892 std::unique_ptr< QgsAbstractGeometry > geom(
geos.reshapeGeometry( reshapeLineString, &errorCode, &mLastError ) );
895 reset( std::move( geom ) );
931 std::unique_ptr< QgsAbstractGeometry > diffGeom(
geos.intersection( other.
constGet(), &mLastError ) );
937 reset( std::move( diffGeom ) );
951 std::unique_ptr< QgsAbstractGeometry > diffGeom(
geos.intersection( other.
constGet(), &mLastError ) );
955 result.mLastError = mLastError;
974 area = std::numeric_limits<double>::max();
976 width = std::numeric_limits<double>::max();
977 height = std::numeric_limits<double>::max();
993 double totalRotation = 0;
997 double rotateAngle = 180.0 / M_PI * currentAngle;
998 totalRotation += rotateAngle;
1000 QTransform t = QTransform::fromTranslate( pt0.
x(), pt0.
y() );
1001 t.rotate( rotateAngle );
1002 t.translate( -pt0.
x(), -pt0.
y() );
1007 double currentArea = bounds.
width() * bounds.
height();
1008 if ( currentArea <
area )
1012 angle = totalRotation;
1013 width = bounds.
width();
1014 height = bounds.
height();
1024 if (
angle > 180.0 )
1038 auto l_boundary = boundary.length();
1040 if ( ( points.length() == 0 ) || ( l_boundary == 3 ) )
1042 switch ( l_boundary )
1049 boundary.pop_back();
1054 boundary.pop_back();
1056 boundary.pop_back();
1073 circ_mec = __recMinimalEnclosingCircle( points, boundary );
1077 boundary.append( pxy );
1078 circ_mec = __recMinimalEnclosingCircle( points, boundary );
1102 QgsCircle circ = __recMinimalEnclosingCircle( P, R );
1123 return engine.
orthogonalize( tolerance, maxIterations, angleThreshold );
1132 return QgsGeometry( d->
geometry->snappedToGrid( hSpacing, vSpacing, dSpacing, mSpacing ) );
1141 return d->
geometry->removeDuplicateNodes( epsilon, useZValues );
1169 return geos.intersects( geometry.d->
geometry.get(), &mLastError );
1182 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( d->
geometry.get() );
1186 return d->
geometry->boundingBox().intersects( rectangle );
1209 return geos.contains( &pt, &mLastError );
1221 return geos.contains( geometry.d->
geometry.get(), &mLastError );
1233 return geos.disjoint( geometry.d->
geometry.get(), &mLastError );
1244 if ( d == geometry.d )
1264 return geos.touches( geometry.d->
geometry.get(), &mLastError );
1276 return geos.overlaps( geometry.d->
geometry.get(), &mLastError );
1288 return geos.within( geometry.d->
geometry.get(), &mLastError );
1300 return geos.crosses( geometry.d->
geometry.get(), &mLastError );
1329 QVector< QgsGeometry > res;
1367 std::unique_ptr< QgsAbstractGeometry > exterior( ( *part )->clone() );
1368 if (
QgsCurve *curve = qgsgeometry_cast< QgsCurve * >( exterior.get() ) )
1372 std::unique_ptr< QgsCurvePolygon > cp = qgis::make_unique< QgsCurvePolygon >();
1373 cp->setExteriorRing( curve );
1375 gc->addGeometry( cp.release() );
1379 std::unique_ptr< QgsPolygon > p = qgis::make_unique< QgsPolygon >();
1380 p->setExteriorRing( qgsgeometry_cast< QgsLineString * >( curve ) );
1382 gc->addGeometry( p.release() );
1395 std::unique_ptr< QgsMultiPoint > mp = qgis::make_unique< QgsMultiPoint >();
1397 QSet< QgsPoint > added;
1400 if ( added.contains( *vertex ) )
1402 mp->addGeometry( ( *vertex ).clone() );
1403 added.insert( *vertex );
1437 res.reserve(
parts->partCount() );
1438 for (
int i = 0; i <
parts->partCount( ); i++ )
1455 return convertToPoint( destMultipart );
1458 return convertToLine( destMultipart );
1461 return convertToPolygon( destMultipart );
1513 if ( !multiGeom || multiGeom->
partCount() < 1 )
1516 std::unique_ptr< QgsAbstractGeometry > firstPart( multiGeom->
geometryN( 0 )->
clone() );
1517 reset( std::move( firstPart ) );
1528 std::unique_ptr<QgsGeometryCollection> resGeom;
1532 resGeom = qgis::make_unique<QgsMultiPoint>();
1535 resGeom = qgis::make_unique<QgsMultiLineString>();
1538 resGeom = qgis::make_unique<QgsMultiPolygon>();
1551 resGeom->addGeometry( g->
clone() );
1554 set( resGeom.release() );
1584 std::unique_ptr< QgsLineString > segmentizedLine;
1586 if ( doSegmentation )
1594 line = segmentizedLine.get();
1598 line = qgsgeometry_cast<QgsLineString *>( d->
geometry.get() );
1606 polyLine.resize( nVertices );
1608 const double *xData = line->
xData();
1609 const double *yData = line->
yData();
1610 for (
int i = 0; i < nVertices; ++i )
1612 data->
setX( *xData++ );
1613 data->
setY( *yData++ );
1628 std::unique_ptr< QgsPolygon > segmentized;
1629 if ( doSegmentation )
1636 segmentized.reset( curvePoly->
toPolygon() );
1637 p = segmentized.get();
1641 p = qgsgeometry_cast<QgsPolygon *>( d->
geometry.get() );
1650 convertPolygon( *p, polygon );
1670 for (
int i = 0; i < nPoints; ++i )
1673 multiPoint[i].
setX( pt->
x() );
1674 multiPoint[i].setY( pt->
y() );
1687 if ( !geomCollection )
1699 mpl.reserve( nLines );
1700 for (
int i = 0; i < nLines; ++i )
1703 std::unique_ptr< QgsLineString > segmentized;
1706 const QgsCurve *curve = qgsgeometry_cast<const QgsCurve *>( geomCollection->
geometryN( i ) );
1712 line = segmentized.get();
1717 polyLine.resize( nVertices );
1719 const double *xData = line->
xData();
1720 const double *yData = line->
yData();
1721 for (
int i = 0; i < nVertices; ++i )
1723 data->
setX( *xData++ );
1724 data->
setY( *yData++ );
1727 mpl.append( polyLine );
1740 if ( !geomCollection )
1746 if ( nPolygons < 1 )
1752 for (
int i = 0; i < nPolygons; ++i )
1754 const QgsPolygon *polygon = qgsgeometry_cast<const QgsPolygon *>( geomCollection->
geometryN( i ) );
1769 convertPolygon( *polygon, poly );
1785 double geosArea = g.
area();
1786 double qgisArea = 0;
1790 qgisArea = surface->
area();
1795 return g.
area( &mLastError );
1806 return g.
length( &mLastError );
1819 return qgsgeometry_cast< const QgsPoint * >( d->
geometry.get() )->distance( *qgsgeometry_cast< const QgsPoint * >( geom.
constGet() ) );
1855 return d->
geometry->vertices_begin();
1862 return d->
geometry->vertices_end();
1892 return d->
geometry->const_parts_begin();
1899 return d->
geometry->const_parts_end();
1928 std::unique_ptr<QgsAbstractGeometry> geom( g.
buffer(
distance, segments, &mLastError ) );
1932 result.mLastError = mLastError;
1951 result.mLastError = mLastError;
1967 QVector<QgsGeometry> results;
1968 results.reserve(
parts.count() );
1975 if ( results.isEmpty() )
1979 for (
const QgsGeometry &result : qgis::as_const( results ) )
1993 std::unique_ptr< QgsAbstractGeometry > offsetGeom(
geos.offsetCurve(
distance, segments, joinStyle, miterLimit, &mLastError ) );
1997 result.mLastError = mLastError;
2001 if (
const QgsCurve *
offsetCurve = qgsgeometry_cast< const QgsCurve * >( offsetGeom.get() ) )
2004 if ( newOrientation != prevOrientation )
2007 std::unique_ptr< QgsAbstractGeometry > flipped(
offsetCurve->reversed() );
2008 offsetGeom = std::move( flipped );
2025 QVector<QgsGeometry> results;
2026 results.reserve(
parts.count() );
2033 if ( results.isEmpty() )
2037 for (
const QgsGeometry &result : qgis::as_const( results ) )
2047 std::unique_ptr< QgsAbstractGeometry > bufferGeom =
geos.singleSidedBuffer(
distance, segments, side,
2048 joinStyle, miterLimit, &mLastError );
2052 result.mLastError = mLastError;
2063 return engine.
taperedBuffer( startWidth, endWidth, segments );
2083 QVector<QgsGeometry> results;
2084 results.reserve(
parts.count() );
2091 if ( results.isEmpty() )
2095 for (
const QgsGeometry &result : qgis::as_const( results ) )
2107 std::unique_ptr< QgsLineString > newLine( line->
clone() );
2108 newLine->extend( startDistance, endDistance );
2122 std::unique_ptr< QgsAbstractGeometry > simplifiedGeom(
geos.simplify( tolerance, &mLastError ) );
2123 if ( !simplifiedGeom )
2126 result.mLastError = mLastError;
2129 return QgsGeometry( std::move( simplifiedGeom ) );
2164 c.get()->dropZValue();
2165 c.get()->dropMValue();
2173 result.mLastError = mLastError;
2188 result.mLastError = mLastError;
2207 std::unique_ptr< QgsAbstractGeometry > cHull(
geos.convexHull( &mLastError ) );
2211 geom.mLastError = mLastError;
2227 result.mLastError = mLastError;
2240 QgsGeometry result =
geos.delaunayTriangulation( tolerance, edgesOnly );
2241 result.mLastError = mLastError;
2253 std::unique_ptr< QgsAbstractGeometry > segmentizedCopy;
2256 segmentizedCopy.reset( d->
geometry->segmentize() );
2257 geom = segmentizedCopy.get();
2262 std::unique_ptr< QgsAbstractGeometry > result(
geos.subdivide( maxNodes, &mLastError ) );
2266 geom.mLastError = mLastError;
2292 for (
int part = 0; part < collection->
numGeometries(); ++part )
2294 const QgsCurve *candidate = qgsgeometry_cast< const QgsCurve * >( collection->
geometryN( part ) );
2297 const double candidateLength = candidate->
length();
2309 curve = qgsgeometry_cast< const QgsCurve * >( line.
constGet() );
2338 return geos.lineLocatePoint( *(
static_cast< QgsPoint *
>( point.d->
geometry.get() ) ), &mLastError );
2358 if ( previous == next )
2405 std::unique_ptr< QgsAbstractGeometry > resultGeom(
geos.intersection( geometry.d->
geometry.get(), &mLastError ) );
2410 geom.mLastError = mLastError;
2426 std::unique_ptr< QgsAbstractGeometry > resultGeom(
geos.combine( geometry.d->
geometry.get(), &mLastError ) );
2430 geom.mLastError = mLastError;
2452 result.mLastError = mLastError;
2466 std::unique_ptr< QgsAbstractGeometry > resultGeom(
geos.difference( geometry.d->
geometry.get(), &mLastError ) );
2470 geom.mLastError = mLastError;
2486 std::unique_ptr< QgsAbstractGeometry > resultGeom(
geos.symDifference( geometry.d->
geometry.get(), &mLastError ) );
2490 geom.mLastError = mLastError;
2500 return engine.
extrude( x, y );
2507 return QVector< QgsPointXY >();
2515 return QVector< QgsPointXY >();
2528 QVector<QgsGeometry> geometryList;
2531 return geometryList;
2538 geometryList.reserve( numGeom );
2539 for (
int i = 0; i < numGeom; ++i )
2546 geometryList.append( *
this );
2549 return geometryList;
2564 line = qgsgeometry_cast< const QgsLineString * >(
constGet() );
2570 line = qgsgeometry_cast< const QgsLineString * >( polygon->
exteriorRing() );
2575 const double *srcX = line->
xData();
2576 const double *srcY = line->
yData();
2578 QPolygonF res( count );
2579 QPointF *dest = res.data();
2580 for (
int i = 0; i < count; ++i )
2582 *dest++ = QPointF( *srcX++, *srcY++ );
2632 reset( std::move( diffGeom ) );
2647 result.mLastError = mLastError;
2664 if (
const QgsCurvePolygon *cp = qgsgeometry_cast< const QgsCurvePolygon * >( g ) )
2666 std::unique_ptr< QgsCurvePolygon > corrected( cp->clone() );
2667 corrected->forceRHR();
2668 newCollection->addGeometry( corrected.release() );
2672 newCollection->addGeometry( g->
clone() );
2681 std::unique_ptr< QgsCurvePolygon > corrected( cp->clone() );
2682 corrected->forceRHR();
2741 return d->
geometry->isValid( mLastError,
static_cast< int >( flags ) );
2751 return geos.isSimple( &mLastError );
2782 return geos.isEqual( g.d->
geometry.get(), &mLastError );
2790 std::unique_ptr< QgsAbstractGeometry > geom(
geos.combine( geometries, &error ) );
2792 result.mLastError = error;
2800 QVector<const QgsAbstractGeometry *> geomV2List;
2803 if ( !( g.isNull() ) )
2805 geomV2List.append( g.constGet() );
2811 result.mLastError = error;
2822 std::unique_ptr< QgsAbstractGeometry > straightGeom( d->
geometry->segmentize( tolerance, toleranceType ) );
2823 reset( std::move( straightGeom ) );
2833 return d->
geometry->hasCurvedSegments();
2844 d->
geometry->transform( ct, direction, transformZ );
2856 d->
geometry->transform( ct, zTranslate, zScale, mTranslate, mScale );
2878 std::unique_ptr< QgsAbstractGeometry > resultGeom =
geos.clip( rectangle, &mLastError );
2882 result.mLastError = mLastError;
2896 static bool vertexIndexInfo(
const QgsAbstractGeometry *g,
int vertexIndex,
int &partIndex,
int &ringIndex,
int &vertex )
2898 if ( vertexIndex < 0 )
2901 if (
const QgsGeometryCollection *geomCollection = qgsgeometry_cast<const QgsGeometryCollection *>( g ) )
2905 for (
int i = 0; i < geomCollection->numGeometries(); ++i )
2911 for (
int k = 0; k < part->
ringCount(); ++k )
2914 if ( vertexIndex < numPoints )
2917 return vertexIndexInfo( part, vertexIndex, nothing, ringIndex, vertex );
2919 vertexIndex -= numPoints;
2920 offset += numPoints;
2924 else if (
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast<const QgsCurvePolygon *>( g ) )
2926 const QgsCurve *ring = curvePolygon->exteriorRing();
2927 if ( vertexIndex < ring->numPoints() )
2931 vertex = vertexIndex;
2936 for (
int i = 0; i < curvePolygon->numInteriorRings(); ++i )
2938 const QgsCurve *ring = curvePolygon->interiorRing( i );
2939 if ( vertexIndex < ring->numPoints() )
2942 vertex = vertexIndex;
2949 else if (
const QgsCurve *curve = qgsgeometry_cast<const QgsCurve *>( g ) )
2951 if ( vertexIndex < curve->numPoints() )
2955 vertex = vertexIndex;
2959 else if ( qgsgeometry_cast<const QgsPoint *>( g ) )
2961 if ( vertexIndex == 0 )
2982 bool res = vertexIndexInfo( d->
geometry.get(), nr,
id.part,
id.ring,
id.vertex );
2988 if (
const QgsGeometryCollection *geomCollection = qgsgeometry_cast<const QgsGeometryCollection *>( g ) )
2990 g = geomCollection->geometryN(
id.part );
2993 if (
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast<const QgsCurvePolygon *>( g ) )
2995 g =
id.ring == 0 ? curvePolygon->exteriorRing() : curvePolygon->interiorRing(
id.ring - 1 );
2998 if (
const QgsCurve *curve = qgsgeometry_cast<const QgsCurve *>( g ) )
3001 res = curve->pointAt(
id.vertex, p,
id.
type );
3015 return d->
geometry->vertexNumberFromVertexId(
id );
3030 d->
geometry->filterVertices( filter );
3064 output.resize( input.size() );
3066 for (
int i = 0; i < input.size(); ++i )
3068 const QgsPoint &pt = input.at( i );
3069 output[i].
setX( pt.
x() );
3070 output[i].setY( pt.
y() );
3078 if ( coords.empty() )
3083 output.resize( rings.size() );
3084 for (
int i = 0; i < rings.size(); ++i )
3086 convertToPolyline( rings[i], output[i] );
3092 return QgsGeometry( qgis::make_unique< QgsPoint >( point.x(), point.y() ) );
3099 if ( polygon.isClosed() )
3101 std::unique_ptr< QgsPolygon > poly = qgis::make_unique< QgsPolygon >();
3102 poly->setExteriorRing( ring.release() );
3123 result.reserve( polygon.count() );
3124 for (
const QPointF &p : polygon )
3133 if ( p1.count() != p2.count() )
3136 for (
int i = 0; i < p1.count(); ++i )
3138 if ( !p1.at( i ).compare( p2.at( i ), epsilon ) )
3146 if ( p1.count() != p2.count() )
3149 for (
int i = 0; i < p1.count(); ++i )
3160 if ( p1.count() != p2.count() )
3163 for (
int i = 0; i < p1.count(); ++i )
3190 return QgsGeometry( smoothLine( *lineString, iterations, offset, minimumDistance, maxAngle ) );
3197 std::unique_ptr< QgsMultiLineString > resultMultiline = qgis::make_unique< QgsMultiLineString> ();
3201 resultMultiline->addGeometry( smoothLine( *(
static_cast< QgsLineString *
>( multiLine->
geometryN( i ) ) ), iterations, offset, minimumDistance, maxAngle ).release() );
3203 return QgsGeometry( std::move( resultMultiline ) );
3209 return QgsGeometry( smoothPolygon( *poly, iterations, offset, minimumDistance, maxAngle ) );
3216 std::unique_ptr< QgsMultiPolygon > resultMultiPoly = qgis::make_unique< QgsMultiPolygon >();
3220 resultMultiPoly->addGeometry( smoothPolygon( *(
static_cast< QgsPolygon *
>( multiPoly->
geometryN( i ) ) ), iterations, offset, minimumDistance, maxAngle ).release() );
3222 return QgsGeometry( std::move( resultMultiPoly ) );
3232 const double offset,
double squareDistThreshold,
double maxAngleRads,
3235 std::unique_ptr< QgsLineString > result = qgis::make_unique< QgsLineString >( line );
3237 for (
unsigned int iteration = 0; iteration < iterations; ++iteration )
3239 outputLine.resize( 0 );
3240 outputLine.reserve( 2 * ( result->numPoints() - 1 ) );
3241 bool skipFirst =
false;
3242 bool skipLast =
false;
3245 QgsPoint p1 = result->pointN( result->numPoints() - 2 );
3251 skipFirst =
angle > maxAngleRads;
3253 for (
int i = 0; i < result->numPoints() - 1; i++ )
3256 QgsPoint p2 = result->pointN( i + 1 );
3258 double angle = M_PI;
3259 if ( i == 0 && isRing )
3261 QgsPoint p3 = result->pointN( result->numPoints() - 2 );
3265 else if ( i < result->numPoints() - 2 )
3267 QgsPoint p3 = result->pointN( i + 2 );
3271 else if ( i == result->numPoints() - 2 && isRing )
3278 skipLast =
angle < M_PI - maxAngleRads ||
angle > M_PI + maxAngleRads;
3281 if ( i == 0 || i >= result->numPoints() - 2
3306 skipFirst = skipLast;
3309 if ( isRing && outputLine.at( 0 ) != outputLine.at( outputLine.count() - 1 ) )
3310 outputLine << outputLine.at( 0 );
3312 result->setPoints( outputLine );
3317 std::unique_ptr<QgsLineString> QgsGeometry::smoothLine(
const QgsLineString &line,
const unsigned int iterations,
const double offset,
double minimumDistance,
double maxAngle )
const
3319 double maxAngleRads = maxAngle * M_PI / 180.0;
3320 double squareDistThreshold = minimumDistance > 0 ? minimumDistance * minimumDistance : -1;
3321 return smoothCurve( line, iterations, offset, squareDistThreshold, maxAngleRads,
false );
3324 std::unique_ptr<QgsPolygon> QgsGeometry::smoothPolygon(
const QgsPolygon &polygon,
const unsigned int iterations,
const double offset,
double minimumDistance,
double maxAngle )
const
3326 double maxAngleRads = maxAngle * M_PI / 180.0;
3327 double squareDistThreshold = minimumDistance > 0 ? minimumDistance * minimumDistance : -1;
3328 std::unique_ptr< QgsPolygon > resultPoly = qgis::make_unique< QgsPolygon >();
3331 squareDistThreshold, maxAngleRads,
true ).release() );
3336 squareDistThreshold, maxAngleRads,
true ).release() );
3341 QgsGeometry QgsGeometry::convertToPoint(
bool destMultipart )
const
3349 if ( ( destMultipart && srcIsMultipart ) ||
3350 ( !destMultipart && !srcIsMultipart ) )
3355 if ( destMultipart )
3364 if ( multiPoint.count() == 1 )
3375 if ( !destMultipart )
3392 if ( !line.isEmpty() )
3401 if ( !destMultipart )
3432 QgsGeometry QgsGeometry::convertToLine(
bool destMultipart )
const
3442 if ( multiPoint.count() < 2 )
3445 if ( destMultipart )
3455 if ( ( destMultipart && srcIsMultipart ) ||
3456 ( !destMultipart && ! srcIsMultipart ) )
3461 if ( destMultipart )
3465 if ( !line.isEmpty() )
3472 if ( multiLine.count() == 1 )
3489 if ( destMultipart )
3494 else if ( multiLine.count() == 1 )
3505 if ( polygon.count() > 1 )
3509 if ( destMultipart )
3513 multiLine.reserve( polygon.count() );
3520 else if ( polygon.count() == 1 )
3522 if ( destMultipart )
3540 QgsGeometry QgsGeometry::convertToPolygon(
bool destMultipart )
const
3550 if ( multiPoint.count() < 3 )
3553 if ( multiPoint.last() != multiPoint.first() )
3554 multiPoint << multiPoint.first();
3557 if ( destMultipart )
3570 for ( QgsMultiPolylineXY::iterator multiLineIt = multiLine.begin(); multiLineIt != multiLine.end(); ++multiLineIt )
3573 if ( ( *multiLineIt ).count() < 3 )
3575 if ( ( *multiLineIt ).count() == 3 && ( *multiLineIt ).first() == ( *multiLineIt ).last() )
3579 if ( ( *multiLineIt ).first() != ( *multiLineIt ).last() )
3580 *multiLineIt << ( *multiLineIt ).first();
3584 if ( !multiPolygon.isEmpty() )
3586 if ( destMultipart )
3590 else if ( multiPolygon.count() == 1 )
3603 if ( line.count() < 3 )
3605 if ( line.count() == 3 && line.first() == line.last() )
3609 if ( line.first() != line.last() )
3610 line << line.first();
3613 if ( destMultipart )
3629 if ( ( destMultipart && srcIsMultipart ) ||
3630 ( !destMultipart && ! srcIsMultipart ) )
3635 if ( destMultipart )
3639 if ( !polygon.isEmpty() )
3645 if ( multiPolygon.count() == 1 )
3661 return new QgsGeos( geometry );
3666 out << geometry.
asWkb();
3672 QByteArray byteArray;
3674 if ( byteArray.isEmpty() )
3676 geometry.
set(
nullptr );
3680 geometry.
fromWkb( byteArray );
3697 return mHasLocation;
Abstract base class for curved geometry type.
QgsGeometry combine(const QgsGeometry &geometry) const
Returns a geometry representing all the points in this geometry and other (a union geometry operation...
@ Success
Operation succeeded.
QgsPoint center() const
Returns the center point.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
@ AddPartNotMultiGeometry
The source geometry is not multi.
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...
QgsPoint project(double distance, double azimuth, double inclination=90.0) const
Returns a new point which correspond to this point projected by a specified distance with specified a...
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...
bool contains(const QgsPoint &point, double epsilon=1E-8) const
Returns true if the circle contains the point.
@ ValidatorGeos
Use GEOS validation methods.
double hausdorffDistanceDensify(const QgsAbstractGeometry *geom, double densifyFraction, QString *errorMsg=nullptr) const
Returns the Hausdorff distance between this geometry and geom.
static Type multiType(Type type)
Returns the multi type for a WKB type.
QVector< QgsRingSequence > QgsCoordinateSequence
double hausdorffDistanceDensify(const QgsGeometry &geom, double densifyFraction) const
Returns the Hausdorff distance between this geometry and geom.
std::unique_ptr< QgsLineString > smoothCurve(const QgsLineString &line, const unsigned int iterations, const double offset, double squareDistThreshold, double maxAngleRads, bool isRing)
QDataStream & operator>>(QDataStream &in, QgsGeometry &geometry)
Reads a geometry from stream in into geometry. QGIS version compatibility is not guaranteed.
int makeDifferenceInPlace(const QgsGeometry &other)
Changes this geometry such that it does not intersect the other geometry.
double distance(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const override
Calculates the distance between this and geom.
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.
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Densifies the geometry by adding the specified number of extra nodes within each segment of the geome...
bool isValid() const
Returns true if the vertex id is valid.
static double sqrDistance2D(const QgsPoint &pt1, const QgsPoint &pt2)
Returns the squared 2D distance between two points.
QByteArray asWkb(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const
Export the geometry to WKB.
OperationResult addPart(const QVector< QgsPointXY > &points, QgsWkbTypes::GeometryType geomType=QgsWkbTypes::UnknownGeometry)
Adds a new part to a the geometry.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
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.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
@ InvalidInput
The input is not valid.
virtual void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const =0
Returns the vertices adjacent to a specified vertex within a geometry.
double distance(const QgsGeometry &geom) const
Returns the minimum distance between this geometry and another geometry.
bool convertGeometryCollectionToSubclass(QgsWkbTypes::GeometryType geomType)
Converts geometry collection to a the desired geometry type subclass (multi-point,...
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
bool within(const QgsGeometry &geometry) const
Returns true if the geometry is completely within another geometry.
static Q_DECL_DEPRECATED QgsPolygonXY createPolygonFromQPolygonF(const QPolygonF &polygon)
Creates a QgsPolygonXYfrom a QPolygonF.
void validateGeometry(QVector< QgsGeometry::Error > &errors, ValidationMethod method=ValidatorQgisInternal, QgsGeometry::ValidityFlags flags=QgsGeometry::ValidityFlags()) const
Validates geometry and produces a list of geometry errors.
double angleAtVertex(int vertex) const
Returns the bisector angle for this geometry at the specified vertex.
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...
virtual QgsPoint * interpolatePoint(double distance) const =0
Returns an interpolated point on the curve at the specified distance.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
QgsGeometry subdivide(int maxNodes=256) const
Subdivides the geometry.
static QgsGeometry fromPolylineXY(const QgsPolylineXY &polyline)
Creates a new LineString geometry from a list of QgsPointXY points.
Point geometry type, with support for z-dimension and m-values.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
int numGeometries() const
Returns the number of geometries within the collection.
QString asJson(int precision=17) const
Exports the geometry to a GeoJSON string.
static QgsGeometry fromMultiPolylineXY(const QgsMultiPolylineXY &multiline)
Creates a new geometry from a QgsMultiPolylineXY object.
static QgsGeometry fromPolyline(const QgsPolyline &polyline)
Creates a new LineString geometry from a list of QgsPoint points.
QgsGeometry variableWidthBufferByM(int segments) const
Calculates a variable width buffer using the m-values from a (multi)line geometry.
QgsGeometry removeInteriorRings(double minimumAllowedArea=-1) const
Removes the interior rings from a (multi)polygon geometry.
static std::unique_ptr< QgsPolygon > fromPolygonXY(const QgsPolygonXY &polygon)
Construct geometry from a polygon.
QgsGeometryPartIterator parts()
Returns Java-style iterator for traversal of parts of the geometry.
int numPoints() const override
Returns the number of points in the curve.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QDataStream & operator<<(QDataStream &out, const QgsGeometry &geometry)
Writes the geometry to stream out. QGIS version compatibility is not guaranteed.
@ NothingHappened
Nothing happened, without any error.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
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...
static std::unique_ptr< QgsAbstractGeometry > geomFromWkb(QgsConstWkbPtr &wkb)
Construct geometry from a WKB string.
Curve polygon geometry type.
QgsGeometry interpolate(double distance) const
Returns an interpolated point on the geometry at the specified distance.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
static QgsGeometry::OperationResult addRing(QgsAbstractGeometry *geometry, std::unique_ptr< QgsCurve > ring)
Add an interior ring to a geometry.
void fromWkb(unsigned char *wkb, int length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
Contains geos related utilities and functions.
@ EngineError
Error occurred in the geometry engine.
Multi line string geometry collection.
QgsGeometry poleOfInaccessibility(double precision, double *distanceFromBoundary=nullptr) const
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal ...
static std::unique_ptr< QgsMultiPolygon > fromMultiPolygonXY(const QgsMultiPolygonXY &multipoly)
Construct geometry from a multipolygon.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QgsGeometry()
Constructor.
Java-style iterator for const traversal of parts of a geometry.
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,...
OperationResult addRing(const QVector< QgsPointXY > &ring)
Adds a new ring to this geometry.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
@ MethodNotImplemented
Method not implemented in geometry engine.
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
OperationResult reshapeGeometry(const QgsLineString &reshapeLineString)
Replaces a part of this geometry with another line.
double area(QString *errorMsg=nullptr) const override
const double * yData() const
Returns a const pointer to the y vertex data.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
QPointF toQPointF() const
Converts a point to a QPointF.
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
EndCapStyle
End cap styles for buffers.
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...
OperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
QgsGeometry minimalEnclosingCircle(QgsPointXY ¢er, double &radius, unsigned int segments=36) const
Returns the minimal enclosing circle for the geometry.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
Type
The WKB type describes the number of dimensions a geometry has.
QgsGeometry & operator=(QgsGeometry const &rhs)
Creates a deep copy of the object.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
OperationResult
Success or failure of a geometry operation.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
QgsAbstractGeometry * buffer(double distance, int segments, QString *errorMsg=nullptr) const override
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...
Line string geometry type, with support for z-dimension and m-values.
bool overlaps(const QgsGeometry &geometry) const
Returns true if the geometry overlaps another geometry.
QVector< QgsGeometry > coerceToType(QgsWkbTypes::Type type) const
Attempts to coerce this geometry into the specified destination type.
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...
QgsPointXY closestVertex(const QgsPointXY &point, int &atVertex, int &beforeVertex, int &afterVertex, double &sqrDist) const
Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap ...
bool deletePart(int partNum)
Deletes part identified by the part number.
QgsMultiPolylineXY asMultiPolyline() const
Returns the contents of the geometry as a multi-linestring.
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
double hausdorffDistance(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const
Returns the Hausdorff distance between this geometry and geom.
const double * xData() const
Returns a const pointer to the x vertex data.
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
double distanceToVertex(int vertex) const
Returns the distance along this geometry from its first vertex to the specified vertex.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
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 bool deleteRing(QgsAbstractGeometry *geom, int ringNum, int partNum=0)
Deletes a ring from a geometry.
QgsGeometry nearestPoint(const QgsGeometry &other) const
Returns the nearest point on this geometry to another geometry.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
static Q_DECL_DEPRECATED QgsPolylineXY createPolylineFromQPolygonF(const QPolygonF &polygon)
Creates a QgsPolylineXY from a QPolygonF.
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.
bool isGeosEqual(const QgsGeometry &) const
Compares the geometry with another geometry using GEOS.
bool deleteRing(int ringNum, int partNum=0)
Deletes a ring in polygon or multipolygon.
static QVector< QgsPointXY > randomPointsInPolygon(const QgsGeometry &polygon, int count, const std::function< bool(const QgsPointXY &) > &acceptPoint, unsigned long seed=0, QgsFeedback *feedback=nullptr)
Returns a list of count random points generated inside a polygon geometry.
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negative values mean left ...
#define Q_NOWARN_DEPRECATED_POP
QgsGeometryCollection * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
bool hasWhere() const
true if the location available from
double radius() const
Returns the radius of the circle.
QgsGeometry poleOfInaccessibility(double precision, double *distanceToBoundary=nullptr) const
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal ...
QgsPolygonXY asPolygon() const
Returns the contents of the geometry as a polygon.
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
QgsLineString * clone() const override
Clones the geometry by performing a deep copy.
int partCount() const override
Returns count of parts contained in the geometry.
@ NodedGeometryError
Error occurred while creating a noded geometry.
Circular string geometry type.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
@ InvalidBaseGeometry
The geometry on which the operation occurs is not valid.
static std::unique_ptr< QgsMultiLineString > fromMultiPolylineXY(const QgsMultiPolylineXY &multiline)
Construct geometry from a multipolyline.
static std::unique_ptr< QgsGeometryCollection > createCollectionOfType(QgsWkbTypes::Type type)
Returns a new geometry collection matching a specified WKB type.
static QgsGeometry fromMultiPointXY(const QgsMultiPointXY &multipoint)
Creates a new geometry from a QgsMultiPointXY object.
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 std::unique_ptr< QgsAbstractGeometry > avoidIntersections(const QgsAbstractGeometry &geom, const QList< QgsVectorLayer * > &avoidIntersectionsLayers, 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 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...
QgsGeometry convertToCurves(double distanceTolerance, double angleTolerance) const
Attempts to convert a non-curved geometry into a curved geometry type (e.g.
QString what() const
A human readable error message containing details about the error.
double sqrDistToVertexAt(QgsPointXY &point SIP_IN, int atVertex) const
Returns the squared Cartesian distance between the given point to the given vertex index (vertex at t...
QgsGeometry offsetCurve(double distance, int segments, JoinStyle joinStyle, double miterLimit) const
Returns an offset line at a given distance and side from an input line.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
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.
QgsPointXY where() const
The coordinates at which the error is located and should be visualized.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setX(double x)
Sets the point's x-coordinate.
bool convertToSingleType()
Converts multi type geometry into single type geometry e.g.
bool equals(const QgsGeometry &geometry) const
Test if this geometry is exactly equal to another geometry.
@ FlagAllowSelfTouchingHoles
Indicates that self-touching holes are permitted. OGC validity states that self-touching holes are NO...
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
QgsGeometry variableWidthBufferByM(int segments) const
Calculates a variable width buffer for a (multi)linestring geometry, where the width at each node is ...
QgsGeometry taperedBuffer(double startWidth, double endWidth, int segments) const
Calculates a variable width buffer ("tapered buffer") for a (multi)curve geometry.
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,...
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
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 std::unique_ptr< QgsMultiPoint > fromMultiPointXY(const QgsMultiPointXY &multipoint)
Construct geometry from a multipoint.
@ ValidatorQgisInternal
Use internal QgsGeometryValidator method.
static QgsGeometry fromQPointF(QPointF point)
Construct geometry from a QPointF.
static QgsLineString * fromQPolygonF(const QPolygonF &polygon)
Returns a new linestring from a QPolygonF polygon input.
QgsGeometry convexHull() const
Returns the smallest convex polygon that contains all the points in the geometry.
bool deleteVertex(int atVertex)
Deletes the vertex at the given position number and item (first number is index 0)
void setY(double y)
Sets the y value of the point.
QMap< int, QVariant > QgsAttributeMap
QgsGeometry densifyByDistance(double distance) const
Densifies the geometry by adding regularly placed extra nodes inside each segment so that the maximum...
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QgsCircularString * toCircularString(bool oriented=false) const
Returns a circular string from the circle.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkt(const QString &text)
Construct geometry from a WKT string.
double length() const
Returns the planar, 2-dimensional length of geometry.
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsGeometry extrude(double x, double y)
Returns an extruded version of this geometry.
bool crosses(const QgsGeometry &geometry) const
Returns true if the geometry crosses another geometry.
Multi polygon geometry collection.
void draw(QPainter &p) const
Draws the geometry onto a QPainter.
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 clipped(const QgsRectangle &rectangle)
Clips the geometry using the specified rectangle.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
std::unique_ptr< QgsAbstractGeometry > geometry
QPolygonF asQPolygonF() const
Returns contents of the geometry as a QPolygonF.
Q_DECL_DEPRECATED OperationResult splitGeometry(const QVector< QgsPointXY > &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QVector< QgsPointXY > &topologyTestPoints, bool splitFeature=true)
Splits this geometry according to a given line.
QVector< QgsPointSequence > QgsRingSequence
QgsGeometry pointOnSurface() const
Returns a point guaranteed to lie on the surface of a geometry.
@ InvalidInputGeometryType
The input geometry (ring, part, split line, etc.) has not the correct geometry type.
bool touches(const QgsGeometry &geometry) const
Returns true if the geometry touches another geometry.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
Multi point geometry collection.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
static QgsPoint closestVertex(const QgsAbstractGeometry &geom, const QgsPoint &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point.
Abstract base class for all geometries.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsGeometry simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
std::unique_ptr< QgsAbstractGeometry > _qgis_lwgeom_make_valid(const QgsAbstractGeometry *lwgeom_in, QString &errorMessage)
Implementation of QgsGeometry::makeValid(). Not a public API.
static bool deletePart(QgsAbstractGeometry *geom, int partNum)
Deletes a part from a geometry.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
bool dropMValue() override
Drops any measure values which exist in the geometry.
double hausdorffDistance(const QgsGeometry &geom) const
Returns the Hausdorff distance between this geometry and geom.
virtual QgsRectangle boundingBox() const =0
Returns the minimal bounding box for the geometry.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
QgsGeometry densifyByDistance(double distance) const
Densifies the geometry by adding regularly placed extra nodes inside each segment so that the maximum...
static double distanceToVertex(const QgsAbstractGeometry &geom, QgsVertexId id)
Returns the distance along a geometry from its first vertex to the specified vertex.
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.
virtual json asJsonObject(int precision=17) const
Exports the geometry to a json object.
static QgsGeometry polygonize(const QVector< QgsGeometry > &geometries)
Creates a GeometryCollection geometry containing possible polygons formed from the constituent linewo...
bool requiresConversionToStraightSegments() const
Returns true if the geometry is a curved geometry type which requires conversion to display as straig...
@ NothingHappened
Nothing happened, without any error.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
double interpolateAngle(double distance) const
Returns the angle parallel to the linestring or polygon boundary at the specified distance along the ...
@ SplitCannotSplitPoint
Points cannot be split.
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygon.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
QgsGeometry makeValid() const
Attempts to make an invalid geometry valid without losing vertices.
BufferSide
Side of line to buffer.
static void convertPointList(const QVector< QgsPointXY > &input, QgsPointSequence &output)
Upgrades a point list from QgsPointXY to QgsPoint.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
QgsGeometry shortestLine(const QgsGeometry &other) const
Returns the shortest line joining this geometry to another geometry.
QVector< QgsPoint > QgsPointSequence
double length(QString *errorMsg=nullptr) const override
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
Java-style iterator for traversal of parts of a geometry.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
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.
static QgsGeometry::OperationResult addPart(QgsAbstractGeometry *geometry, std::unique_ptr< QgsAbstractGeometry > part)
Add a part to multi type geometry.
QgsGeometry singleSidedBuffer(double distance, int segments, BufferSide side, JoinStyle joinStyle=JoinStyleRound, double miterLimit=2.0) const
Returns a single sided buffer for a (multi)line geometry.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
@ Success
Operation succeeded.
OperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
Utility class for identifying a unique vertex within a geometry.
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...
QgsGeometry forceRHR() const
Forces geometries to respect the Right-Hand-Rule, in which the area that is bounded by a polygon is t...
double height() const
Returns the height of the rectangle.
QgsGeometry convertToType(QgsWkbTypes::GeometryType destType, bool destMultipart=false) const
Try to convert the geometry to the requested type.
static QgsCircle from2Points(const QgsPoint &pt1, const QgsPoint &pt2)
Constructs a circle by 2 points on the circle.
double closestVertexWithContext(const QgsPointXY &point, int &atVertex) const
Searches for the closest vertex in this geometry to the given point.
int vertexNrFromVertexId(QgsVertexId id) const
Returns the vertex number corresponding to a vertex id.
void mapToPixel(const QgsMapToPixel &mtp)
Transforms the geometry from map units to pixels in place.
QgsGeometry makeDifference(const QgsGeometry &other) const
Returns the geometry formed by modifying this geometry such that it does not intersect the other geom...
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsPolylineXY asPolyline() const
Returns the contents of the geometry as a polyline.
QgsVertexIterator vertices() const
Returns a read-only, Java-style iterator for traversal of vertices of all the geometry,...
bool isMeasure() const
Returns true if the geometry contains m values.
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
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.
QgsMultiPointXY asMultiPoint() const
Returns the contents of the geometry as a multi-point.
bool isSimple() const
Determines whether the geometry is simple (according to OGC definition), i.e.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
QPointF asQPointF() const
Returns contents of the geometry as a QPointF if wkbType is WKBPoint, otherwise returns a null QPoint...
static QgsGeometry createWedgeBuffer(const QgsPoint ¢er, double azimuth, double angularWidth, double outerRadius, double innerRadius=0)
Creates a wedge shaped buffer from a center point.
EngineOperationResult
Success or failure of a geometry operation.
ValidationMethod
Available methods for validating geometries.
Java-style iterator for traversal of vertices of a geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
virtual QgsPolygon * toPolygon(unsigned int segments=36) const
Returns a segmented polygon.
bool vertexIdFromVertexNr(int number, QgsVertexId &id) const
Calculates the vertex ID from a vertex number.
void setX(double x)
Sets the x value of the point.
JoinStyle
Join styles for buffers.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
QgsGeometry symDifference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other.
bool contains(const QgsPointXY *p) const
Returns true if the geometry contains the point p.
virtual int numPoints() const =0
Returns the number of points in the curve.
static QgsCircle minimalCircleFrom3Points(const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double epsilon=1E-8)
Constructs the smallest circle from 3 points.
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
QgsAbstractGeometry::part_iterator parts_begin()
Returns STL-style iterator pointing to the first part of the geometry.
bool isGeosValid(QgsGeometry::ValidityFlags flags=QgsGeometry::ValidityFlags()) const
Checks validity of the geometry using GEOS.
void adjacentVertices(int atVertex, int &beforeVertex, int &afterVertex) const
Returns the indexes of the vertices before and after the given vertex index.
QgsCurve * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
Orientation
Curve orientation.
QgsWkbTypes::GeometryType type
#define Q_NOWARN_DEPRECATED_PUSH
static void validateGeometry(const QgsGeometry &geometry, QVector< QgsGeometry::Error > &errors, QgsGeometry::ValidationMethod method=QgsGeometry::ValidatorQgisInternal)
Validate geometry and produce a list of geometry errors.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkbType(QgsWkbTypes::Type t)
Returns empty geometry from wkb type.
Contains geometry relation and modification algorithms.
bool isEmpty() const
Returns true if the rectangle is empty.
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)=0
Transforms the geometry using a coordinate transform.
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)
double area() const
Returns the planar, 2-dimensional area of the geometry.
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.
virtual int ringCount(int part=0) const =0
Returns the number of rings of which this geometry is built.
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 bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
QVector< QgsPointXY > randomPointsInPolygon(int count, const std::function< bool(const QgsPointXY &) > &acceptPoint, unsigned long seed=0, QgsFeedback *feedback=nullptr) const
Returns a list of count random points generated inside a (multi)polygon geometry.
double width() const
Returns the width of the rectangle.
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other.
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.
bool boundingBoxIntersects(const QgsRectangle &rectangle) const
Returns true if the bounding box of this geometry intersects with a rectangle.
static std::unique_ptr< QgsAbstractGeometry > fromPolylineXY(const QgsPolylineXY &polyline)
Construct geometry from a polyline.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
static Type flatType(Type type)
Returns the flat type for a WKB type.
QgsGeometry delaunayTriangulation(double tolerance=0.0, bool edgesOnly=false) const
Returns the Delaunay triangulation for the vertices of the geometry.
static QgsGeometry fromMultiPolygonXY(const QgsMultiPolygonXY &multipoly)
Creates a new geometry from a QgsMultiPolygon.
QgsGeometry taperedBuffer(double startWidth, double endWidth, int segments) const
Calculates a tapered width buffer for a (multi)curve geometry.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
double closestSegmentWithContext(const QgsPointXY &point, QgsPointXY &minDistPoint, int &afterVertex, int *leftOf=nullptr, double epsilon=DEFAULT_SEGMENT_EPSILON) const
Searches for the closest segment of geometry to the given point.
QgsGeometryConstPartIterator constParts() const
Returns Java-style iterator for traversal of parts of the geometry.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
QgsGeometry orientedMinimumBoundingBox() const
Returns the oriented minimum bounding box for the geometry, which is the smallest (by area) rotated r...
QgsMultiPolygonXY asMultiPolygon() const
Returns the contents of the geometry as a multi-polygon.
@ GeometryEngineError
Geometry engine misses a method implemented or an error occurred in the geometry engine.
QgsAbstractGeometry::part_iterator parts_end()
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
static std::unique_ptr< QgsAbstractGeometry > fromPointXY(const QgsPointXY &point)
Construct geometry from a point.
double lineLocatePoint(const QgsGeometry &point) const
Returns a distance representing the location along this linestring of the closest point on this lines...
bool disjoint(const QgsGeometry &geometry) const
Returns true if the geometry is disjoint of another geometry.
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.