Skip to content

Commit 68fe5f5

Browse files
committed
[FEATURE:] New geometry classes
1 parent cec5bde commit 68fe5f5

File tree

129 files changed

+13055
-7605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+13055
-7605
lines changed

python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ INCLUDE_DIRECTORIES(
8383
../src/core/diagram
8484
../src/core/effects
8585
../src/core/dxf
86+
../src/core/geometry
8687
../src/core/gps
8788
../src/core/layertree
8889
../src/core/raster

python/core/conversions.sip

+134
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,140 @@ template <TYPE>
265265
};
266266

267267

268+
%MappedType QList< QList<QgsPointV2> >
269+
{
270+
%TypeHeaderCode
271+
#include <QList>
272+
#include "qgspointv2.h"
273+
%End
274+
275+
%ConvertFromTypeCode
276+
// Create the list.
277+
PyObject *l;
278+
279+
if ((l = PyList_New(sipCpp->size())) == NULL)
280+
return NULL;
281+
282+
const sipMappedType* qlist_type = sipFindMappedType("QList<QgsPointV2>");
283+
284+
// Set the list elements.
285+
for (int i = 0; i < sipCpp->size(); ++i)
286+
{
287+
QList<QgsPointV2>* t = new QList<QgsPointV2>(sipCpp->at(i));
288+
PyObject *tobj;
289+
290+
if ((tobj = sipConvertFromMappedType(t, qlist_type, sipTransferObj)) == NULL)
291+
{
292+
Py_DECREF(l);
293+
delete t;
294+
return NULL;
295+
}
296+
PyList_SET_ITEM(l, i, tobj);
297+
}
298+
299+
return l;
300+
%End
301+
302+
%ConvertToTypeCode
303+
const sipMappedType* qlist_type = sipFindMappedType("QList<QgsPointV2>");
304+
305+
// Check the type if that is all that is required.
306+
if (sipIsErr == NULL)
307+
{
308+
if (!PyList_Check(sipPy))
309+
return 0;
310+
311+
for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
312+
if (!sipCanConvertToMappedType(PyList_GET_ITEM(sipPy, i), qlist_type, SIP_NOT_NONE))
313+
return 0;
314+
315+
return 1;
316+
}
317+
318+
319+
QList< QList<QgsPointV2> > *ql = new QList< QList<QgsPointV2> >;
320+
321+
for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
322+
{
323+
int state;
324+
//TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(PyList_GET_ITEM(sipPy, i), sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
325+
QList<QgsPointV2> * t = reinterpret_cast< QList<QgsPointV2> * >(sipConvertToMappedType(PyList_GET_ITEM(sipPy, i), qlist_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
326+
327+
if (*sipIsErr)
328+
{
329+
sipReleaseMappedType(t, qlist_type, state);
330+
delete ql;
331+
return 0;
332+
}
333+
ql->append(*t);
334+
sipReleaseMappedType(t, qlist_type, state);
335+
}
336+
337+
*sipCppPtr = ql;
338+
return sipGetState(sipTransferObj);
339+
%End
340+
};
341+
342+
%MappedType QList< QList< QList<QgsPointV2> > >
343+
{
344+
%TypeHeaderCode
345+
#include <QList>
346+
#include "qgspointv2.h"
347+
%End
348+
349+
%ConvertFromTypeCode
350+
PyObject *l;
351+
if ((l = PyList_New(sipCpp->size())) == NULL)
352+
{
353+
return NULL;
354+
}
355+
const sipMappedType* qlist_type = sipFindMappedType("QList<QList<QgsPointV2> >");
356+
if(!qlist_type )
357+
{
358+
Py_DECREF(l); return NULL;
359+
}
360+
361+
for (int i = 0; i < sipCpp->size(); ++i)
362+
{
363+
QList< QList<QgsPointV2> >* t = new QList<QList<QgsPointV2> >(sipCpp->at(i));
364+
PyObject *tobj;
365+
if ((tobj = sipConvertFromMappedType(t, qlist_type, sipTransferObj)) == NULL)
366+
{
367+
Py_DECREF(l);
368+
delete t;
369+
return NULL;
370+
}
371+
PyList_SET_ITEM(l, i, tobj);
372+
}
373+
return l;
374+
%End
375+
%ConvertToTypeCode
376+
const sipMappedType* qlist_type = sipFindMappedType("QList<QList<QgsPointV2> >");
377+
if (sipIsErr == NULL)
378+
{
379+
return 0;
380+
}
381+
QList< QList< QList<QgsPointV2> > >* ql = new QList< QList< QList<QgsPointV2> > >();
382+
for( int i = 0;i < PyList_GET_SIZE(sipPy); ++i)
383+
{
384+
int state;
385+
QList<QList<QgsPointV2> > *t = reinterpret_cast< QList< QList<QgsPointV2> > * >(sipConvertToMappedType(PyList_GET_ITEM(sipPy, i), qlist_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
386+
if( *sipIsErr )
387+
{
388+
sipReleaseMappedType(t, qlist_type, state);
389+
delete ql;
390+
return 0;
391+
}
392+
ql->append( *t );
393+
sipReleaseMappedType( t, qlist_type, state );
394+
}
395+
*sipCppPtr = ql;
396+
return sipGetState(sipTransferObj);
397+
398+
399+
%End
400+
};
401+
268402

269403
%If (QSETINT_CONVERSION)
270404
%MappedType QSet<int>

python/core/core.sip

+20-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
%Include qgsfeatureiterator.sip
4141
%Include qgsfeaturerequest.sip
4242
%Include qgsfield.sip
43-
%Include qgsgeometry.sip
4443
%Include qgsgeometryvalidator.sip
4544
%Include qgsgeometrysimplifier.sip
4645
%Include qgshistogram.sip
@@ -273,3 +272,23 @@
273272
%Include symbology-ng/qgssymbologyv2conversion.sip
274273

275274
%Include dxf/qgsdxfexport.sip
275+
276+
%Include geometry/qgsgeometry.sip
277+
%Include geometry/qgsabstractgeometryv2.sip
278+
%Include geometry/qgscircularstringv2.sip
279+
%Include geometry/qgscompoundcurvev2.sip
280+
%Include geometry/qgscurvepolygonv2.sip
281+
%Include geometry/qgscurvev2.sip
282+
%Include geometry/qgsgeometrycollectionv2.sip
283+
%Include geometry/qgsgeometryengine.sip
284+
%Include geometry/qgsgeos.sip
285+
%Include geometry/qgslinestringv2.sip
286+
%Include geometry/qgsmulticurvev2.sip
287+
%Include geometry/qgsmultilinestringv2.sip
288+
%Include geometry/qgsmultipointv2.sip
289+
%Include geometry/qgsmultipolygonv2.sip
290+
%Include geometry/qgsmultisurfacev2.sip
291+
%Include geometry/qgspointv2.sip
292+
%Include geometry/qgspolygonv2.sip
293+
%Include geometry/qgssurfacev2.sip
294+
%Include geometry/qgswkbtypes.sip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
struct QgsVertexId
2+
{
3+
%TypeHeaderCode
4+
#include <qgsabstractgeometryv2.h>
5+
%End
6+
7+
enum VertexType
8+
{
9+
SegmentVertex, //start / endpoint of a segment
10+
CurveVertex
11+
};
12+
13+
QgsVertexId();
14+
QgsVertexId( int _part, int _ring, int _vertex, VertexType _type );
15+
16+
bool isValid() const;
17+
int part;
18+
int ring;
19+
int vertex;
20+
VertexType type;
21+
};
22+
23+
class QgsAbstractGeometryV2
24+
{
25+
%TypeHeaderCode
26+
#include <qgsabstractgeometryv2.h>
27+
#include <qgslinestringv2.h>
28+
%End
29+
30+
%ConvertToSubClassCode
31+
if (dynamic_cast<QgsPointV2*>(sipCpp) != NULL)
32+
sipClass = sipClass_QgsPointV2;
33+
else if (dynamic_cast<QgsLineStringV2*>(sipCpp) != NULL )
34+
sipClass = sipClass_QgsLineStringV2;
35+
else if (dynamic_cast<QgsCircularStringV2*>(sipCpp) != NULL )
36+
sipClass = sipClass_QgsCircularStringV2;
37+
else if (dynamic_cast<QgsCompoundCurveV2*>(sipCpp) != NULL )
38+
sipClass = sipClass_QgsCompoundCurveV2;
39+
else if (dynamic_cast<QgsPolygonV2*>(sipCpp) != NULL )
40+
sipClass = sipClass_QgsPolygonV2;
41+
else if (dynamic_cast<QgsCurvePolygonV2*>(sipCpp) != NULL )
42+
sipClass = sipClass_QgsCurvePolygonV2;
43+
else if (dynamic_cast<QgsMultiPointV2*>(sipCpp) != NULL )
44+
sipClass = sipClass_QgsMultiPointV2;
45+
else if (dynamic_cast<QgsLineStringV2*>(sipCpp) != NULL )
46+
sipClass = sipClass_QgsLineStringV2;
47+
else if (dynamic_cast<QgsMultiPolygonV2*>(sipCpp) != NULL )
48+
sipClass = sipClass_QgsMultiPolygonV2;
49+
else if (dynamic_cast<QgsMultiSurfaceV2*>(sipCpp) != NULL )
50+
sipClass = sipClass_QgsMultiSurfaceV2;
51+
else if (dynamic_cast<QgsMultiCurveV2*>(sipCpp) != NULL )
52+
sipClass = sipClass_QgsMultiCurveV2;
53+
else
54+
sipClass = 0;
55+
%End
56+
57+
public:
58+
59+
QgsAbstractGeometryV2();
60+
virtual ~QgsAbstractGeometryV2();
61+
QgsAbstractGeometryV2( const QgsAbstractGeometryV2& geom );
62+
//virtual QgsAbstractGeometryV2& operator=( const QgsAbstractGeometryV2& geom );
63+
64+
virtual QgsAbstractGeometryV2* clone() const = 0;
65+
virtual void clear() = 0;
66+
67+
QgsRectangle boundingBox() const;
68+
69+
//mm-sql interface
70+
virtual int dimension() const = 0;
71+
//virtual int coordDim() const { return mCoordDimension; }
72+
virtual QString geometryType() const = 0;
73+
QgsWKBTypes::Type wkbType() const;
74+
QString wktTypeStr() const;
75+
bool is3D() const;
76+
bool isMeasure() const;
77+
78+
//import
79+
virtual bool fromWkb( const unsigned char * wkb ) = 0;
80+
virtual bool fromWkt( const QString& wkt ) = 0;
81+
82+
//export
83+
virtual int wkbSize() const = 0;
84+
virtual unsigned char* asWkb( int& binarySize ) const = 0;
85+
virtual QString asWkt( int precision = 17 ) const = 0;
86+
virtual QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
87+
virtual QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
88+
virtual QString asJSON( int precision = 17 ) const = 0;
89+
90+
virtual QgsRectangle calculateBoundingBox() const;
91+
92+
//render pipeline
93+
virtual void transform( const QgsCoordinateTransform& ct ) = 0;
94+
virtual void transform( const QTransform& t ) = 0;
95+
virtual void clip( const QgsRectangle& rect );
96+
virtual void draw( QPainter& p ) const = 0;
97+
98+
/**Returns next vertex id and coordinates
99+
@return false if at end*/
100+
virtual bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const = 0;
101+
102+
virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord /Out/ ) const = 0;
103+
int nCoordinates() const;
104+
QgsPointV2 vertexAt( const QgsVertexId& id ) const;
105+
virtual double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const = 0;
106+
107+
//low-level editing
108+
virtual bool insertVertex( const QgsVertexId& position, const QgsPointV2& vertex ) = 0;
109+
virtual bool moveVertex( const QgsVertexId& position, const QgsPointV2& newPos ) = 0;
110+
virtual bool deleteVertex( const QgsVertexId& position ) = 0;
111+
112+
/**Length for linear geometries,perimeter for area geometries*/
113+
virtual double length() const;
114+
virtual double area() const;
115+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
class QgsCircularStringV2: public QgsCurveV2
2+
{
3+
%TypeHeaderCode
4+
#include <qgscircularstringv2.h>
5+
%End
6+
7+
public:
8+
QgsCircularStringV2();
9+
~QgsCircularStringV2();
10+
11+
virtual QString geometryType() const;
12+
virtual int dimension() const;
13+
virtual QgsAbstractGeometryV2* clone() const;
14+
virtual void clear();
15+
16+
virtual QgsRectangle calculateBoundingBox() const;
17+
18+
virtual bool fromWkb( const unsigned char * wkb );
19+
virtual bool fromWkt( const QString& wkt );
20+
21+
int wkbSize() const;
22+
unsigned char* asWkb( int& binarySize ) const;
23+
QString asWkt( int precision = 17 ) const;
24+
QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
25+
QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
26+
QString asJSON( int precision = 17 ) const;
27+
28+
int numPoints() const;
29+
QgsPointV2 pointN( int i ) const;
30+
void points( QList<QgsPointV2>& pts ) const;
31+
void setPoints( const QList<QgsPointV2>& points );
32+
33+
34+
//curve interface
35+
virtual double length() const;
36+
virtual QgsPointV2 startPoint() const;
37+
virtual QgsPointV2 endPoint() const;
38+
virtual QgsLineStringV2* curveToLine() const;
39+
40+
void draw( QPainter& p ) const;
41+
void transform( const QgsCoordinateTransform& ct );
42+
void transform( const QTransform& t );
43+
void clip( const QgsRectangle& rect );
44+
void addToPainterPath( QPainterPath& path ) const;
45+
void drawAsPolygon( QPainter& p ) const;
46+
47+
virtual bool insertVertex( const QgsVertexId& position, const QgsPointV2& vertex );
48+
virtual bool moveVertex( const QgsVertexId& position, const QgsPointV2& newPos );
49+
virtual bool deleteVertex( const QgsVertexId& position );
50+
51+
double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const;
52+
bool pointAt( int i, QgsPointV2& vertex, QgsVertexId::VertexType& type ) const;
53+
54+
void sumUpArea( double& sum ) const;
55+
};

0 commit comments

Comments
 (0)