Skip to content
Permalink
Browse files
add __repr__ for more geometry classes and add test
  • Loading branch information
3nids committed Jun 19, 2018
1 parent ac4f508 commit cc3e29bcc2fe0a768832693104d091ed10e145d6
Show file tree
Hide file tree
Showing 44 changed files with 191 additions and 3 deletions.
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgscircle.h
QgsCircle.__repr__ = lambda self: '<QgsPoint {}>'.format(self.toString())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgscircularstring.h
QgsCircularString.__repr__ = lambda self: '<QgsCircularString {}>'.format(self.asWkt())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgscompoundcurve.h
QgsCompoundCurve.__repr__ = lambda self: '<QgsCompoundCurve {}>'.format(self.asWkt())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgscurvepolygon.h
QgsCurvePolygon.__repr__ = lambda self: '<QgsCurvePolygon {}>'.format(self.asWkt())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsellipse.h
QgsEllipse.__repr__ = lambda self: '<QgsEllipse {}>'.format(self.toString())
@@ -2,3 +2,4 @@
QgsGeometry.BufferSide.baseClass = QgsGeometry
QgsGeometry.EndCapStyle.baseClass = QgsGeometry
QgsGeometry.JoinStyle.baseClass = QgsGeometry
QgsGeometry.__repr__ = lambda self: '<QgsGeometry {}>'.format(self.asWkt())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgslinestring.h
QgsLineString.__repr__ = lambda self: '<QgsLineString {}>'.format(self.asWkt())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsmulticurve.h
QgsMultiCurve.__repr__ = lambda self: '<QgsMulitCurve {}>'.format(self.asWkt())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsmultilinestring.h
QgsMultiLineString.__repr__ = lambda self: '<QgsMultiLineString {}>'.format(self.asWkt())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsmultipoint.h
QgsMultiPoint.__repr__ = lambda self: '<QgsMultiPoint {}>'.format(self.asWkt())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsmultipolygon.h
QgsMultiPolygon.__repr__ = lambda self: '<QgsMultiPolygon {}>'.format(self.asWkt())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgspolygon.h
QgsPolygon.__repr__ = lambda self: '<QgsPolygon {}>'.format(self.asWkt())
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/core/geometry/qgsrectangle.h
QgsRectangle.__repr__ = lambda self: '<QgsRectangle {}>'.format(self.asWktCoordinates())
@@ -253,6 +253,7 @@ Returns true if the circle contains the ``point``.
virtual QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const;



};

/************************************************************************
@@ -162,6 +162,7 @@ Sets the circular string's points
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;



protected:

virtual QgsRectangle calculateBoundingBox() const;
@@ -166,6 +166,7 @@ Appends first point if not already closed.
virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;



protected:

virtual QgsRectangle calculateBoundingBox() const;
@@ -216,6 +216,7 @@ Returns approximate rotation angle for a vertex. Usually average angle between a
virtual QgsCurvePolygon *createEmptyWithSameType() const /Factory/;



protected:

virtual int childCount() const;
@@ -248,6 +248,7 @@ returns a string representation of the ellipse.
Members will be truncated to the specified precision.
%End


protected:

};
@@ -1290,6 +1290,7 @@ Exports the geometry to WKT
precision parameter added in QGIS 2.4
%End


QString asJson( int precision = 17 ) const;
%Docstring
Exports the geometry to a GeoJSON string.
@@ -317,6 +317,7 @@ of the curve.
virtual QgsLineString *createEmptyWithSameType() const /Factory/;



protected:

virtual QgsRectangle calculateBoundingBox() const;
@@ -57,6 +57,7 @@ Returns a copy of the multi curve, where each component curve has had its line d




};


@@ -53,6 +53,7 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/;



protected:

virtual bool wktOmitChildType() const;
@@ -55,6 +55,7 @@ Multi point geometry collection.
virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;



protected:

virtual bool wktOmitChildType() const;
@@ -54,6 +54,7 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
virtual QgsMultiPolygon *createEmptyWithSameType() const /Factory/;



protected:

virtual bool wktOmitChildType() const;
@@ -65,6 +65,7 @@ negative if the point lies outside the polygon.
virtual QgsPolygon *createEmptyWithSameType() const /Factory/;



protected:


@@ -322,6 +322,7 @@ Converts the rectangle to a 3D box, with the specified

operator QVariant() const;


};


@@ -122,7 +122,6 @@ Returns a string representation of the point (x, y) with a preset ``precision``.
If ``precision`` is -1, then a default precision will be used.
%End


QString asWkt() const;
%Docstring
Returns the well known text representation for the point (e.g. "POINT(x y)").
@@ -39,6 +39,16 @@ count=0

modules=(core gui analysis server)
for module in "${modules[@]}"; do

# clean auto_additions and auto_generated folders
rm -rf python/${module}/auto_additions/*.py
rm -rf python/${module}/auto_generated/*.py
# put back __init__.py
echo '"""
This folder is completed using sipify.pl script
It is not aimed to be manually edited
"""' > python/${module}/auto_additions/__init__.py

while read -r sipfile; do
echo "$sipfile.in"
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)
@@ -247,6 +247,8 @@ class CORE_EXPORT QgsCircle : public QgsEllipse

QString toString( int pointPrecision = 17, int radiusPrecision = 17, int azimuthPrecision = 2 ) const override;

SIP_PYTHON_SPECIAL_REPR( "'<QgsPoint {}>'.format(self.toString())" )

};

#endif // QGSCIRCLE_H
@@ -146,6 +146,8 @@ class CORE_EXPORT QgsCircularString: public QgsCurve

QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsCircularString {}>'.format(self.asWkt())" )

protected:

QgsRectangle calculateBoundingBox() const override;
@@ -146,6 +146,8 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve

QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsCompoundCurve {}>'.format(self.asWkt())" )

protected:

QgsRectangle calculateBoundingBox() const override;
@@ -204,6 +204,8 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface

QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsCurvePolygon {}>'.format(self.asWkt())" )

protected:

int childCount() const override;
@@ -240,6 +240,8 @@ class CORE_EXPORT QgsEllipse
*/
virtual QString toString( int pointPrecision = 17, int axisPrecision = 17, int azimuthPrecision = 2 ) const;

