Skip to content
Permalink
Browse files
[FEATURE:] New geometry classes
  • Loading branch information
mhugent committed May 25, 2015
1 parent cec5bde commit 68fe5f579157e81faa79fcea9aa251ae73638c2d
Show file tree
Hide file tree
Showing 129 changed files with 13,055 additions and 7,605 deletions.
@@ -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.