21 #include <QDomDocument>
27 #if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
28 #define GEOSGeometry struct GEOSGeom_t
29 #define GEOSCoordSequence struct GEOSCoordSeq_t
113 void fromGeos( GEOSGeometry* geos );
118 void fromWkb(
unsigned char * wkb,
size_t length );
124 const unsigned char* asWkb()
const;
129 size_t wkbSize()
const;
135 const GEOSGeometry* asGeos()
const;
177 QgsPoint closestVertex(
const QgsPoint& point,
int& atVertex,
int& beforeVertex,
int& afterVertex,
double& sqrDist );
191 void adjacentVertices(
int atVertex,
int& beforeVertex,
int& afterVertex );
204 bool insertVertex(
double x,
double y,
int beforeVertex );
212 bool moveVertex(
double x,
double y,
int atVertex );
224 bool deleteVertex(
int atVertex );
238 double sqrDistToVertexAt(
QgsPoint& point,
int atVertex );
246 double closestVertexWithContext(
const QgsPoint& point,
int& atVertex );
263 int addRing(
const QList<QgsPoint>& ring );
275 int addPart( GEOSGeometry *newPart );
286 int translate(
double dx,
double dy );
299 int splitGeometry(
const QList<QgsPoint>& splitLine,
300 QList<QgsGeometry*>&newGeometries,
302 QList<QgsPoint> &topologyTestPoints );
307 int reshapeGeometry(
const QList<QgsPoint>& reshapeWithLine );
321 bool intersects(
const QgsGeometry* geometry )
const;
324 bool contains(
const QgsPoint* p )
const;
328 bool contains(
const QgsGeometry* geometry )
const;
332 bool disjoint(
const QgsGeometry* geometry )
const;
344 bool overlaps(
const QgsGeometry* geometry )
const;
356 QgsGeometry* buffer(
double distance,
int segments );
391 QString exportToWkt()
const;
398 QString exportToGeoJSON()
const;
428 QList<QgsGeometry*> asGeometryCollection()
const;
434 bool deleteRing(
int ringNum,
int partNum = 0 );
439 bool deletePart(
int partNum );
444 bool convertToMultiType();
462 Error() : message(
"none" ), hasLocation( false ) {}
463 Error( QString m ) : message( m ), hasLocation( false ) {}
464 Error( QString m,
QgsPoint p ) : message( m ), location( p ), hasLocation( true ) {}
466 QString
what() {
return message; };
475 void validateGeometry( QList<Error> &errors );
508 bool exportWkbToGeos()
const;
513 bool exportGeosToWkb()
const;
528 bool insertVertex(
double x,
double y,
530 const GEOSCoordSequence* old_sequence,
531 GEOSCoordSequence** new_sequence );
538 void translateVertex(
QgsWkbPtr &wkbPtr,
double dx,
double dy,
bool hasZValue );
552 int splitLinearGeometry( GEOSGeometry *splitLine, QList<QgsGeometry*>& newGeometries );
555 int splitPolygonGeometry( GEOSGeometry *splitLine, QList<QgsGeometry*>& newGeometries );
558 int topologicalTestPointsSplit(
const GEOSGeometry* splitLine, QList<QgsPoint>& testPoints )
const;
565 static GEOSGeometry* reshapeLine(
const GEOSGeometry* origLine,
const GEOSGeometry* reshapeLineGeos );
572 static GEOSGeometry* reshapePolygon(
const GEOSGeometry* polygon,
const GEOSGeometry* reshapeLineGeos );
576 static GEOSGeometry* nodeGeometries(
const GEOSGeometry *splitLine,
const GEOSGeometry *poly );
580 static int lineContainedInLine(
const GEOSGeometry* line1,
const GEOSGeometry* line2 );
586 static int pointContainedInLine(
const GEOSGeometry* point,
const GEOSGeometry* line );
589 static bool geomInDegrees(
const GEOSGeometry* geom );
592 int numberOfGeometries( GEOSGeometry* g )
const;
594 int mergeGeometriesMultiTypeSplit( QVector<GEOSGeometry*>& splitResult );
605 static bool geosRelOp(
char( *op )(
const GEOSGeometry*,
const GEOSGeometry * ),
609 double leftOf(
double x,
double y,
double& x1,
double& y1,
double& x2,
double& y2 );
611 static inline bool moveVertex(
QgsWkbPtr &wkbPtr,
const double &x,
const double &y,
int atVertex,
bool hasZValue,
int &pointIndex,
bool isRing );
612 static inline bool deleteVertex(
QgsConstWkbPtr &srcPtr,
QgsWkbPtr &dstPtr,
int atVertex,
bool hasZValue,
int &pointIndex,
bool isRing,
bool lastItem );
613 static inline bool insertVertex(
QgsConstWkbPtr &srcPtr,
QgsWkbPtr &dstPtr,
int beforeVertex,
const double &x,
const double &y,
bool hasZValue,
int &pointIndex,
bool isRing );
620 mutable unsigned char *
mP;
625 inline const QgsWkbPtr &
operator>>(
double &v )
const { memcpy( &v, mP,
sizeof( v ) ); mP +=
sizeof( v );
return *
this; }
626 inline const QgsWkbPtr &
operator>>(
int &v )
const { memcpy( &v, mP,
sizeof( v ) ); mP +=
sizeof( v );
return *
this; }
627 inline const QgsWkbPtr &
operator>>(
unsigned int &v )
const { memcpy( &v, mP,
sizeof( v ) ); mP +=
sizeof( v );
return *
this; }
628 inline const QgsWkbPtr &
operator>>(
char &v )
const { memcpy( &v, mP,
sizeof( v ) ); mP +=
sizeof( v );
return *
this; }
631 inline QgsWkbPtr &
operator<<(
const double &v ) { memcpy( mP, &v,
sizeof( v ) ); mP +=
sizeof( v );
return *
this; }
632 inline QgsWkbPtr &
operator<<(
const int &v ) { memcpy( mP, &v,
sizeof( v ) ); mP +=
sizeof( v );
return *
this; }
633 inline QgsWkbPtr &
operator<<(
const unsigned int &v ) { memcpy( mP, &v,
sizeof( v ) ); mP +=
sizeof( v );
return *
this; }
634 inline QgsWkbPtr &
operator<<(
const char &v ) { memcpy( mP, &v,
sizeof( v ) ); mP +=
sizeof( v );
return *
this; }
639 inline operator unsigned char *()
const {
return mP; }
644 mutable unsigned char *
mP;
651 inline const QgsConstWkbPtr &
operator>>(
unsigned int &v )
const { memcpy( &v, mP,
sizeof( v ) ); mP +=
sizeof( v );
return *
this; }
657 inline operator const unsigned char *()
const {
return mP; }