25 #include <QPainterPath>
42 mCurves.
append( static_cast<QgsCurveV2*>( c->
clone() ) );
53 mCurves.
append( static_cast<QgsCurveV2*>( c->
clone() ) );
66 qDeleteAll( mCurves );
73 if ( mCurves.
size() < 1 )
79 for (
int i = 1; i < mCurves.
size(); ++i )
106 int currentCurveSize = 0;
107 for (
int i = 0; i <
nCurves; ++i )
112 wkbPtr -= ( 1 +
sizeof( int ) );
125 currentCurve->
fromWkb( wkbPtr );
126 currentCurveSize = currentCurve->
wkbSize();
127 mCurves.
append( currentCurve );
128 wkbPtr += currentCurveSize;
158 if ( !mCurves.
back()->fromWkt( childWkt ) )
169 int size =
sizeof( char ) +
sizeof( quint32 ) +
sizeof( quint32 );
180 unsigned char* geomPtr =
new unsigned char[binarySize];
183 wkb << static_cast<quint32>(
wkbType() );
184 wkb << static_cast<quint32>( mCurves.
size() );
188 unsigned char* curveWkb = curve->
asWkb( curveWkbLen );
189 memcpy( wkb, curveWkb, curveWkbLen );
202 if ( dynamic_cast<const QgsLineStringV2*>( curve ) )
205 childWkt = childWkt.
mid( childWkt.
indexOf(
"(" ) );
207 wkt += childWkt +
",";
234 if ( dynamic_cast<const QgsLineStringV2*>( curve ) )
243 else if ( dynamic_cast<const QgsCircularStringV2*>( curve ) )
270 for ( ; curveIt != mCurves.
constEnd(); ++curveIt )
272 length += ( *curveIt )->length();
279 if ( mCurves.
size() < 1 )
283 return mCurves.
at( 0 )->startPoint();
288 if ( mCurves.
size() < 1 )
298 if ( mCurves.
size() < 1 )
303 mCurves[0]->points( pts );
304 for (
int i = 1; i < mCurves.
size(); ++i )
307 mCurves[i]->points( pList );
317 for (
int i = 0; i <
nCurves; ++i )
319 nPoints += mCurves.
at( i )->numPoints() - 1;
330 for ( ; curveIt != mCurves.
constEnd(); ++curveIt )
333 line->
append( currentLine );
341 if ( i >= mCurves.
size() )
345 return mCurves.
at( i );
363 if ( mCurves.
size() - 1 < i )
368 delete( mCurves[i] );
381 if ( mCurves.
size() > 0 )
383 lastCurve = mCurves.
at( mCurves.
size() - 1 );
387 if ( !lastCurve || lastCurve->
geometryType() !=
"LineString" )
407 for ( ; it != mCurves.
constEnd(); ++it )
416 for ( ; it != mCurves.
end(); ++it )
418 ( *it )->transform( ct );
425 for ( ; it != mCurves.
end(); ++it )
427 ( *it )->transform( t );
435 for ( ; it != mCurves.
constEnd(); ++it )
437 ( *it )->addToPainterPath( pp );
446 for ( ; it != mCurves.
constEnd(); ++it )
448 ( *it )->addToPainterPath( pp );
456 if ( curveIds.
size() < 1 )
460 int curveId = curveIds.
at( 0 ).first;
461 if ( curveId >= mCurves.
size() )
465 return mCurves[curveId]->insertVertex( curveIds.
at( 0 ).second, vertex );
472 for ( ; idIt != curveIds.
constEnd(); ++idIt )
474 mCurves[idIt->
first]->moveVertex( idIt->second, newPos );
477 return curveIds.
size() > 0;
484 for ( ; idIt != curveIds.
constEnd(); ++idIt )
486 mCurves[idIt->
first]->deleteVertex( idIt->second );
488 return curveIds.
size() > 0;
495 int currentVertexIndex = 0;
496 for (
int i = 0; i < mCurves.
size(); ++i )
498 int increment = mCurves.
at( i )->numPoints() - 1;
499 if (
id.vertex >= currentVertexIndex &&
id.vertex <= currentVertexIndex + increment )
501 int curveVertexId =
id.vertex - currentVertexIndex;
503 curveIds.
append( qMakePair( i, vid ) );
504 if ( curveVertexId == increment && i < ( mCurves.
size() - 1 ) )
507 curveIds.
append( qMakePair( i + 1, vid ) );
510 currentVertexIndex += increment;
523 int currentVertexId = 0;
524 for (
int j = 0; j < mCurves.
size(); ++j )
526 int nCurvePoints = mCurves.
at( j )->numPoints();
527 if (( i - currentVertexId ) < nCurvePoints )
529 return ( mCurves.
at( j )->pointAt( i - currentVertexId, vertex, type ) );
531 currentVertexId += ( nCurvePoints - 1 );
539 for ( ; curveIt != mCurves.
constEnd(); ++curveIt )
541 ( *curveIt )->sumUpArea( sum );
557 for ( ; curveIt != mCurves.
constEnd(); ++curveIt )
559 if (( *curveIt )->hasCurvedSegments() )
void addPath(const QPainterPath &path)
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.
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
void transform(const QgsCoordinateTransform &ct) override
Transforms the geometry using a coordinate transform.
virtual QgsLineStringV2 * curveToLine() const override
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
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 (...
void close()
Appends first point if not already closed.
virtual QgsAbstractGeometryV2 & operator=(const QgsAbstractGeometryV2 &geom)
QDomNode appendChild(const QDomNode &newChild)
bool pointAt(int i, QgsPointV2 &vertex, QgsVertexId::VertexType &type) const override
Returns the point and vertex id of a point within the curve.
bool hasCurvedSegments() const override
Returns true if the geometry contains curved segments.
Circular string geometry type.
virtual void points(QList< QgsPointV2 > &pt) const =0
Returns a list of points within the curve.
virtual QgsPointV2 endPoint() const override
Returns the end point of the curve.
virtual bool deleteVertex(const QgsVertexId &position) override
Deletes a vertex within the geometry.
virtual QgsPointV2 startPoint() const override
Returns the starting point of the curve.
const T & at(int i) const
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
virtual bool insertVertex(const QgsVertexId &position, const QgsPointV2 &vertex) override
Inserts a vertex into the geometry.
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.
unsigned char * asWkb(int &binarySize) const override
Returns a WKB representation of the geometry.
static double closestSegmentFromComponents(T &container, componentType ctype, const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon)
virtual QgsRectangle calculateBoundingBox() const override
Calculates the minimal bounding box for the geometry.
void append(const QgsLineStringV2 *line)
void sumUpArea(double &sum) const override
Calculates the area of the curve.
QDomElement createElementNS(const QString &nsURI, const QString &qName)
void addToPainterPath(QPainterPath &path) const override
Adds a curve to a painter path.
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.
QgsCompoundCurveV2 & operator=(const QgsCompoundCurveV2 &curve)
void removeCurve(int i)
Removes a curve from the geometry.
virtual QgsLineStringV2 * curveToLine() const override
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
QgsWKBTypes::Type readHeader() const
static Type flatType(Type type)
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
void combineExtentWith(QgsRectangle *rect)
expand the rectangle so that covers both the original rectangle and the given rectangle ...
void append(const T &value)
Utility class for identifying a unique vertex within a geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
void drawAsPolygon(QPainter &p) const override
Draws the curve as a polygon on the specified QPainter.
Line string geometry type.
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
virtual QString geometryType() const override
Returns a unique string representing the geometry type.
void addVertex(const QgsPointV2 &pt)
Adds a vertex to the end of the geometry.
virtual bool fromWkb(const unsigned char *wkb)=0
Sets the geometry from a WKB string.
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry.
QgsWKBTypes::Type mWkbType
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
virtual unsigned char * asWkb(int &binarySize) const =0
Returns a WKB representation of the geometry.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
const QgsCurveV2 * curveAt(int i) const
Returns the curve at the specified index.
void setZMTypeFromSubGeometry(const QgsAbstractGeometryV2 *subggeom, QgsWKBTypes::Type baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry.
Compound curve geometry type.
static QDomElement pointsToGML3(const QList< QgsPointV2 > &points, QDomDocument &doc, int precision, const QString &ns, bool is3D)
Returns a gml::posList DOM element.
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
void addCurve(QgsCurveV2 *c)
Adds a curve to the geometr (takes ownership)
void addVertex(const QgsPointV2 &pt)
virtual QgsPointV2 endPoint() const =0
Returns the end point of the curve.
QString mid(int position, int n) const
void drawPath(const QPainterPath &path)
virtual bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
virtual bool moveVertex(const QgsVertexId &position, const QgsPointV2 &newPos) override
Moves a vertex within the geometry.
virtual bool isClosed() const
Returns true if the curve is closed.
int wkbSize() const override
Returns the size of the WKB representation of the geometry.
virtual void points(QList< QgsPointV2 > &pts) const override
Returns a list of points within the curve.
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
QgsRectangle mBoundingBox
virtual 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.
static Type parseType(const QString &wktStr)
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'.
virtual QgsAbstractGeometryV2 * clone() const override
Clones the geometry by performing a deep copy.
const_iterator constEnd() 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.
virtual bool fromWkb(const unsigned char *wkb) override
Sets the geometry from a WKB string.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
virtual int numPoints() const override
Returns the number of points in the curve.
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
virtual double length() const override
Returns the length (or perimeter for area geometries) of the geometry.
int nCurves() const
Returns the number of curves in the geometry.
virtual void clear() override
Clears the geometry, ie reset it to a null geometry.