Skip to content
Permalink
Browse files
[FEATURE:] New geometry classes
  • Loading branch information
mhugent committed May 25, 2015
1 parent cec5bde commit 68fe5f579157e81faa79fcea9aa251ae73638c2d
Showing with 13,055 additions and 7,605 deletions.
  1. +1 −0 python/CMakeLists.txt
  2. +134 −0 python/core/conversions.sip
  3. +20 −1 python/core/core.sip
  4. +115 −0 python/core/geometry/qgsabstractgeometryv2.sip
  5. +55 −0 python/core/geometry/qgscircularstringv2.sip
  6. +61 −0 python/core/geometry/qgscompoundcurvev2.sip
  7. +62 −0 python/core/geometry/qgscurvepolygonv2.sip
  8. +26 −0 python/core/geometry/qgscurvev2.sip
  9. +95 −133 python/core/{ → geometry}/qgsgeometry.sip
  10. +52 −0 python/core/geometry/qgsgeometrycollectionv2.sip
  11. +40 −0 python/core/geometry/qgsgeometryengine.sip
  12. +42 −0 python/core/geometry/qgsgeos.sip
  13. +58 −0 python/core/geometry/qgslinestringv2.sip
  14. +23 −0 python/core/geometry/qgsmulticurvev2.sip
  15. +20 −0 python/core/geometry/qgsmultilinestringv2.sip
  16. +22 −0 python/core/geometry/qgsmultipointv2.sip
  17. +22 −0 python/core/geometry/qgsmultipolygonv2.sip
  18. +22 −0 python/core/geometry/qgsmultisurfacev2.sip
  19. +58 −0 python/core/geometry/qgspointv2.sip
  20. +22 −0 python/core/geometry/qgspolygonv2.sip
  21. +11 −0 python/core/geometry/qgssurfacev2.sip
  22. +93 −0 python/core/geometry/qgswkbtypes.sip
  23. +1 −0 src/analysis/CMakeLists.txt
  24. +1 −0 src/analysis/interpolation/qgsinterpolator.cpp
  25. +1 −0 src/analysis/interpolation/qgstininterpolator.cpp
  26. +1 −0 src/app/CMakeLists.txt
  27. +1 −0 src/browser/CMakeLists.txt
  28. +25 −2 src/core/CMakeLists.txt
  29. +200 −0 src/core/geometry/qgsabstractgeometryv2.cpp
  30. +142 −0 src/core/geometry/qgsabstractgeometryv2.h
  31. +934 −0 src/core/geometry/qgscircularstringv2.cpp
  32. +95 −0 src/core/geometry/qgscircularstringv2.h
  33. +567 −0 src/core/geometry/qgscompoundcurvev2.cpp
  34. +88 −0 src/core/geometry/qgscompoundcurvev2.h
  35. +634 −0 src/core/geometry/qgscurvepolygonv2.cpp
  36. +89 −0 src/core/geometry/qgscurvepolygonv2.h
  37. +81 −0 src/core/geometry/qgscurvev2.cpp
  38. +51 −0 src/core/geometry/qgscurvev2.h
  39. +2,212 −0 src/core/geometry/qgsgeometry.cpp
  40. +174 −278 src/core/{ → geometry}/qgsgeometry.h
  41. +448 −0 src/core/geometry/qgsgeometrycollectionv2.cpp
  42. +81 −0 src/core/geometry/qgsgeometrycollectionv2.h
  43. +261 −0 src/core/geometry/qgsgeometryeditutils.cpp
  44. +50 −0 src/core/geometry/qgsgeometryeditutils.h
  45. +72 −0 src/core/geometry/qgsgeometryengine.h
  46. +266 −0 src/core/geometry/qgsgeometryimport.cpp
  47. +62 −0 src/core/geometry/qgsgeometryimport.h
  48. +524 −0 src/core/geometry/qgsgeometryutils.cpp
  49. +143 −0 src/core/geometry/qgsgeometryutils.h
  50. +1,969 −0 src/core/geometry/qgsgeos.cpp
  51. +135 −0 src/core/geometry/qgsgeos.h
  52. +494 −0 src/core/geometry/qgslinestringv2.cpp
  53. +90 −0 src/core/geometry/qgslinestringv2.h
  54. +108 −0 src/core/geometry/qgsmulticurvev2.cpp
  55. +41 −0 src/core/geometry/qgsmulticurvev2.h
  56. +103 −0 src/core/geometry/qgsmultilinestringv2.cpp
  57. +41 −0 src/core/geometry/qgsmultilinestringv2.h
  58. +92 −0 src/core/geometry/qgsmultipointv2.cpp
  59. +41 −0 src/core/geometry/qgsmultipointv2.h
  60. +119 −0 src/core/geometry/qgsmultipolygonv2.cpp
  61. +41 −0 src/core/geometry/qgsmultipolygonv2.h
  62. +128 −0 src/core/geometry/qgsmultisurfacev2.cpp
  63. +41 −0 src/core/geometry/qgsmultisurfacev2.h
  64. +245 −0 src/core/geometry/qgspointv2.cpp
  65. +84 −0 src/core/geometry/qgspointv2.h
  66. +106 −0 src/core/geometry/qgspolygonv2.cpp
  67. +41 −0 src/core/geometry/qgspolygonv2.h
  68. +34 −0 src/core/geometry/qgssurfacev2.h
  69. +26 −0 src/core/geometry/qgswkbptr.cpp
  70. +65 −0 src/core/geometry/qgswkbptr.h
  71. +192 −0 src/core/geometry/qgswkbtypes.cpp
  72. +125 −0 src/core/geometry/qgswkbtypes.h
  73. +12 −0 src/core/qgsapplication.h
  74. +1 −0 src/core/qgsclipper.cpp
  75. +2 −43 src/core/qgsdatasourceuri.cpp
  76. +1 −0 src/core/qgsdistancearea.cpp
  77. +0 −6,800 src/core/qgsgeometry.cpp
  78. +19 −27 src/core/qgsmaptopixel.cpp
  79. +2 −0 src/core/qgsmaptopixel.h
  80. +1 −0 src/core/qgsogcutils.cpp
  81. +1 −0 src/core/qgspointlocator.cpp
  82. +1 −31 src/core/qgsvectorlayer.cpp
  83. +8 −1 src/core/symbology-ng/qgsrendererv2.cpp
  84. +1 −0 src/customwidgets/CMakeLists.txt
  85. +1 −0 src/gui/CMakeLists.txt
  86. +1 −0 src/plugins/coordinate_capture/CMakeLists.txt
  87. +1 −0 src/plugins/evis/CMakeLists.txt
  88. +1 −1 src/plugins/georeferencer/CMakeLists.txt
  89. +1 −1 src/plugins/globe/CMakeLists.txt
  90. +1 −0 src/plugins/gps_importer/CMakeLists.txt
  91. +1 −0 src/plugins/grass/CMakeLists.txt
  92. +1 −0 src/plugins/heatmap/CMakeLists.txt
  93. +1 −0 src/plugins/interpolation/CMakeLists.txt
  94. +1 −0 src/plugins/offline_editing/CMakeLists.txt
  95. +1 −1 src/plugins/oracle_raster/CMakeLists.txt
  96. +1 −1 src/plugins/plugin_template/CMakeLists.txt
  97. +1 −0 src/plugins/raster_terrain_analysis/CMakeLists.txt
  98. +1 −0 src/plugins/roadgraph/CMakeLists.txt
  99. +1 −0 src/plugins/spatialquery/CMakeLists.txt
  100. +1 −1 src/plugins/spit/CMakeLists.txt
  101. +1 −1 src/plugins/topology/CMakeLists.txt
  102. +1 −0 src/plugins/zonal_statistics/CMakeLists.txt
  103. +1 −0 src/providers/delimitedtext/CMakeLists.txt
  104. +1 −0 src/providers/gpx/CMakeLists.txt
  105. +1 −0 src/providers/grass/CMakeLists.txt
  106. +1 −0 src/providers/memory/CMakeLists.txt
  107. +1 −0 src/providers/mssql/CMakeLists.txt
  108. +1 −0 src/providers/ogr/CMakeLists.txt
  109. +1 −0 src/providers/oracle/CMakeLists.txt
  110. +1 −0 src/providers/postgres/CMakeLists.txt
  111. +3 −87 src/providers/postgres/qgspostgresconn.cpp
  112. +3 −2 src/providers/postgres/qgspostgresfeatureiterator.cpp
  113. +1 −0 src/providers/spatialite/CMakeLists.txt
  114. +1 −0 src/providers/wfs/CMakeLists.txt
  115. +1 −1 src/providers/wms/CMakeLists.txt
  116. +1 −0 src/server/CMakeLists.txt
  117. +1 −0 tests/bench/CMakeLists.txt
  118. +1 −0 tests/src/analysis/CMakeLists.txt
  119. +1 −0 tests/src/app/CMakeLists.txt
  120. +3 −0 tests/src/core/CMakeLists.txt
  121. +4 −4 tests/src/core/testqgsexpression.cpp
  122. +18 −18 tests/src/core/testqgsgeometry.cpp
  123. +22 −15 tests/src/core/testqgsgeometryimport.cpp
  124. +175 −0 tests/src/core/testqgsgeometryutils.cpp
  125. +1 −0 tests/src/gui/CMakeLists.txt
  126. +1 −0 tests/src/providers/CMakeLists.txt
  127. +121 −153 tests/src/python/test_qgsgeometry.py
  128. +1 −1 tests/src/python/test_qgsgeometry_avoid_intersections.py
  129. +2 −2 tests/src/python/test_qgsmemoryprovider.py
