20#include <nlohmann/json.hpp>
30using namespace Qt::StringLiterals;
56 auto result = std::make_unique< QgsPolygon >();
58 return result.release();
109 for (
int i = 0; i < nRings; ++i )
111 auto line = std::make_unique<QgsLineString>();
112 line->fromWkbPoints( ringType, wkbPtr );
133 int binarySize =
sizeof( char ) +
sizeof( quint32 ) +
sizeof( quint32 );
142 binarySize +=
sizeof( quint32 ) + curve->numPoints() * ( 2 + curve->is3D() + curve->isMeasure() ) *
sizeof( double );
176 wkb << static_cast<quint32>( type );
188 curve->points( pts );
210 childWkt = childWkt.mid( childWkt.indexOf(
'(' ) );
212 wkt += childWkt +
',';
216 if ( !curve->isEmpty() )
221 std::unique_ptr<QgsLineString> line( curve->curveToLine() );
222 childWkt = line->asWkt( precision );
226 childWkt = curve->asWkt( precision );
229 childWkt = childWkt.mid( childWkt.indexOf(
'(' ) );
230 wkt += childWkt +
',';
233 if ( wkt.endsWith(
',' ) )
256 if ( lineString && !lineString->
isClosed() )
289 if ( lineString && !lineString->
isClosed() )
321 multiLine->
reserve( nInteriorRings + 1 );
323 for (
int i = 0; i < nInteriorRings; ++i )
334 return std::numeric_limits< double >::quiet_NaN();
337 double minimumDistance = std::numeric_limits<double>::max();
338 double minDistX = 0.0;
339 double minDistY = 0.0;
342 for (
int ringIndex = 0; ringIndex < numRings; ++ringIndex )
347 for (
int i = 0, j = len - 1; i < len; j = i++ )
349 double aX = ring->
xAt( i );
350 double aY = ring->
yAt( i );
351 double bX = ring->
xAt( j );
352 double bY = ring->
yAt( j );
354 if ( ( ( aY > y ) != ( bY > y ) ) && ( x < ( bX - aX ) * ( y - aY ) / ( bY - aY ) + aX ) )
357 minimumDistance = std::min( minimumDistance,
QgsGeometryUtilsBase::sqrDistToLine( x, y, aX, aY, bX, bY, minDistX, minDistY, 4 * std::numeric_limits<double>::epsilon() ) );
361 return ( inside ? 1 : -1 ) * std::sqrt( minimumDistance );
376 for (
int i = 0; i < nInteriorRings; ++i )
387 json coordinates = json::array();
390 std::unique_ptr< QgsLineString > exteriorLineString(
exteriorRing()->curveToLine() );
392 exteriorLineString->points( exteriorPts );
395 std::unique_ptr< QgsLineString > interiorLineString;
398 interiorLineString.reset(
interiorRing( i )->curveToLine() );
400 interiorLineString->points( interiorPts );
404 return { {
"type",
"Polygon" }, {
"coordinates", coordinates } };
GeoJsonProfile
GeoJson export Profile according to OGC Features and Geometries JSON - Part 1: Core https://docs....
WkbType
The WKB type describes the number of dimensions a geometry has.
@ LineString25D
LineString25D.
@ LineStringM
LineStringM.
@ LineStringZM
LineStringZM.
@ LineStringZ
LineStringZ.
virtual bool convertTo(Qgis::WkbType type)
Converts the geometry to a specified type.
QFlags< WkbFlag > WkbFlags
QString wktTypeStr() const
Returns the WKT type string of the geometry.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, Qgis::WkbType baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
@ FlagExportTrianglesAsPolygons
Triangles should be exported as polygon geometries.
QgsAbstractGeometry()=default
static endian_t endian()
Returns whether this machine uses big or little endian.
Qgis::WkbType readHeader() const
readHeader
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.
bool isEmpty() const override
Returns true if the geometry is empty.
QVector< QgsCurve * > mInteriorRings
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
void clear() override
Clears the geometry, ie reset it to a null geometry.
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).
std::unique_ptr< QgsCurve > mExteriorRing
Abstract base class for curved geometry type.
QgsCurve * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
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.
void reserve(int size)
Attempts to allocate memory for at least size geometries.
static double sqrDistToLine(double ptX, double ptY, double x1, double y1, double x2, double y2, double &minDistX, double &minDistY, double epsilon)
Returns the squared distance between a point and a line.
static void pointsToWKB(QgsWkbPtr &wkb, const QgsPointSequence &points, bool is3D, bool isMeasure, QgsAbstractGeometry::WkbFlags flags)
Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }.
static json pointsToJson(const QgsPointSequence &points, int precision, Qgis::GeoJsonProfile profile)
Returns coordinates as json object.
Line string geometry type, with support for z-dimension and m-values.
bool isClosed() const override
Returns true if the curve is closed.
void close()
Closes the line string by appending the first point to the end of the line, if it is not already clos...
Multi line string geometry collection.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
QgsCurvePolygon * toCurveType() const override
Returns the geometry converted to the more generic curve type QgsCurvePolygon.
json asJsonObject(int precision=17, Qgis::GeoJsonProfile profile=Qgis::GeoJsonProfile::Legacy) const override
Returns a json object representation of the geometry with the given precision and profile.
void setExteriorRing(QgsCurve *ring) override
Sets the exterior ring of the polygon.
void addInteriorRing(QgsCurve *ring) override
Adds an interior ring to the geometry (takes ownership).
int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns the length of the QByteArray returned by asWkb().
QByteArray asWkb(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns a WKB representation of the geometry.
QgsPolygon * clone() const override
Clones the geometry by performing a deep copy.
void clear() override
Clears the geometry, ie reset it to a null geometry.
QString geometryType() const override
Returns a unique string representing the geometry type.
double pointDistanceToBoundary(double x, double y) const
Returns the distance from a point to the boundary of the polygon (either the exterior ring or any clo...
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
friend class QgsCurvePolygon
QgsPolygon()
Constructor for an empty polygon geometry.
QgsPolygon * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
QgsPolygon * surfaceToPolygon() const override
Gets a polygon representation of this surface.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
double yAt(int index) const override
Returns the y-coordinate of the specified node in the line string.
int numPoints() const override
Returns the number of points in the curve.
double xAt(int index) const override
Returns the x-coordinate of the specified node in the line string.
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QVector< QgsPoint > QgsPointSequence