27 #include <QPainterPath>
103 int currentCurveSize = 0;
104 for (
int i = 0; i < nRings; ++i )
109 wkbPtr -= ( 1 +
sizeof( int ) );
128 currentCurve->
fromWkb( wkbPtr );
129 currentCurveSize = currentCurve->
wkbSize();
138 wkbPtr += currentCurveSize;
190 hasZ = hasZ || curve->
is3D();
214 int size =
sizeof( char ) +
sizeof( quint32 ) +
sizeof( quint32 );
229 unsigned char* geomPtr =
new unsigned char[binarySize];
232 wkb << static_cast<quint32>(
wkbType() );
238 memcpy( wkb, ringWkb, curveWkbLen );
244 unsigned char* ringWkb = curve->
asWkb( curveWkbLen );
245 memcpy( wkb, ringWkb, curveWkbLen );
260 childWkt = childWkt.
mid( childWkt.
indexOf(
"(" ) );
262 wkt += childWkt +
",";
267 if ( dynamic_cast<const QgsLineStringV2*>( curve ) )
270 childWkt = childWkt.
mid( childWkt.
indexOf(
"(" ) );
272 wkt += childWkt +
",";
288 elemOuterBoundaryIs.
appendChild( exteriorLineString->
asGML2( doc, precision, ns ) );
289 delete exteriorLineString;
295 elemInnerBoundaryIs.
appendChild( interiorLineString->
asGML2( doc, precision, ns ) );
296 delete interiorLineString;
314 return elemCurvePolygon;
320 QString json =
"{\"type\": \"Polygon\", \"coordinates\": [";
324 exteriorLineString->
points( exteriorPts );
326 delete exteriorLineString;
332 interiorLineString->
points( interiorPts );
334 delete interiorLineString;
351 double totalArea = 0.0;
357 totalArea += qAbs( area );
364 if (( *ringIt )->isClosed() )
366 ( *ringIt )->sumUpArea( area );
367 totalArea -= qAbs( area );
380 perimeter += ( *ringIt )->length();
397 for (
int i = 0; i < n; ++i )
419 rings.
push_back(( *it )->curveToLine() );
502 ( *it )->addToPainterPath( path );
518 ( *it )->transform( ct, d );
532 ( *it )->transform( t );
545 coordinates.
append( ringCoords );
551 ( *it )->points( ringCoords );
552 coordinates.
append( ringCoords );
554 coord.append( coordinates );
622 else if ( vId.
vertex == n )
638 bool success = ring->
moveVertex( vId, newPos );
644 else if ( vId.
vertex == n - 1 )
686 else if ( vId.
vertex == n - 1 )
703 if (( *it )->hasCurvedSegments() )
bool removeInteriorRing(int nr)
Removes ring.
bool hasCurvedSegments() const override
Returns true if the geometry contains curved segments.
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
A rectangle specified with double values.
virtual bool deleteVertex(const QgsVertexId &position) override
Deletes a vertex within the geometry.
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
virtual bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
virtual double vertexAngle(const QgsVertexId &vertex) const =0
Returns approximate rotation angle for a vertex.
static QPair< QgsWKBTypes::Type, QString > wktReadBlock(const QString &wkt)
Parses a WKT block of the format "TYPE( contents )" and returns a pair of geometry type to contents (...
virtual bool moveVertex(const QgsVertexId &position, const QgsPointV2 &newPos) override
Moves a vertex within the geometry.
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
virtual QgsRectangle calculateBoundingBox() const override
Calculates the minimal bounding box for the geometry.
virtual QgsAbstractGeometryV2 & operator=(const QgsAbstractGeometryV2 &geom)
QDomNode appendChild(const QDomNode &newChild)
void addInteriorRing(QgsCurveV2 *ring)
Adds an interior ring to the geometry (takes ownership)
void push_back(const T &value)
void clear() override
Clears the geometry, ie reset it to a null geometry.
void points(QList< QgsPointV2 > &pt) const override
Returns a list of points within the curve.
virtual bool moveVertex(const QgsVertexId &position, const QgsPointV2 &newPos)=0
Moves a vertex within the geometry.
Circular string geometry type.
virtual double length() const
Returns the length of the geometry.
QgsPolygonV2 * surfaceToPolygon() const override
virtual void points(QList< QgsPointV2 > &pt) const =0
Returns a list of points within the curve.
virtual QgsPointV2 vertexAt(const QgsVertexId &id) const override
Returns the point corresponding to a specified vertex id.
const T & at(int i) const
static QString pointsToJSON(const QList< QgsPointV2 > &points, int precision)
Returns a geoJSON coordinates string.
QgsCurveV2 * exteriorRing() const
virtual void addToPainterPath(QPainterPath &path) const =0
Adds a curve to a painter path.
Abstract base class for all geometries.
static QStringList wktGetChildBlocks(const QString &wkt, const QString &defaultType="")
Parses a WKT string and returns of list of blocks contained in the WKT.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
static double closestSegmentFromComponents(T &container, componentType ctype, const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon)
QDomElement createElementNS(const QString &nsURI, const QString &qName)
static endian_t endian()
Returns whether this machine uses big or little endian.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
virtual int wkbSize() const =0
Returns the size of the WKB representation of the geometry.
virtual void coordinateSequence(QList< QList< QList< QgsPointV2 > > > &coord) const override
Retrieves the sequence of geometries, rings and nodes.
virtual bool insertVertex(const QgsVertexId &position, const QgsPointV2 &vertex)=0
Inserts a vertex into the geometry.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
virtual int numPoints() const =0
Returns the number of points in the curve.
QgsWKBTypes::Type readHeader() const
int wkbSize() const override
Returns the size of the WKB representation of the geometry.
static Type flatType(Type type)
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
void setInteriorRings(const QList< QgsCurveV2 * > &rings)
Sets all interior rings (takes ownership)
void append(const T &value)
virtual bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
virtual double perimeter() const override
Returns the perimeter of the geometry.
virtual QString geometryType() const override
Returns a unique string representing the geometry type.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
Utility class for identifying a unique vertex within a geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
Line string geometry type.
virtual QgsRectangle calculateBoundingBox() const
Calculates the minimal bounding box for the geometry.
virtual int vertexCount(int=0, int=0) const override
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
virtual bool fromWkb(const unsigned char *wkb)=0
Sets the geometry from a WKB string.
QgsWKBTypes::Type mWkbType
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
QgsCurvePolygonV2 & operator=(const QgsCurvePolygonV2 &p)
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
virtual unsigned char * asWkb(int &binarySize) const =0
Returns a WKB representation of the geometry.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
virtual QgsPolygonV2 * toPolygon() const
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform)=0
Transforms the geometry using a coordinate transform.
void setZMTypeFromSubGeometry(const QgsAbstractGeometryV2 *subggeom, QgsWKBTypes::Type baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform) override
Transforms the geometry using a coordinate transform.
virtual bool nextVertex(QgsVertexId &id, QgsPointV2 &vertex) const override
Returns next vertex id and coordinates.
virtual int vertexCount(int=0, int ring=0) const override
unsigned char * asWkb(int &binarySize) const override
Returns a WKB representation of the geometry.
virtual void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
virtual QgsCurvePolygonV2 * clone() const override
Clones the geometry by performing a deep copy.
double closestSegment(const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon) const override
Searches for the closest segment of the geometry to a given point.
Compound curve geometry type.
virtual bool fromWkb(const unsigned char *wkb) override
Sets the geometry from a WKB string.
virtual void sumUpArea(double &sum) const =0
Calculates the area of the curve.
bool nextVertex(QgsVertexId &id, QgsPointV2 &vertex) const override
Returns next vertex id and coordinates.
virtual bool deleteVertex(const QgsVertexId &position)=0
Deletes a vertex within the geometry.
QList< QgsCurveV2 * > mInteriorRings
virtual QgsLineStringV2 * curveToLine() const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry.
QString mid(int position, int n) const
void drawPath(const QPainterPath &path)
void setExteriorRing(QgsCurveV2 *ring)
Sets exterior ring (takes ownership)
QgsPointV2 pointOnSurface() const override
virtual bool isClosed() const
Returns true if the curve is closed.
virtual bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
virtual QgsPointV2 vertexAt(const QgsVertexId &id) const override
Returns the point corresponding to a specified vertex id.
QgsRectangle mBoundingBox
virtual void drawAsPolygon(QPainter &p) const =0
Draws the curve as a polygon on the specified QPainter.
static Type parseType(const QString &wktStr)
QgsAbstractGeometryV2 * segmentize() const override
Returns a version of the geometry without curves.
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'.
Curve polygon geometry type.
virtual bool insertVertex(const QgsVertexId &position, const QgsPointV2 &vertex) override
Inserts a vertex into the geometry.
const_iterator constEnd() const
int numInteriorRings() const
const_iterator constBegin() const
virtual QgsAbstractGeometryV2 * clone() const =0
Clones the geometry by performing a deep copy.
Abstract base class for curved geometry type.
double vertexAngle(const QgsVertexId &vertex) const override
Returns approximate rotation angle for a vertex.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
QgsCurveV2 * interiorRing(int i) const
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
virtual double area() const override
Returns the area of the geometry.
QgsCurveV2 * mExteriorRing