@@ -83,6 +83,7 @@ INCLUDE_DIRECTORIES(
../src/core/diagram
../src/core/effects
../src/core/dxf
../src/core/geometry
../src/core/gps
../src/core/layertree
../src/core/raster
@@ -265,6 +265,140 @@ template <TYPE>
};


%MappedType QList< QList<QgsPointV2> >
{
%TypeHeaderCode
#include <QList>
#include "qgspointv2.h"
%End

%ConvertFromTypeCode
// Create the list.
PyObject *l;

if ((l = PyList_New(sipCpp->size())) == NULL)
return NULL;

const sipMappedType* qlist_type = sipFindMappedType("QList<QgsPointV2>");

// Set the list elements.
for (int i = 0; i < sipCpp->size(); ++i)
{
QList<QgsPointV2>* t = new QList<QgsPointV2>(sipCpp->at(i));
PyObject *tobj;

if ((tobj = sipConvertFromMappedType(t, qlist_type, sipTransferObj)) == NULL)
{
Py_DECREF(l);
delete t;
return NULL;
}
PyList_SET_ITEM(l, i, tobj);
}

return l;
%End

%ConvertToTypeCode
const sipMappedType* qlist_type = sipFindMappedType("QList<QgsPointV2>");

// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PyList_Check(sipPy))
return 0;

for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
if (!sipCanConvertToMappedType(PyList_GET_ITEM(sipPy, i), qlist_type, SIP_NOT_NONE))
return 0;

return 1;
}