SIP_PYTHON_SPECIAL_REPR( "'<QgsEllipse {}>'.format(self.toString())" )

protected:
QgsPoint mCenter;
double mSemiMajorAxis = 0.0;
@@ -1248,6 +1248,8 @@ class CORE_EXPORT QgsGeometry
*/
QString asWkt( int precision = 17 ) const;

SIP_PYTHON_SPECIAL_REPR( "'<QgsGeometry {}>'.format(self.asWkt())" )

/**
* Exports the geometry to a GeoJSON string.
*/
@@ -346,6 +346,8 @@ class CORE_EXPORT QgsLineString: public QgsCurve

QgsLineString *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsLineString {}>'.format(self.asWkt())" )

protected:

QgsRectangle calculateBoundingBox() const override;
@@ -73,6 +73,8 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection

QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsMulitCurve {}>'.format(self.asWkt())" )


};

@@ -65,6 +65,8 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve

QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsMultiLineString {}>'.format(self.asWkt())" )

protected:

bool wktOmitChildType() const override;
@@ -66,6 +66,8 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection

QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsMultiPoint {}>'.format(self.asWkt())" )

protected:

bool wktOmitChildType() const override;
@@ -65,6 +65,8 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface

QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsMultiPolygon {}>'.format(self.asWkt())" )

protected:

bool wktOmitChildType() const override;
@@ -84,6 +84,8 @@ class CORE_EXPORT QgsPolygon: public QgsCurvePolygon

QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY;

SIP_PYTHON_SPECIAL_REPR( "'<QgsPolygon {}>'.format(self.asWkt())" )

protected:

friend class QgsCurvePolygon;
@@ -541,6 +541,8 @@ class CORE_EXPORT QgsRectangle
return QVariant::fromValue( *this );
}

SIP_PYTHON_SPECIAL_REPR( "'<QgsRectange {}>'.format(self.asWktCoordinates())" )

private:

double mXmin = 0.0;
@@ -156,8 +156,6 @@ class CORE_EXPORT QgsPointXY
*/
QString toString( int precision = -1 ) const;

SIP_PYTHON_SPECIAL_REPR( "'<QgsPointXY {}>'.format(self.toString())" )

/**
* Returns the well known text representation for the point (e.g. "POINT(x y)").
* The wkt is created without an SRID.
@@ -9,6 +9,7 @@ IF (WITH_SERVER)
ENDIF (WITH_SERVER)

ADD_PYTHON_TEST(PyCoreAdittions test_core_additions.py)
ADD_PYTHON_TEST(PyPythonRepr test_python_repr.py)
ADD_PYTHON_TEST(PyQgsActionManager test_qgsactionmanager.py)
ADD_PYTHON_TEST(PyQgsAFSProvider test_provider_afs.py)
ADD_PYTHON_TEST(PyQgsPythonProvider test_provider_python.py)

0 comments on commit cc3e29b

Please sign in to comment.