QList< QList<QgsPointV2> > *ql = new QList< QList<QgsPointV2> >;

for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
{
int state;
//TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(PyList_GET_ITEM(sipPy, i), sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
QList<QgsPointV2> * t = reinterpret_cast< QList<QgsPointV2> * >(sipConvertToMappedType(PyList_GET_ITEM(sipPy, i), qlist_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

if (*sipIsErr)
{
sipReleaseMappedType(t, qlist_type, state);
delete ql;
return 0;
}
ql->append(*t);
sipReleaseMappedType(t, qlist_type, state);
}

*sipCppPtr = ql;
return sipGetState(sipTransferObj);
%End
};

%MappedType QList< QList< QList<QgsPointV2> > >
{
%TypeHeaderCode
#include <QList>
#include "qgspointv2.h"
%End

%ConvertFromTypeCode
PyObject *l;
if ((l = PyList_New(sipCpp->size())) == NULL)
{
return NULL;
}
const sipMappedType* qlist_type = sipFindMappedType("QList<QList<QgsPointV2> >");
if(!qlist_type )
{
Py_DECREF(l); return NULL;
}

for (int i = 0; i < sipCpp->size(); ++i)
{
QList< QList<QgsPointV2> >* t = new QList<QList<QgsPointV2> >(sipCpp->at(i));
PyObject *tobj;
if ((tobj = sipConvertFromMappedType(t, qlist_type, sipTransferObj)) == NULL)
{
Py_DECREF(l);
delete t;
return NULL;
}
PyList_SET_ITEM(l, i, tobj);
}
return l;
%End
%ConvertToTypeCode
const sipMappedType* qlist_type = sipFindMappedType("QList<QList<QgsPointV2> >");
if (sipIsErr == NULL)
{
return 0;
}
QList< QList< QList<QgsPointV2> > >* ql = new QList< QList< QList<QgsPointV2> > >();
for( int i = 0;i < PyList_GET_SIZE(sipPy); ++i)
{
int state;
QList<QList<QgsPointV2> > *t = reinterpret_cast< QList< QList<QgsPointV2> > * >(sipConvertToMappedType(PyList_GET_ITEM(sipPy, i), qlist_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
if( *sipIsErr )
{
sipReleaseMappedType(t, qlist_type, state);
delete ql;
return 0;
}
ql->append( *t );
sipReleaseMappedType( t, qlist_type, state );
}
*sipCppPtr = ql;
return sipGetState(sipTransferObj);


%End
};


%If (QSETINT_CONVERSION)
%MappedType QSet<int>
@@ -40,7 +40,6 @@
%Include qgsfeatureiterator.sip
%Include qgsfeaturerequest.sip
%Include qgsfield.sip
%Include qgsgeometry.sip
%Include qgsgeometryvalidator.sip
%Include qgsgeometrysimplifier.sip
%Include qgshistogram.sip
@@ -273,3 +272,23 @@
%Include symbology-ng/qgssymbologyv2conversion.sip

%Include dxf/qgsdxfexport.sip

%Include geometry/qgsgeometry.sip
%Include geometry/qgsabstractgeometryv2.sip
%Include geometry/qgscircularstringv2.sip
%Include geometry/qgscompoundcurvev2.sip
%Include geometry/qgscurvepolygonv2.sip
%Include geometry/qgscurvev2.sip
%Include geometry/qgsgeometrycollectionv2.sip
%Include geometry/qgsgeometryengine.sip
%Include geometry/qgsgeos.sip
%Include geometry/qgslinestringv2.sip
%Include geometry/qgsmulticurvev2.sip
%Include geometry/qgsmultilinestringv2.sip
%Include geometry/qgsmultipointv2.sip
%Include geometry/qgsmultipolygonv2.sip
%Include geometry/qgsmultisurfacev2.sip
%Include geometry/qgspointv2.sip
%Include geometry/qgspolygonv2.sip
%Include geometry/qgssurfacev2.sip
%Include geometry/qgswkbtypes.sip
@@ -0,0 +1,115 @@
struct QgsVertexId
{
%TypeHeaderCode
#include <qgsabstractgeometryv2.h>
%End

enum VertexType
{
SegmentVertex, //start / endpoint of a segment
CurveVertex
};

QgsVertexId();
QgsVertexId( int _part, int _ring, int _vertex, VertexType _type );

bool isValid() const;
int part;
int ring;
int vertex;
VertexType type;
};

class QgsAbstractGeometryV2
{
%TypeHeaderCode
#include <qgsabstractgeometryv2.h>
#include <qgslinestringv2.h>
%End

%ConvertToSubClassCode
if (dynamic_cast<QgsPointV2*>(sipCpp) != NULL)
sipClass = sipClass_QgsPointV2;
else if (dynamic_cast<QgsLineStringV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsLineStringV2;
else if (dynamic_cast<QgsCircularStringV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsCircularStringV2;
else if (dynamic_cast<QgsCompoundCurveV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsCompoundCurveV2;
else if (dynamic_cast<QgsPolygonV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsPolygonV2;
else if (dynamic_cast<QgsCurvePolygonV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsCurvePolygonV2;
else if (dynamic_cast<QgsMultiPointV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsMultiPointV2;
else if (dynamic_cast<QgsLineStringV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsLineStringV2;
else if (dynamic_cast<QgsMultiPolygonV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsMultiPolygonV2;
else if (dynamic_cast<QgsMultiSurfaceV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsMultiSurfaceV2;
else if (dynamic_cast<QgsMultiCurveV2*>(sipCpp) != NULL )
sipClass = sipClass_QgsMultiCurveV2;
else
sipClass = 0;
%End

public:

QgsAbstractGeometryV2();
virtual ~QgsAbstractGeometryV2();
QgsAbstractGeometryV2( const QgsAbstractGeometryV2& geom );
//virtual QgsAbstractGeometryV2& operator=( const QgsAbstractGeometryV2& geom );

virtual QgsAbstractGeometryV2* clone() const = 0;
virtual void clear() = 0;

QgsRectangle boundingBox() const;

//mm-sql interface
virtual int dimension() const = 0;
//virtual int coordDim() const { return mCoordDimension; }
virtual QString geometryType() const = 0;
QgsWKBTypes::Type wkbType() const;
QString wktTypeStr() const;
bool is3D() const;
bool isMeasure() const;

//import
virtual bool fromWkb( const unsigned char * wkb ) = 0;
virtual bool fromWkt( const QString& wkt ) = 0;

//export
virtual int wkbSize() const = 0;
virtual unsigned char* asWkb( int& binarySize ) const = 0;
virtual QString asWkt( int precision = 17 ) const = 0;
virtual QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
virtual QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
virtual QString asJSON( int precision = 17 ) const = 0;

virtual QgsRectangle calculateBoundingBox() const;

//render pipeline
virtual void transform( const QgsCoordinateTransform& ct ) = 0;
virtual void transform( const QTransform& t ) = 0;
virtual void clip( const QgsRectangle& rect );
virtual void draw( QPainter& p ) const = 0;

/**Returns next vertex id and coordinates
@return false if at end*/
virtual bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const = 0;

virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord /Out/ ) const = 0;
int nCoordinates() const;
QgsPointV2 vertexAt( const QgsVertexId& id ) const;
virtual double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const = 0;

//low-level editing
virtual bool insertVertex( const QgsVertexId& position, const QgsPointV2& vertex ) = 0;
virtual bool moveVertex( const QgsVertexId& position, const QgsPointV2& newPos ) = 0;
virtual bool deleteVertex( const QgsVertexId& position ) = 0;

/**Length for linear geometries,perimeter for area geometries*/
virtual double length() const;
virtual double area() const;
};
@@ -0,0 +1,55 @@
class QgsCircularStringV2: public QgsCurveV2
{
%TypeHeaderCode
#include <qgscircularstringv2.h>
%End

public:
QgsCircularStringV2();
~QgsCircularStringV2();

virtual QString geometryType() const;
virtual int dimension() const;
virtual QgsAbstractGeometryV2* clone() const;
virtual void clear();

virtual QgsRectangle calculateBoundingBox() const;

virtual bool fromWkb( const unsigned char * wkb );
virtual bool fromWkt( const QString& wkt );

int wkbSize() const;
unsigned char* asWkb( int& binarySize ) const;
QString asWkt( int precision = 17 ) const;
QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
QString asJSON( int precision = 17 ) const;

int numPoints() const;
QgsPointV2 pointN( int i ) const;
void points( QList<QgsPointV2>& pts ) const;
void setPoints( const QList<QgsPointV2>& points );


//curve interface
virtual double length() const;
virtual QgsPointV2 startPoint() const;
virtual QgsPointV2 endPoint() const;
virtual QgsLineStringV2* curveToLine() const;

void draw( QPainter& p ) const;
void transform( const QgsCoordinateTransform& ct );
void transform( const QTransform& t );
void clip( const QgsRectangle& rect );
void addToPainterPath( QPainterPath& path ) const;
void drawAsPolygon( QPainter& p ) const;

virtual bool insertVertex( const QgsVertexId& position, const QgsPointV2& vertex );
virtual bool moveVertex( const QgsVertexId& position, const QgsPointV2& newPos );
virtual bool deleteVertex( const QgsVertexId& position );

double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const;
bool pointAt( int i, QgsPointV2& vertex, QgsVertexId::VertexType& type ) const;

void sumUpArea( double& sum ) const;
};

0 comments on commit 68fe5f5

Please sign in to comment.