diff --git a/doc/api_break.dox b/doc/api_break.dox index be718134f550..9c2e675a9a4d 100644 --- a/doc/api_break.dox +++ b/doc/api_break.dox @@ -453,6 +453,9 @@ QgsAbstractGeometry {#qgis_api_break_3_0_QgsAbstractGeometry} - asWkb() returns QByteArray instead of new raw pointer - wkbSize() has been removed, use asWkb() to get length of returned QByteArray - fromWkb() gets the WKB pointer passed by reference instead of value, so that caller may to find out where the parsing ended +- asGML2() was renamed to asGml2() +- asGML3() was renamed to asGml3() +- asJSON() was renamed to asJson() QgsActionManager {#qgis_api_break_3_0_QgsActionManager} @@ -1313,7 +1316,7 @@ can force a detach and full clone of the geometry, so it is preferable to use th method if the geometry is not being modified. - isEmpty() was renamed to isNull() to differentiate a missing geometry from a geometry which is empty (eg an empty geometry collection) -- wkbSize() and asWkb() has been replaced by exportToWkb(). WKB representation is no longer cached within QgsGeometry +- wkbSize() was removed. WKB representation is no longer cached within QgsGeometry - asGeos() has been replaced by exportToGeos(). GEOS representation is no longer cached within QgsGeometry - int addPart( const QList &points, QgsWkbTypes::GeometryType geomType ) has been renamed to addPointsXY - int addPart( const QList &points, QgsWkbTypes::GeometryType geomType ) has been renamed to addPoints @@ -1333,6 +1336,8 @@ maintains Z or M dimensions from the input points and is more efficient. - fromMultiPolyline() was renamed to fromMultiPolylineXY() - fromPolygon() was renamed to fromPolygonXY() - fromMultiPolygon() was renamed to fromMultiPolygonXY() +- exportToWkt() was renamed to asWkt() +- exportToGeoJSON() was renamed to asJson() QgsGeometryAnalyzer {#qgis_api_break_3_0_QgsGeometryAnalyzer} @@ -1963,6 +1968,8 @@ QgsPoint {#qgis_api_break_3_0_QgsPoint} -------- - onSegment() has been removed. Use sqrDistToSegment() instead for a more precise test. +- toDegreesMinutesSeconds() and toDegreesMinutes() have been removed. Use QgsCoordinateFormatter instead. +- wellKnownText() was renamed to asWkt() QgsPointDisplacementRenderer {#qgis_api_break_3_0_QgsPointDisplacementRenderer} diff --git a/python/__init__.py b/python/__init__.py index 96232adc7fbd..0cedfe0ca710 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -83,7 +83,7 @@ def mapping_feature(feature): def mapping_geometry(geometry): - geo = geometry.exportToGeoJSON() + geo = geometry.asJson() # We have to use eval because exportToGeoJSON() gives us # back a string that looks like a dictionary. return eval(geo) diff --git a/python/core/core_auto.sip b/python/core/core_auto.sip index e2ca9ea21969..26418e3e3bda 100644 --- a/python/core/core_auto.sip +++ b/python/core/core_auto.sip @@ -21,6 +21,7 @@ %Include qgscolorscheme.sip %Include qgscolorschemeregistry.sip %Include qgsconditionalstyle.sip +%Include qgscoordinateformatter.sip %Include qgscoordinatetransform.sip %Include qgscrscache.sip %Include qgsdartmeasurement.sip diff --git a/python/core/geometry/qgsabstractgeometry.sip b/python/core/geometry/qgsabstractgeometry.sip index 26acfc9dac3f..26793c5d0934 100644 --- a/python/core/geometry/qgsabstractgeometry.sip +++ b/python/core/geometry/qgsabstractgeometry.sip @@ -166,7 +166,7 @@ class QgsAbstractGeometry .. seealso:: asWkt .. seealso:: asGML2 .. seealso:: asGML3 -.. seealso:: asJSON +.. seealso:: asJson() .. versionadded:: 3.0 :rtype: QByteArray %End @@ -175,47 +175,47 @@ class QgsAbstractGeometry %Docstring Returns a WKT representation of the geometry. \param precision number of decimal places for coordinates -.. seealso:: asWkb -.. seealso:: asGML2 -.. seealso:: asGML3 -.. seealso:: asJSON +.. seealso:: asWkb() +.. seealso:: asGml2() +.. seealso:: asGml3() +.. seealso:: asJson() :rtype: str %End - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const = 0; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const = 0; %Docstring Returns a GML2 representation of the geometry. \param doc DOM document \param precision number of decimal places for coordinates \param ns XML namespace -.. seealso:: asWkb -.. seealso:: asWkt -.. seealso:: asGML3 -.. seealso:: asJSON +.. seealso:: asWkb() +.. seealso:: asWkt() +.. seealso:: asGml3() +.. seealso:: asJson() :rtype: QDomElement %End - virtual QDomElement asGML3( 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; %Docstring Returns a GML3 representation of the geometry. \param doc DOM document \param precision number of decimal places for coordinates \param ns XML namespace -.. seealso:: asWkb -.. seealso:: asWkt -.. seealso:: asGML2 -.. seealso:: asJSON +.. seealso:: asWkb() +.. seealso:: asWkt() +.. seealso:: asGml2() +.. seealso:: asJson() :rtype: QDomElement %End - virtual QString asJSON( int precision = 17 ) const = 0; + virtual QString asJson( int precision = 17 ) const = 0; %Docstring Returns a GeoJSON representation of the geometry. \param precision number of decimal places for coordinates -.. seealso:: asWkb -.. seealso:: asWkt -.. seealso:: asGML2 -.. seealso:: asGML3 +.. seealso:: asWkb() +.. seealso:: asWkt() +.. seealso:: asGml2() +.. seealso:: asGml3() :rtype: str %End diff --git a/python/core/geometry/qgscircularstring.sip b/python/core/geometry/qgscircularstring.sip index df6e6509c58b..f91947cb2009 100644 --- a/python/core/geometry/qgscircularstring.sip +++ b/python/core/geometry/qgscircularstring.sip @@ -47,11 +47,11 @@ class QgsCircularString: QgsCurve virtual QString asWkt( int precision = 17 ) const; - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual bool isEmpty() const; diff --git a/python/core/geometry/qgscompoundcurve.sip b/python/core/geometry/qgscompoundcurve.sip index 73915c2090b5..5c0eef93e241 100644 --- a/python/core/geometry/qgscompoundcurve.sip +++ b/python/core/geometry/qgscompoundcurve.sip @@ -47,11 +47,11 @@ class QgsCompoundCurve: QgsCurve virtual QString asWkt( int precision = 17 ) const; - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual double length() const; diff --git a/python/core/geometry/qgscurvepolygon.sip b/python/core/geometry/qgscurvepolygon.sip index 9c092c6fe962..e602d3c7864e 100644 --- a/python/core/geometry/qgscurvepolygon.sip +++ b/python/core/geometry/qgscurvepolygon.sip @@ -50,11 +50,11 @@ class QgsCurvePolygon: QgsSurface virtual QString asWkt( int precision = 17 ) const; - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual double area() const; diff --git a/python/core/geometry/qgsgeometry.sip b/python/core/geometry/qgsgeometry.sip index 6533802c3e46..a1e90b2504e4 100644 --- a/python/core/geometry/qgsgeometry.sip +++ b/python/core/geometry/qgsgeometry.sip @@ -1088,14 +1088,14 @@ Returns an extruded version of this geometry. :rtype: QgsGeometry %End - QByteArray exportToWkb() const; + QByteArray asWkb() const; %Docstring Export the geometry to WKB .. versionadded:: 3.0 :rtype: QByteArray %End - QString exportToWkt( int precision = 17 ) const; + QString asWkt( int precision = 17 ) const; %Docstring Exports the geometry to WKT .. note:: @@ -1105,17 +1105,9 @@ Returns an extruded version of this geometry. :rtype: str %End - QString exportToGeoJSON( int precision = 17 ) const; + QString asJson( int precision = 17 ) const; %Docstring - Exports the geometry to GeoJSON - :return: a QString representing the geometry as GeoJSON -.. versionadded:: 1.8 -.. note:: - - Available in Python bindings since QGIS 1.9 -.. note:: - - precision parameter added in QGIS 2.4 + Exports the geometry to a GeoJSON string. :rtype: str %End diff --git a/python/core/geometry/qgsgeometrycollection.sip b/python/core/geometry/qgsgeometrycollection.sip index 2b0b3452928a..6e97b64ffb06 100644 --- a/python/core/geometry/qgsgeometrycollection.sip +++ b/python/core/geometry/qgsgeometrycollection.sip @@ -97,11 +97,11 @@ Adds a geometry and takes ownership. Returns true in case of success. virtual QString asWkt( int precision = 17 ) const; - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual QgsRectangle boundingBox() const; diff --git a/python/core/geometry/qgslinestring.sip b/python/core/geometry/qgslinestring.sip index f54e5e307bbe..bbeaad6907bd 100644 --- a/python/core/geometry/qgslinestring.sip +++ b/python/core/geometry/qgslinestring.sip @@ -189,11 +189,11 @@ Closes the line string by appending the first point to the end of the line, if i virtual QString asWkt( int precision = 17 ) const; - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual double length() const; diff --git a/python/core/geometry/qgsmulticurve.sip b/python/core/geometry/qgsmulticurve.sip index ae038bdd5eaa..90c7613edbc7 100644 --- a/python/core/geometry/qgsmulticurve.sip +++ b/python/core/geometry/qgsmulticurve.sip @@ -30,11 +30,11 @@ class QgsMultiCurve: QgsGeometryCollection virtual bool fromWkt( const QString &wkt ); - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual bool addGeometry( QgsAbstractGeometry *g /Transfer/ ); diff --git a/python/core/geometry/qgsmultilinestring.sip b/python/core/geometry/qgsmultilinestring.sip index 029bc8dcc6b5..4380f5ead36f 100644 --- a/python/core/geometry/qgsmultilinestring.sip +++ b/python/core/geometry/qgsmultilinestring.sip @@ -29,11 +29,11 @@ class QgsMultiLineString: QgsMultiCurve virtual bool fromWkt( const QString &wkt ); - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual bool addGeometry( QgsAbstractGeometry *g /Transfer/ ); diff --git a/python/core/geometry/qgsmultipoint.sip b/python/core/geometry/qgsmultipoint.sip index ec53997a534c..28b89fa264a4 100644 --- a/python/core/geometry/qgsmultipoint.sip +++ b/python/core/geometry/qgsmultipoint.sip @@ -31,11 +31,11 @@ class QgsMultiPoint: QgsGeometryCollection virtual void clear(); - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual int nCoordinates() const; diff --git a/python/core/geometry/qgsmultipolygon.sip b/python/core/geometry/qgsmultipolygon.sip index a66d153ef253..61594955b96d 100644 --- a/python/core/geometry/qgsmultipolygon.sip +++ b/python/core/geometry/qgsmultipolygon.sip @@ -28,11 +28,11 @@ class QgsMultiPolygon: QgsMultiSurface virtual bool fromWkt( const QString &wkt ); - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual bool addGeometry( QgsAbstractGeometry *g /Transfer/ ); diff --git a/python/core/geometry/qgsmultisurface.sip b/python/core/geometry/qgsmultisurface.sip index 9a6056d475c4..3cb215d7177c 100644 --- a/python/core/geometry/qgsmultisurface.sip +++ b/python/core/geometry/qgsmultisurface.sip @@ -30,11 +30,11 @@ class QgsMultiSurface: QgsGeometryCollection virtual bool fromWkt( const QString &wkt ); - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual bool addGeometry( QgsAbstractGeometry *g /Transfer/ ); diff --git a/python/core/geometry/qgspoint.sip b/python/core/geometry/qgspoint.sip index c4a0f31bc2d9..84b873e19ccf 100644 --- a/python/core/geometry/qgspoint.sip +++ b/python/core/geometry/qgspoint.sip @@ -34,10 +34,10 @@ class QgsPoint: QgsAbstractGeometry \code{.py} pt = QgsPoint(43.4, 5.3) - pt.exportToWkt() # Point(43.4 5.3) + pt.asWkt() # Point(43.4 5.3) pt_z = QgsPoint(120, 343, 77) - pt.exportToWkt() # PointZ(120 343 77) + pt.asWkt() # PointZ(120 343 77) pt_m = QgsPoint(33, 88, m=5) pt_m.m() # 5 @@ -349,11 +349,11 @@ class QgsPoint: QgsAbstractGeometry virtual QString asWkt( int precision = 17 ) const; - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - virtual QString asJSON( int precision = 17 ) const; + virtual QString asJson( int precision = 17 ) const; virtual void draw( QPainter &p ) const; diff --git a/python/core/geometry/qgstriangle.sip b/python/core/geometry/qgstriangle.sip index 9288ea06616b..1e5985b323a4 100644 --- a/python/core/geometry/qgstriangle.sip +++ b/python/core/geometry/qgstriangle.sip @@ -65,7 +65,7 @@ class QgsTriangle : QgsPolygon virtual bool fromWkt( const QString &wkt ); - virtual QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; + virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; virtual QgsPolygon *surfaceToPolygon() const /Factory/; diff --git a/python/core/qgscoordinateformatter.sip b/python/core/qgscoordinateformatter.sip new file mode 100644 index 000000000000..1743d58c6032 --- /dev/null +++ b/python/core/qgscoordinateformatter.sip @@ -0,0 +1,107 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/qgscoordinateformatter.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + +class QgsCoordinateFormatter +{ +%Docstring + Contains methods for converting coordinates for display in various formats. + + QgsCoordinateFormatter contains static methods for converting numeric coordinates into different + formats, for instance as degrees, minutes, seconds values. Note that QgsCoordinateFormatter has + no consideration for the validity of converting coordinates to the various display formats, and it + is up to the caller to ensure that sensible formats are used for particular coordinates. For instance, + ensuring that only geographic coordinates and not projected coordinates are formatted to degree + based formats. + +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgscoordinateformatter.h" +%End + public: + + enum Format + { + FormatPair, + FormatDegreesMinutesSeconds, + FormatDegreesMinutes, + FormatDecimalDegrees, + }; + + enum FormatFlag + { + FlagDegreesUseStringSuffix, + FlagDegreesPadMinutesSeconds, + }; + typedef QFlags FormatFlags; + + + static QString formatX( double x, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix ); +%Docstring + Formats an ``x`` coordinate value according to the specified parameters. + + The ``format`` argument indicates the desired display format for the coordinate. + + The ``precision`` argument gives the number of decimal places to include for coordinates. + + Optional ``flags`` can be specified to control the output format. + +.. seealso:: formatY() + :rtype: str +%End + + static QString formatY( double y, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix ); +%Docstring + Formats a ``y`` coordinate value according to the specified parameters. + + The ``format`` argument indicates the desired display format for the coordinate. + + The ``precision`` argument gives the number of decimal places to include for coordinates. + + Optional ``flags`` can be specified to control the output format. + +.. seealso:: formatX() + :rtype: str +%End + + static QString format( QgsPointXY point, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix ); +%Docstring + Formats a ``point`` according to the specified parameters. + + The ``format`` argument indicates the desired display format for the coordinate. + + The ``precision`` argument gives the number of decimal places to include for coordinates. + + Optional ``flags`` can be specified to control the output format. + :rtype: str +%End + + static QString asPair( double x, double y, int precision = 12 ); +%Docstring + Formats coordinates as an "``x``,``y``" pair, with optional decimal ``precision`` (number + of decimal places to include). + :rtype: str +%End + +}; + +QFlags operator|(QgsCoordinateFormatter::FormatFlag f1, QFlags f2); + + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/qgscoordinateformatter.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/core/qgspointxy.sip b/python/core/qgspointxy.sip index f2fe6c629c38..d2c91afd452b 100644 --- a/python/core/qgspointxy.sip +++ b/python/core/qgspointxy.sip @@ -105,50 +105,17 @@ Sets the x and y value of the point :rtype: QPointF %End - QString toString() const; + QString toString( int precision = -1 ) const; %Docstring -String representation of the point (x,y) + Returns a string representation of the point (x, y) with a preset ``precision``. + If ``precision`` is -1, then a default precision will be used. :rtype: str %End - QString toString( int precision ) const; + QString asWkt() const; %Docstring -As above but with precision for string representation of a point - :rtype: str -%End - - QString toDegreesMinutesSeconds( int precision, const bool useSuffix = true, const bool padded = false ) const; -%Docstring - Return a string representation as degrees minutes seconds. - Its up to the calling function to ensure that this point can - be meaningfully represented in this form. - \param precision number of decimal points to use for seconds - \param useSuffix set to true to include a direction suffix (e.g., 'N'), - set to false to use a "-" prefix for west and south coordinates - \param padded set to true to force minutes and seconds to use two decimals, - e.g., '05' instead of '5'. - :rtype: str -%End - - QString toDegreesMinutes( int precision, const bool useSuffix = true, const bool padded = false ) const; -%Docstring - Return a string representation as degrees minutes. - Its up to the calling function to ensure that this point can - be meaningfully represented in this form. - \param precision number of decimal points to use for minutes - \param useSuffix set to true to include a direction suffix (e.g., 'N'), - set to false to use a "-" prefix for west and south coordinates - \param padded set to true to force minutes to use two decimals, - e.g., '05' instead of '5'. - :rtype: str -%End - - - QString wellKnownText() const; -%Docstring - Return the well known text representation for the point. + Return the well known text representation for the point (e.g. "POINT(x y)"). The wkt is created without an SRID. - :return: Well known text in the form POINT(x y) :rtype: str %End diff --git a/python/plugins/db_manager/db_plugins/vlayers/data_model.py b/python/plugins/db_manager/db_plugins/vlayers/data_model.py index 11f3c2fca3d5..ba60c4af3dd2 100644 --- a/python/plugins/db_manager/db_plugins/vlayers/data_model.py +++ b/python/plugins/db_manager/db_plugins/vlayers/data_model.py @@ -100,7 +100,7 @@ def __init__(self, db, sql, parent=None): a = f.attributes() if has_geometry: if f.hasGeometry(): - a += [f.geometry().exportToWkt()] + a += [f.geometry().asWkt()] else: a += [None] data += [a] diff --git a/python/plugins/processing/algs/qgis/HypsometricCurves.py b/python/plugins/processing/algs/qgis/HypsometricCurves.py index 609d0956dbb0..b555606a04d4 100644 --- a/python/plugins/processing/algs/qgis/HypsometricCurves.py +++ b/python/plugins/processing/algs/qgis/HypsometricCurves.py @@ -135,7 +135,7 @@ def processAlgorithm(self, parameters, context, feedback): fName = os.path.join( outputPath, 'hystogram_%s_%s.csv' % (source.sourceName(), f.id())) - ogrGeom = ogr.CreateGeometryFromWkt(intersectedGeom.exportToWkt()) + ogrGeom = ogr.CreateGeometryFromWkt(intersectedGeom.asWkt()) bbox = intersectedGeom.boundingBox() xMin = bbox.xMinimum() xMax = bbox.xMaximum() diff --git a/src/app/qgsclipboard.cpp b/src/app/qgsclipboard.cpp index 02f55c41cbb0..b8b969db8acb 100644 --- a/src/app/qgsclipboard.cpp +++ b/src/app/qgsclipboard.cpp @@ -115,7 +115,7 @@ QString QgsClipboard::generateClipboardText() const if ( format == AttributesWithWKT ) { if ( it->hasGeometry() ) - textFields += it->geometry().exportToWkt(); + textFields += it->geometry().asWkt(); else { textFields += QgsApplication::nullRepresentation(); @@ -249,7 +249,7 @@ void QgsClipboard::insert( const QgsFeature &feature ) { mFeatureClipboard.push_back( feature ); - QgsDebugMsgLevel( "inserted " + feature.geometry().exportToWkt(), 4 ); + QgsDebugMsgLevel( "inserted " + feature.geometry().asWkt(), 4 ); mUseSystemClipboard = false; emit changed(); } diff --git a/src/app/qgsdecorationnortharrow.cpp b/src/app/qgsdecorationnortharrow.cpp index 91c0b31297d4..6c38d0346bad 100644 --- a/src/app/qgsdecorationnortharrow.cpp +++ b/src/app/qgsdecorationnortharrow.cpp @@ -127,7 +127,7 @@ void QgsDecorationNorthArrow::render( const QgsMapSettings &mapSettings, QgsRend { mRotationInt = QgsBearingUtils:: bearingTrueNorth( mapSettings.destinationCrs(), context.extent().center() ); } - catch ( QgsException &e ) + catch ( QgsException & ) { mRotationInt = 0.0; //QgsDebugMsg( "Can not get direction to true north. Probably project CRS is not defined." ); diff --git a/src/app/qgsmaptoolselectutils.cpp b/src/app/qgsmaptoolselectutils.cpp index 25c46e392a52..8bc4026e951b 100644 --- a/src/app/qgsmaptoolselectutils.cpp +++ b/src/app/qgsmaptoolselectutils.cpp @@ -224,7 +224,7 @@ QgsFeatureIds QgsMapToolSelectUtils::getMatchingFeatures( QgsMapCanvas *canvas, } QgsDebugMsgLevel( "Selection layer: " + vlayer->name(), 3 ); - QgsDebugMsgLevel( "Selection polygon: " + selectGeomTrans.exportToWkt(), 3 ); + QgsDebugMsgLevel( "Selection polygon: " + selectGeomTrans.asWkt(), 3 ); QgsDebugMsgLevel( "doContains: " + QString( doContains ? "T" : "F" ), 3 ); QgsRenderContext context = QgsRenderContext::fromMapSettings( canvas->mapSettings() ); diff --git a/src/app/qgsmaptoolshowhidelabels.cpp b/src/app/qgsmaptoolshowhidelabels.cpp index 5d830c43694d..fe21b7a29264 100644 --- a/src/app/qgsmaptoolshowhidelabels.cpp +++ b/src/app/qgsmaptoolshowhidelabels.cpp @@ -214,7 +214,7 @@ bool QgsMapToolShowHideLabels::selectedFeatures( QgsVectorLayer *vlayer, QApplication::setOverrideCursor( Qt::WaitCursor ); QgsDebugMsg( "Selection layer: " + vlayer->name() ); - QgsDebugMsg( "Selection polygon: " + selectGeomTrans.exportToWkt() ); + QgsDebugMsg( "Selection polygon: " + selectGeomTrans.asWkt() ); QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest() .setFilterRect( selectGeomTrans.boundingBox() ) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 8a95532381c5..ad56d72ae743 100755 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -145,6 +145,7 @@ SET(QGIS_CORE_SRCS qgscolorscheme.cpp qgscolorschemeregistry.cpp qgsconditionalstyle.cpp + qgscoordinateformatter.cpp qgscoordinatereferencesystem.cpp qgscoordinatetransform.cpp qgscoordinatetransform_p.cpp @@ -832,6 +833,7 @@ SET(QGIS_CORE_HDRS qgscolorschemeregistry.h qgsconnectionpool.h qgsconditionalstyle.h + qgscoordinateformatter.h qgscoordinatetransform.h qgscoordinateutils.h qgscrscache.h diff --git a/src/core/composer/qgscomposermapgrid.cpp b/src/core/composer/qgscomposermapgrid.cpp index 5812ff6de7f2..2101f6059605 100644 --- a/src/core/composer/qgscomposermapgrid.cpp +++ b/src/core/composer/qgscomposermapgrid.cpp @@ -33,7 +33,7 @@ #include "qgsexpressioncontext.h" #include "qgsexception.h" #include "qgssettings.h" - +#include "qgscoordinateformatter.h" #include #include @@ -1484,49 +1484,56 @@ QString QgsComposerMapGrid::gridAnnotationString( double value, QgsComposerMapGr return mGridAnnotationExpression->evaluate( &expressionContext ).toString(); } - QgsPointXY p; - p.setX( coord == QgsComposerMapGrid::Longitude ? value : 0 ); - p.setY( coord == QgsComposerMapGrid::Longitude ? 0 : value ); - - QString annotationString; - if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinute ) - { - annotationString = p.toDegreesMinutes( mGridAnnotationPrecision ); - } - else if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinuteNoSuffix ) - { - annotationString = p.toDegreesMinutes( mGridAnnotationPrecision, false ); - } - else if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinutePadded ) - { - annotationString = p.toDegreesMinutes( mGridAnnotationPrecision, true, true ); - } - else if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinuteSecond ) + QgsCoordinateFormatter::Format format = QgsCoordinateFormatter::FormatDecimalDegrees; + QgsCoordinateFormatter::FormatFlags flags = 0; + switch ( mGridAnnotationFormat ) { - annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision ); - } - else if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinuteSecondNoSuffix ) - { - annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision, false ); - } - else if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinuteSecondPadded ) - { - annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision, true, true ); - } + case Decimal: + case DecimalWithSuffix: + case CustomFormat: + break; // already handled above - QStringList split = annotationString.split( ',' ); - if ( coord == QgsComposerMapGrid::Longitude ) - { - return split.at( 0 ); + case DegreeMinute: + format = QgsCoordinateFormatter::FormatDegreesMinutes; + flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix; + break; + + case DegreeMinuteSecond: + format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds; + flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix; + break; + + case DegreeMinuteNoSuffix: + format = QgsCoordinateFormatter::FormatDegreesMinutes; + flags = 0; + break; + + case DegreeMinutePadded: + format = QgsCoordinateFormatter::FormatDegreesMinutes; + flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix | QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds; + break; + + case DegreeMinuteSecondNoSuffix: + format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds; + flags = 0; + break; + + case DegreeMinuteSecondPadded: + format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds; + flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix | QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds; + break; } - else + + switch ( coord ) { - if ( split.size() < 2 ) - { - return QLatin1String( "" ); - } - return split.at( 1 ); + case Longitude: + return QgsCoordinateFormatter::formatX( value, format, flags ); + + case Latitude: + return QgsCoordinateFormatter::formatY( value, format, flags ); } + + return QString(); // no warnings } int QgsComposerMapGrid::xGridLines( QList< QPair< double, QLineF > > &lines ) const diff --git a/src/core/expression/qgsexpressionfunction.cpp b/src/core/expression/qgsexpressionfunction.cpp index e52ea09a76d5..4b0cc5815d0f 100644 --- a/src/core/expression/qgsexpressionfunction.cpp +++ b/src/core/expression/qgsexpressionfunction.cpp @@ -2662,7 +2662,7 @@ static QVariant fcnGeomToWKT( const QVariantList &values, const QgsExpressionCon qlonglong prec = 8; if ( values.length() == 2 ) prec = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ); - QString wkt = fGeom.exportToWkt( prec ); + QString wkt = fGeom.asWkt( prec ); return QVariant( wkt ); } diff --git a/src/core/geometry/qgsabstractgeometry.h b/src/core/geometry/qgsabstractgeometry.h index af0012cff901..dca52089a318 100644 --- a/src/core/geometry/qgsabstractgeometry.h +++ b/src/core/geometry/qgsabstractgeometry.h @@ -196,7 +196,7 @@ class CORE_EXPORT QgsAbstractGeometry * \see asWkt * \see asGML2 * \see asGML3 - * \see asJSON + * \see asJson() * \since QGIS 3.0 */ virtual QByteArray asWkb() const = 0; @@ -204,10 +204,10 @@ class CORE_EXPORT QgsAbstractGeometry /** * Returns a WKT representation of the geometry. * \param precision number of decimal places for coordinates - * \see asWkb - * \see asGML2 - * \see asGML3 - * \see asJSON + * \see asWkb() + * \see asGml2() + * \see asGml3() + * \see asJson() */ virtual QString asWkt( int precision = 17 ) const = 0; @@ -216,34 +216,34 @@ class CORE_EXPORT QgsAbstractGeometry * \param doc DOM document * \param precision number of decimal places for coordinates * \param ns XML namespace - * \see asWkb - * \see asWkt - * \see asGML3 - * \see asJSON + * \see asWkb() + * \see asWkt() + * \see asGml3() + * \see asJson() */ - virtual QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const = 0; + virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const = 0; /** * Returns a GML3 representation of the geometry. * \param doc DOM document * \param precision number of decimal places for coordinates * \param ns XML namespace - * \see asWkb - * \see asWkt - * \see asGML2 - * \see asJSON + * \see asWkb() + * \see asWkt() + * \see asGml2() + * \see asJson() */ - virtual QDomElement asGML3( 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; /** * Returns a GeoJSON representation of the geometry. * \param precision number of decimal places for coordinates - * \see asWkb - * \see asWkt - * \see asGML2 - * \see asGML3 + * \see asWkb() + * \see asWkt() + * \see asGml2() + * \see asGml3() */ - virtual QString asJSON( int precision = 17 ) const = 0; + virtual QString asJson( int precision = 17 ) const = 0; //render pipeline diff --git a/src/core/geometry/qgscircularstring.cpp b/src/core/geometry/qgscircularstring.cpp index 15b012a129e9..71469906be3f 100644 --- a/src/core/geometry/qgscircularstring.cpp +++ b/src/core/geometry/qgscircularstring.cpp @@ -306,15 +306,15 @@ QString QgsCircularString::asWkt( int precision ) const return wkt; } -QDomElement QgsCircularString::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsCircularString::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { // GML2 does not support curves std::unique_ptr< QgsLineString > line( curveToLine() ); - QDomElement gml = line->asGML2( doc, precision, ns ); + QDomElement gml = line->asGml2( doc, precision, ns ); return gml; } -QDomElement QgsCircularString::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsCircularString::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QgsPointSequence pts; points( pts ); @@ -332,11 +332,11 @@ QDomElement QgsCircularString::asGML3( QDomDocument &doc, int precision, const Q return elemCurve; } -QString QgsCircularString::asJSON( int precision ) const +QString QgsCircularString::asJson( int precision ) const { // GeoJSON does not support curves std::unique_ptr< QgsLineString > line( curveToLine() ); - QString json = line->asJSON( precision ); + QString json = line->asJson( precision ); return json; } diff --git a/src/core/geometry/qgscircularstring.h b/src/core/geometry/qgscircularstring.h index e3543aafa001..19c8efd1c3fd 100644 --- a/src/core/geometry/qgscircularstring.h +++ b/src/core/geometry/qgscircularstring.h @@ -49,9 +49,9 @@ class CORE_EXPORT QgsCircularString: public QgsCurve QByteArray asWkb() const override; QString asWkt( int precision = 17 ) const override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; bool isEmpty() const override; int numPoints() const override; diff --git a/src/core/geometry/qgscompoundcurve.cpp b/src/core/geometry/qgscompoundcurve.cpp index 04ea069174a8..53673cd4ed12 100644 --- a/src/core/geometry/qgscompoundcurve.cpp +++ b/src/core/geometry/qgscompoundcurve.cpp @@ -267,15 +267,15 @@ QString QgsCompoundCurve::asWkt( int precision ) const return wkt; } -QDomElement QgsCompoundCurve::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsCompoundCurve::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { // GML2 does not support curves std::unique_ptr< QgsLineString > line( curveToLine() ); - QDomElement gml = line->asGML2( doc, precision, ns ); + QDomElement gml = line->asGml2( doc, precision, ns ); return gml; } -QDomElement QgsCompoundCurve::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsCompoundCurve::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement compoundCurveElem = doc.createElementNS( ns, QStringLiteral( "CompositeCurve" ) ); @@ -285,7 +285,7 @@ QDomElement QgsCompoundCurve::asGML3( QDomDocument &doc, int precision, const QS for ( const QgsCurve *curve : mCurves ) { QDomElement curveMemberElem = doc.createElementNS( ns, QStringLiteral( "curveMember" ) ); - QDomElement curveElem = curve->asGML3( doc, precision, ns ); + QDomElement curveElem = curve->asGml3( doc, precision, ns ); curveMemberElem.appendChild( curveElem ); compoundCurveElem.appendChild( curveMemberElem ); } @@ -293,11 +293,11 @@ QDomElement QgsCompoundCurve::asGML3( QDomDocument &doc, int precision, const QS return compoundCurveElem; } -QString QgsCompoundCurve::asJSON( int precision ) const +QString QgsCompoundCurve::asJson( int precision ) const { // GeoJSON does not support curves std::unique_ptr< QgsLineString > line( curveToLine() ); - QString json = line->asJSON( precision ); + QString json = line->asJson( precision ); return json; } diff --git a/src/core/geometry/qgscompoundcurve.h b/src/core/geometry/qgscompoundcurve.h index 788724e985f8..eae706480de5 100644 --- a/src/core/geometry/qgscompoundcurve.h +++ b/src/core/geometry/qgscompoundcurve.h @@ -49,9 +49,9 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve QByteArray asWkb() const override; QString asWkt( int precision = 17 ) const override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; //curve interface double length() const override; diff --git a/src/core/geometry/qgscurvepolygon.cpp b/src/core/geometry/qgscurvepolygon.cpp index 8504e017352c..a167e69cb3ae 100644 --- a/src/core/geometry/qgscurvepolygon.cpp +++ b/src/core/geometry/qgscurvepolygon.cpp @@ -335,7 +335,7 @@ QString QgsCurvePolygon::asWkt( int precision ) const return wkt; } -QDomElement QgsCurvePolygon::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsCurvePolygon::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { // GML2 does not support curves QDomElement elemPolygon = doc.createElementNS( ns, QStringLiteral( "Polygon" ) ); @@ -345,7 +345,7 @@ QDomElement QgsCurvePolygon::asGML2( QDomDocument &doc, int precision, const QSt QDomElement elemOuterBoundaryIs = doc.createElementNS( ns, QStringLiteral( "outerBoundaryIs" ) ); std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() ); - QDomElement outerRing = exteriorLineString->asGML2( doc, precision, ns ); + QDomElement outerRing = exteriorLineString->asGml2( doc, precision, ns ); outerRing.toElement().setTagName( QStringLiteral( "LinearRing" ) ); elemOuterBoundaryIs.appendChild( outerRing ); elemPolygon.appendChild( elemOuterBoundaryIs ); @@ -354,7 +354,7 @@ QDomElement QgsCurvePolygon::asGML2( QDomDocument &doc, int precision, const QSt { QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, QStringLiteral( "innerBoundaryIs" ) ); interiorLineString.reset( interiorRing( i )->curveToLine() ); - QDomElement innerRing = interiorLineString->asGML2( doc, precision, ns ); + QDomElement innerRing = interiorLineString->asGml2( doc, precision, ns ); innerRing.toElement().setTagName( QStringLiteral( "LinearRing" ) ); elemInnerBoundaryIs.appendChild( innerRing ); elemPolygon.appendChild( elemInnerBoundaryIs ); @@ -362,7 +362,7 @@ QDomElement QgsCurvePolygon::asGML2( QDomDocument &doc, int precision, const QSt return elemPolygon; } -QDomElement QgsCurvePolygon::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsCurvePolygon::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemCurvePolygon = doc.createElementNS( ns, QStringLiteral( "Polygon" ) ); @@ -370,7 +370,7 @@ QDomElement QgsCurvePolygon::asGML3( QDomDocument &doc, int precision, const QSt return elemCurvePolygon; QDomElement elemExterior = doc.createElementNS( ns, QStringLiteral( "exterior" ) ); - QDomElement curveElem = exteriorRing()->asGML3( doc, precision, ns ); + QDomElement curveElem = exteriorRing()->asGml3( doc, precision, ns ); if ( curveElem.tagName() == QLatin1String( "LineString" ) ) { curveElem.setTagName( QStringLiteral( "LinearRing" ) ); @@ -381,7 +381,7 @@ QDomElement QgsCurvePolygon::asGML3( QDomDocument &doc, int precision, const QSt for ( int i = 0, n = numInteriorRings(); i < n; ++i ) { QDomElement elemInterior = doc.createElementNS( ns, QStringLiteral( "interior" ) ); - QDomElement innerRing = interiorRing( i )->asGML3( doc, precision, ns ); + QDomElement innerRing = interiorRing( i )->asGml3( doc, precision, ns ); if ( innerRing.tagName() == QLatin1String( "LineString" ) ) { innerRing.setTagName( QStringLiteral( "LinearRing" ) ); @@ -392,7 +392,7 @@ QDomElement QgsCurvePolygon::asGML3( QDomDocument &doc, int precision, const QSt return elemCurvePolygon; } -QString QgsCurvePolygon::asJSON( int precision ) const +QString QgsCurvePolygon::asJson( int precision ) const { // GeoJSON does not support curves QString json = QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [" ); diff --git a/src/core/geometry/qgscurvepolygon.h b/src/core/geometry/qgscurvepolygon.h index e79ed804598b..a3eb971e9f24 100644 --- a/src/core/geometry/qgscurvepolygon.h +++ b/src/core/geometry/qgscurvepolygon.h @@ -53,9 +53,9 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface QByteArray asWkb() const override; QString asWkt( int precision = 17 ) const override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; //surface interface double area() const override; diff --git a/src/core/geometry/qgsgeometry.cpp b/src/core/geometry/qgsgeometry.cpp index cb49244e9ad2..2de1ceab9090 100644 --- a/src/core/geometry/qgsgeometry.cpp +++ b/src/core/geometry/qgsgeometry.cpp @@ -1197,7 +1197,7 @@ bool QgsGeometry::crosses( const QgsGeometry &geometry ) const return geos.crosses( geometry.d->geometry.get(), &mLastError ); } -QString QgsGeometry::exportToWkt( int precision ) const +QString QgsGeometry::asWkt( int precision ) const { if ( !d->geometry ) { @@ -1206,13 +1206,13 @@ QString QgsGeometry::exportToWkt( int precision ) const return d->geometry->asWkt( precision ); } -QString QgsGeometry::exportToGeoJSON( int precision ) const +QString QgsGeometry::asJson( int precision ) const { if ( !d->geometry ) { return QStringLiteral( "null" ); } - return d->geometry->asJSON( precision ); + return d->geometry->asJson( precision ); } QgsGeometry QgsGeometry::convertToType( QgsWkbTypes::GeometryType destType, bool destMultipart ) const @@ -2081,7 +2081,7 @@ QgsGeometry QgsGeometry::extrude( double x, double y ) return engine.extrude( x, y ); } -QByteArray QgsGeometry::exportToWkb() const +QByteArray QgsGeometry::asWkb() const { return d->geometry ? d->geometry->asWkb() : QByteArray(); } @@ -3112,7 +3112,7 @@ QgsGeometryEngine *QgsGeometry::createGeometryEngine( const QgsAbstractGeometry QDataStream &operator<<( QDataStream &out, const QgsGeometry &geometry ) { - out << geometry.exportToWkb(); + out << geometry.asWkb(); return out; } diff --git a/src/core/geometry/qgsgeometry.h b/src/core/geometry/qgsgeometry.h index 6fdafeb03c46..8bd9502d6ded 100644 --- a/src/core/geometry/qgsgeometry.h +++ b/src/core/geometry/qgsgeometry.h @@ -1107,23 +1107,19 @@ class CORE_EXPORT QgsGeometry * Export the geometry to WKB * \since QGIS 3.0 */ - QByteArray exportToWkb() const; + QByteArray asWkb() const; /** * Exports the geometry to WKT * \note precision parameter added in QGIS 2.4 * \returns true in case of success and false else */ - QString exportToWkt( int precision = 17 ) const; + QString asWkt( int precision = 17 ) const; /** - * Exports the geometry to GeoJSON - * \returns a QString representing the geometry as GeoJSON - * \since QGIS 1.8 - * \note Available in Python bindings since QGIS 1.9 - * \note precision parameter added in QGIS 2.4 + * Exports the geometry to a GeoJSON string. */ - QString exportToGeoJSON( int precision = 17 ) const; + QString asJson( int precision = 17 ) const; /** * Try to convert the geometry to the requested type diff --git a/src/core/geometry/qgsgeometrycollection.cpp b/src/core/geometry/qgsgeometrycollection.cpp index 3aba58c1958f..33289492573a 100644 --- a/src/core/geometry/qgsgeometrycollection.cpp +++ b/src/core/geometry/qgsgeometrycollection.cpp @@ -354,36 +354,36 @@ QString QgsGeometryCollection::asWkt( int precision ) const return wkt; } -QDomElement QgsGeometryCollection::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsGeometryCollection::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemMultiGeometry = doc.createElementNS( ns, QStringLiteral( "MultiGeometry" ) ); for ( const QgsAbstractGeometry *geom : mGeometries ) { QDomElement elemGeometryMember = doc.createElementNS( ns, QStringLiteral( "geometryMember" ) ); - elemGeometryMember.appendChild( geom->asGML2( doc, precision, ns ) ); + elemGeometryMember.appendChild( geom->asGml2( doc, precision, ns ) ); elemMultiGeometry.appendChild( elemGeometryMember ); } return elemMultiGeometry; } -QDomElement QgsGeometryCollection::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsGeometryCollection::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemMultiGeometry = doc.createElementNS( ns, QStringLiteral( "MultiGeometry" ) ); for ( const QgsAbstractGeometry *geom : mGeometries ) { QDomElement elemGeometryMember = doc.createElementNS( ns, QStringLiteral( "geometryMember" ) ); - elemGeometryMember.appendChild( geom->asGML3( doc, precision, ns ) ); + elemGeometryMember.appendChild( geom->asGml3( doc, precision, ns ) ); elemMultiGeometry.appendChild( elemGeometryMember ); } return elemMultiGeometry; } -QString QgsGeometryCollection::asJSON( int precision ) const +QString QgsGeometryCollection::asJson( int precision ) const { QString json = QStringLiteral( "{\"type\": \"GeometryCollection\", \"geometries\": [" ); for ( const QgsAbstractGeometry *geom : mGeometries ) { - json += geom->asJSON( precision ) + ", "; + json += geom->asJson( precision ) + ", "; } if ( json.endsWith( QLatin1String( ", " ) ) ) { diff --git a/src/core/geometry/qgsgeometrycollection.h b/src/core/geometry/qgsgeometrycollection.h index 4d32b947d617..74c3022a4a2c 100644 --- a/src/core/geometry/qgsgeometrycollection.h +++ b/src/core/geometry/qgsgeometrycollection.h @@ -96,9 +96,9 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry bool fromWkt( const QString &wkt ) override; QByteArray asWkb() const override; QString asWkt( int precision = 17 ) const override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; QgsRectangle boundingBox() const override; diff --git a/src/core/geometry/qgslinestring.cpp b/src/core/geometry/qgslinestring.cpp index ba7ac0d0d12a..d1009479f4b4 100644 --- a/src/core/geometry/qgslinestring.cpp +++ b/src/core/geometry/qgslinestring.cpp @@ -300,7 +300,7 @@ QString QgsLineString::asWkt( int precision ) const return wkt; } -QDomElement QgsLineString::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsLineString::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { QgsPointSequence pts; points( pts ); @@ -315,7 +315,7 @@ QDomElement QgsLineString::asGML2( QDomDocument &doc, int precision, const QStri return elemLineString; } -QDomElement QgsLineString::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsLineString::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QgsPointSequence pts; points( pts ); @@ -329,7 +329,7 @@ QDomElement QgsLineString::asGML3( QDomDocument &doc, int precision, const QStri return elemLineString; } -QString QgsLineString::asJSON( int precision ) const +QString QgsLineString::asJson( int precision ) const { QgsPointSequence pts; points( pts ); diff --git a/src/core/geometry/qgslinestring.h b/src/core/geometry/qgslinestring.h index 7c2c4a90cc57..76380c3c169c 100644 --- a/src/core/geometry/qgslinestring.h +++ b/src/core/geometry/qgslinestring.h @@ -186,9 +186,9 @@ class CORE_EXPORT QgsLineString: public QgsCurve QByteArray asWkb() const override; QString asWkt( int precision = 17 ) const override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; //curve interface double length() const override; diff --git a/src/core/geometry/qgsmulticurve.cpp b/src/core/geometry/qgsmulticurve.cpp index d9e867b94380..60193ed3e29c 100644 --- a/src/core/geometry/qgsmulticurve.cpp +++ b/src/core/geometry/qgsmulticurve.cpp @@ -63,7 +63,7 @@ bool QgsMultiCurve::fromWkt( const QString &wkt ) QStringLiteral( "LineString" ) ); } -QDomElement QgsMultiCurve::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsMultiCurve::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { // GML2 does not support curves QDomElement elemMultiLineString = doc.createElementNS( ns, QStringLiteral( "MultiLineString" ) ); @@ -78,7 +78,7 @@ QDomElement QgsMultiCurve::asGML2( QDomDocument &doc, int precision, const QStri std::unique_ptr< QgsLineString > lineString( static_cast( geom )->curveToLine() ); QDomElement elemLineStringMember = doc.createElementNS( ns, QStringLiteral( "lineStringMember" ) ); - elemLineStringMember.appendChild( lineString->asGML2( doc, precision, ns ) ); + elemLineStringMember.appendChild( lineString->asGml2( doc, precision, ns ) ); elemMultiLineString.appendChild( elemLineStringMember ); } } @@ -86,7 +86,7 @@ QDomElement QgsMultiCurve::asGML2( QDomDocument &doc, int precision, const QStri return elemMultiLineString; } -QDomElement QgsMultiCurve::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsMultiCurve::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemMultiCurve = doc.createElementNS( ns, QStringLiteral( "MultiCurve" ) ); @@ -100,7 +100,7 @@ QDomElement QgsMultiCurve::asGML3( QDomDocument &doc, int precision, const QStri const QgsCurve *curve = static_cast( geom ); QDomElement elemCurveMember = doc.createElementNS( ns, QStringLiteral( "curveMember" ) ); - elemCurveMember.appendChild( curve->asGML3( doc, precision, ns ) ); + elemCurveMember.appendChild( curve->asGml3( doc, precision, ns ) ); elemMultiCurve.appendChild( elemCurveMember ); } } @@ -108,7 +108,7 @@ QDomElement QgsMultiCurve::asGML3( QDomDocument &doc, int precision, const QStri return elemMultiCurve; } -QString QgsMultiCurve::asJSON( int precision ) const +QString QgsMultiCurve::asJson( int precision ) const { // GeoJSON does not support curves QString json = QStringLiteral( "{\"type\": \"MultiLineString\", \"coordinates\": [" ); diff --git a/src/core/geometry/qgsmulticurve.h b/src/core/geometry/qgsmulticurve.h index 5bb310d7e541..79d25c831dd0 100644 --- a/src/core/geometry/qgsmulticurve.h +++ b/src/core/geometry/qgsmulticurve.h @@ -35,9 +35,9 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection void clear() override; QgsMultiCurve *toCurveType() const override SIP_FACTORY; bool fromWkt( const QString &wkt ) override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER ) override; bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index ) override; diff --git a/src/core/geometry/qgsmultilinestring.cpp b/src/core/geometry/qgsmultilinestring.cpp index f96bade3743e..3afb5a9acce5 100644 --- a/src/core/geometry/qgsmultilinestring.cpp +++ b/src/core/geometry/qgsmultilinestring.cpp @@ -55,7 +55,7 @@ bool QgsMultiLineString::fromWkt( const QString &wkt ) return fromCollectionWkt( wkt, QVector() << new QgsLineString, QStringLiteral( "LineString" ) ); } -QDomElement QgsMultiLineString::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsMultiLineString::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemMultiLineString = doc.createElementNS( ns, QStringLiteral( "MultiLineString" ) ); @@ -67,7 +67,7 @@ QDomElement QgsMultiLineString::asGML2( QDomDocument &doc, int precision, const if ( const QgsLineString *lineString = qgsgeometry_cast( geom ) ) { QDomElement elemLineStringMember = doc.createElementNS( ns, QStringLiteral( "lineStringMember" ) ); - elemLineStringMember.appendChild( lineString->asGML2( doc, precision, ns ) ); + elemLineStringMember.appendChild( lineString->asGml2( doc, precision, ns ) ); elemMultiLineString.appendChild( elemLineStringMember ); } } @@ -75,7 +75,7 @@ QDomElement QgsMultiLineString::asGML2( QDomDocument &doc, int precision, const return elemMultiLineString; } -QDomElement QgsMultiLineString::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsMultiLineString::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemMultiCurve = doc.createElementNS( ns, QStringLiteral( "MultiCurve" ) ); @@ -87,7 +87,7 @@ QDomElement QgsMultiLineString::asGML3( QDomDocument &doc, int precision, const if ( const QgsLineString *lineString = qgsgeometry_cast( geom ) ) { QDomElement elemCurveMember = doc.createElementNS( ns, QStringLiteral( "curveMember" ) ); - elemCurveMember.appendChild( lineString->asGML3( doc, precision, ns ) ); + elemCurveMember.appendChild( lineString->asGml3( doc, precision, ns ) ); elemMultiCurve.appendChild( elemCurveMember ); } } @@ -95,7 +95,7 @@ QDomElement QgsMultiLineString::asGML3( QDomDocument &doc, int precision, const return elemMultiCurve; } -QString QgsMultiLineString::asJSON( int precision ) const +QString QgsMultiLineString::asJson( int precision ) const { QString json = QStringLiteral( "{\"type\": \"MultiLineString\", \"coordinates\": [" ); for ( const QgsAbstractGeometry *geom : mGeometries ) diff --git a/src/core/geometry/qgsmultilinestring.h b/src/core/geometry/qgsmultilinestring.h index cd36340494e9..c0bb1a1c32dd 100644 --- a/src/core/geometry/qgsmultilinestring.h +++ b/src/core/geometry/qgsmultilinestring.h @@ -35,9 +35,9 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve QgsMultiLineString *clone() const override SIP_FACTORY; void clear() override; bool fromWkt( const QString &wkt ) override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER ) override; bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index ) override; diff --git a/src/core/geometry/qgsmultipoint.cpp b/src/core/geometry/qgsmultipoint.cpp index 88c7db354cd7..5e7f8a15d46f 100644 --- a/src/core/geometry/qgsmultipoint.cpp +++ b/src/core/geometry/qgsmultipoint.cpp @@ -67,7 +67,7 @@ void QgsMultiPoint::clear() mWkbType = QgsWkbTypes::MultiPoint; } -QDomElement QgsMultiPoint::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsMultiPoint::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemMultiPoint = doc.createElementNS( ns, QStringLiteral( "MultiPoint" ) ); @@ -79,7 +79,7 @@ QDomElement QgsMultiPoint::asGML2( QDomDocument &doc, int precision, const QStri if ( qgsgeometry_cast( geom ) ) { QDomElement elemPointMember = doc.createElementNS( ns, QStringLiteral( "pointMember" ) ); - elemPointMember.appendChild( geom->asGML2( doc, precision, ns ) ); + elemPointMember.appendChild( geom->asGml2( doc, precision, ns ) ); elemMultiPoint.appendChild( elemPointMember ); } } @@ -87,7 +87,7 @@ QDomElement QgsMultiPoint::asGML2( QDomDocument &doc, int precision, const QStri return elemMultiPoint; } -QDomElement QgsMultiPoint::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsMultiPoint::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemMultiPoint = doc.createElementNS( ns, QStringLiteral( "MultiPoint" ) ); @@ -99,7 +99,7 @@ QDomElement QgsMultiPoint::asGML3( QDomDocument &doc, int precision, const QStri if ( qgsgeometry_cast( geom ) ) { QDomElement elemPointMember = doc.createElementNS( ns, QStringLiteral( "pointMember" ) ); - elemPointMember.appendChild( geom->asGML3( doc, precision, ns ) ); + elemPointMember.appendChild( geom->asGml3( doc, precision, ns ) ); elemMultiPoint.appendChild( elemPointMember ); } } @@ -107,7 +107,7 @@ QDomElement QgsMultiPoint::asGML3( QDomDocument &doc, int precision, const QStri return elemMultiPoint; } -QString QgsMultiPoint::asJSON( int precision ) const +QString QgsMultiPoint::asJson( int precision ) const { QString json = QStringLiteral( "{\"type\": \"MultiPoint\", \"coordinates\": " ); diff --git a/src/core/geometry/qgsmultipoint.h b/src/core/geometry/qgsmultipoint.h index 2e242a6fdbeb..f7b4ca298678 100644 --- a/src/core/geometry/qgsmultipoint.h +++ b/src/core/geometry/qgsmultipoint.h @@ -36,9 +36,9 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection QgsMultiPoint *toCurveType() const override SIP_FACTORY; bool fromWkt( const QString &wkt ) override; void clear() override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; int nCoordinates() const override; bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER ) override; bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index ) override; diff --git a/src/core/geometry/qgsmultipolygon.cpp b/src/core/geometry/qgsmultipolygon.cpp index 312a9c59967b..95db0338810f 100644 --- a/src/core/geometry/qgsmultipolygon.cpp +++ b/src/core/geometry/qgsmultipolygon.cpp @@ -55,7 +55,7 @@ bool QgsMultiPolygon::fromWkt( const QString &wkt ) return fromCollectionWkt( wkt, QVector() << new QgsPolygon, QStringLiteral( "Polygon" ) ); } -QDomElement QgsMultiPolygon::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsMultiPolygon::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { // GML2 does not support curves QDomElement elemMultiPolygon = doc.createElementNS( ns, QStringLiteral( "MultiPolygon" ) ); @@ -68,7 +68,7 @@ QDomElement QgsMultiPolygon::asGML2( QDomDocument &doc, int precision, const QSt if ( qgsgeometry_cast( geom ) ) { QDomElement elemPolygonMember = doc.createElementNS( ns, QStringLiteral( "polygonMember" ) ); - elemPolygonMember.appendChild( geom->asGML2( doc, precision, ns ) ); + elemPolygonMember.appendChild( geom->asGml2( doc, precision, ns ) ); elemMultiPolygon.appendChild( elemPolygonMember ); } } @@ -76,7 +76,7 @@ QDomElement QgsMultiPolygon::asGML2( QDomDocument &doc, int precision, const QSt return elemMultiPolygon; } -QDomElement QgsMultiPolygon::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsMultiPolygon::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemMultiSurface = doc.createElementNS( ns, QStringLiteral( "MultiPolygon" ) ); @@ -88,7 +88,7 @@ QDomElement QgsMultiPolygon::asGML3( QDomDocument &doc, int precision, const QSt if ( qgsgeometry_cast( geom ) ) { QDomElement elemSurfaceMember = doc.createElementNS( ns, QStringLiteral( "polygonMember" ) ); - elemSurfaceMember.appendChild( geom->asGML3( doc, precision, ns ) ); + elemSurfaceMember.appendChild( geom->asGml3( doc, precision, ns ) ); elemMultiSurface.appendChild( elemSurfaceMember ); } } @@ -96,7 +96,7 @@ QDomElement QgsMultiPolygon::asGML3( QDomDocument &doc, int precision, const QSt return elemMultiSurface; } -QString QgsMultiPolygon::asJSON( int precision ) const +QString QgsMultiPolygon::asJson( int precision ) const { // GeoJSON does not support curves QString json = QStringLiteral( "{\"type\": \"MultiPolygon\", \"coordinates\": [" ); diff --git a/src/core/geometry/qgsmultipolygon.h b/src/core/geometry/qgsmultipolygon.h index 13b92c9f898a..092ad677ebd4 100644 --- a/src/core/geometry/qgsmultipolygon.h +++ b/src/core/geometry/qgsmultipolygon.h @@ -34,9 +34,9 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface void clear() override; QgsMultiPolygon *clone() const override SIP_FACTORY; bool fromWkt( const QString &wkt ) override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER ) override; bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index ) override; diff --git a/src/core/geometry/qgsmultisurface.cpp b/src/core/geometry/qgsmultisurface.cpp index 93251d75711d..903e710326fb 100644 --- a/src/core/geometry/qgsmultisurface.cpp +++ b/src/core/geometry/qgsmultisurface.cpp @@ -63,7 +63,7 @@ bool QgsMultiSurface::fromWkt( const QString &wkt ) QStringLiteral( "Polygon" ) ); } -QDomElement QgsMultiSurface::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsMultiSurface::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { // GML2 does not support curves QDomElement elemMultiPolygon = doc.createElementNS( ns, QStringLiteral( "MultiPolygon" ) ); @@ -78,7 +78,7 @@ QDomElement QgsMultiSurface::asGML2( QDomDocument &doc, int precision, const QSt std::unique_ptr< QgsPolygon > polygon( static_cast( geom )->surfaceToPolygon() ); QDomElement elemPolygonMember = doc.createElementNS( ns, QStringLiteral( "polygonMember" ) ); - elemPolygonMember.appendChild( polygon->asGML2( doc, precision, ns ) ); + elemPolygonMember.appendChild( polygon->asGml2( doc, precision, ns ) ); elemMultiPolygon.appendChild( elemPolygonMember ); } } @@ -86,7 +86,7 @@ QDomElement QgsMultiSurface::asGML2( QDomDocument &doc, int precision, const QSt return elemMultiPolygon; } -QDomElement QgsMultiSurface::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsMultiSurface::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemMultiSurface = doc.createElementNS( ns, QStringLiteral( "MultiSurface" ) ); @@ -98,7 +98,7 @@ QDomElement QgsMultiSurface::asGML3( QDomDocument &doc, int precision, const QSt if ( qgsgeometry_cast( geom ) ) { QDomElement elemSurfaceMember = doc.createElementNS( ns, QStringLiteral( "surfaceMember" ) ); - elemSurfaceMember.appendChild( geom->asGML3( doc, precision, ns ) ); + elemSurfaceMember.appendChild( geom->asGml3( doc, precision, ns ) ); elemMultiSurface.appendChild( elemSurfaceMember ); } } @@ -106,7 +106,7 @@ QDomElement QgsMultiSurface::asGML3( QDomDocument &doc, int precision, const QSt return elemMultiSurface; } -QString QgsMultiSurface::asJSON( int precision ) const +QString QgsMultiSurface::asJson( int precision ) const { // GeoJSON does not support curves QString json = QStringLiteral( "{\"type\": \"MultiPolygon\", \"coordinates\": [" ); diff --git a/src/core/geometry/qgsmultisurface.h b/src/core/geometry/qgsmultisurface.h index 0944f7d43eef..655f3aa5c685 100644 --- a/src/core/geometry/qgsmultisurface.h +++ b/src/core/geometry/qgsmultisurface.h @@ -35,9 +35,9 @@ class CORE_EXPORT QgsMultiSurface: public QgsGeometryCollection QgsMultiSurface *clone() const override SIP_FACTORY; QgsMultiSurface *toCurveType() const override SIP_FACTORY; bool fromWkt( const QString &wkt ) override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER ) override; bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index ) override; QgsAbstractGeometry *boundary() const override SIP_FACTORY; diff --git a/src/core/geometry/qgspoint.cpp b/src/core/geometry/qgspoint.cpp index 71df86b37555..b0f23b53d35a 100644 --- a/src/core/geometry/qgspoint.cpp +++ b/src/core/geometry/qgspoint.cpp @@ -247,7 +247,7 @@ QString QgsPoint::asWkt( int precision ) const return wkt; } -QDomElement QgsPoint::asGML2( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsPoint::asGml2( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral( "Point" ) ); QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral( "coordinates" ) ); @@ -266,7 +266,7 @@ QDomElement QgsPoint::asGML2( QDomDocument &doc, int precision, const QString &n return elemPoint; } -QDomElement QgsPoint::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsPoint::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral( "Point" ) ); QDomElement elemPosList = doc.createElementNS( ns, QStringLiteral( "pos" ) ); @@ -286,7 +286,7 @@ QDomElement QgsPoint::asGML3( QDomDocument &doc, int precision, const QString &n * See details in QEP #17 ****************************************************************************/ -QString QgsPoint::asJSON( int precision ) const +QString QgsPoint::asJson( int precision ) const { return "{\"type\": \"Point\", \"coordinates\": [" + qgsDoubleToString( mX, precision ) + ", " + qgsDoubleToString( mY, precision ) diff --git a/src/core/geometry/qgspoint.h b/src/core/geometry/qgspoint.h index 217f36215b6d..9d41bd439c4e 100644 --- a/src/core/geometry/qgspoint.h +++ b/src/core/geometry/qgspoint.h @@ -56,10 +56,10 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry * * \code{.py} * pt = QgsPoint(43.4, 5.3) - * pt.exportToWkt() # Point(43.4 5.3) + * pt.asWkt() # Point(43.4 5.3) * * pt_z = QgsPoint(120, 343, 77) - * pt.exportToWkt() # PointZ(120 343 77) + * pt.asWkt() # PointZ(120 343 77) * * pt_m = QgsPoint(33, 88, m=5) * pt_m.m() # 5 @@ -397,9 +397,9 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry bool fromWkt( const QString &wkt ) override; QByteArray asWkb() const override; QString asWkt( int precision = 17 ) const override; - QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - QString asJSON( int precision = 17 ) const override; + QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; + QString asJson( int precision = 17 ) const override; void draw( QPainter &p ) const override; void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) override; diff --git a/src/core/geometry/qgstriangle.cpp b/src/core/geometry/qgstriangle.cpp index 47f6ad2c7f66..97860bfd9473 100644 --- a/src/core/geometry/qgstriangle.cpp +++ b/src/core/geometry/qgstriangle.cpp @@ -211,7 +211,7 @@ bool QgsTriangle::fromWkt( const QString &wkt ) return true; } -QDomElement QgsTriangle::asGML3( QDomDocument &doc, int precision, const QString &ns ) const +QDomElement QgsTriangle::asGml3( QDomDocument &doc, int precision, const QString &ns ) const { QDomElement elemTriangle = doc.createElementNS( ns, QStringLiteral( "Triangle" ) ); @@ -220,7 +220,7 @@ QDomElement QgsTriangle::asGML3( QDomDocument &doc, int precision, const QString return elemTriangle; QDomElement elemExterior = doc.createElementNS( ns, QStringLiteral( "exterior" ) ); - QDomElement curveElem = exteriorRing()->asGML3( doc, precision, ns ); + QDomElement curveElem = exteriorRing()->asGml3( doc, precision, ns ); if ( curveElem.tagName() == QLatin1String( "LineString" ) ) { curveElem.setTagName( QStringLiteral( "LinearRing" ) ); diff --git a/src/core/geometry/qgstriangle.h b/src/core/geometry/qgstriangle.h index 41482a4a9e0f..904fcbf35e7c 100644 --- a/src/core/geometry/qgstriangle.h +++ b/src/core/geometry/qgstriangle.h @@ -72,8 +72,7 @@ class CORE_EXPORT QgsTriangle : public QgsPolygon // inherited: QString asWkt( int precision = 17 ) const; // inherited (as a polygon): QDomElement asGML2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const; - QDomElement asGML3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; - // inherited: QString asJSON( int precision = 17 ) const; + QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override; QgsPolygon *surfaceToPolygon() const override SIP_FACTORY; diff --git a/src/core/layout/qgslayoutitemmapgrid.cpp b/src/core/layout/qgslayoutitemmapgrid.cpp index f11bef927865..3670781b5863 100644 --- a/src/core/layout/qgslayoutitemmapgrid.cpp +++ b/src/core/layout/qgslayoutitemmapgrid.cpp @@ -33,6 +33,7 @@ #include "qgsexpressioncontext.h" #include "qgsexception.h" #include "qgssettings.h" +#include "qgscoordinateformatter.h" #include #include @@ -1410,49 +1411,56 @@ QString QgsLayoutItemMapGrid::gridAnnotationString( double value, QgsLayoutItemM return mGridAnnotationExpression->evaluate( &expressionContext ).toString(); } - QgsPointXY p; - p.setX( coord == QgsLayoutItemMapGrid::Longitude ? value : 0 ); - p.setY( coord == QgsLayoutItemMapGrid::Longitude ? 0 : value ); - - QString annotationString; - if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinute ) - { - annotationString = p.toDegreesMinutes( mGridAnnotationPrecision ); - } - else if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinuteNoSuffix ) - { - annotationString = p.toDegreesMinutes( mGridAnnotationPrecision, false ); - } - else if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinutePadded ) - { - annotationString = p.toDegreesMinutes( mGridAnnotationPrecision, true, true ); - } - else if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinuteSecond ) + QgsCoordinateFormatter::Format format = QgsCoordinateFormatter::FormatDecimalDegrees; + QgsCoordinateFormatter::FormatFlags flags = 0; + switch ( mGridAnnotationFormat ) { - annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision ); - } - else if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinuteSecondNoSuffix ) - { - annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision, false ); - } - else if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinuteSecondPadded ) - { - annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision, true, true ); - } + case Decimal: + case DecimalWithSuffix: + case CustomFormat: + break; // already handled above - QStringList split = annotationString.split( ',' ); - if ( coord == QgsLayoutItemMapGrid::Longitude ) - { - return split.at( 0 ); + case DegreeMinute: + format = QgsCoordinateFormatter::FormatDegreesMinutes; + flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix; + break; + + case DegreeMinuteSecond: + format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds; + flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix; + break; + + case DegreeMinuteNoSuffix: + format = QgsCoordinateFormatter::FormatDegreesMinutes; + flags = 0; + break; + + case DegreeMinutePadded: + format = QgsCoordinateFormatter::FormatDegreesMinutes; + flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix | QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds; + break; + + case DegreeMinuteSecondNoSuffix: + format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds; + flags = 0; + break; + + case DegreeMinuteSecondPadded: + format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds; + flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix | QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds; + break; } - else + + switch ( coord ) { - if ( split.size() < 2 ) - { - return QLatin1String( "" ); - } - return split.at( 1 ); + case Longitude: + return QgsCoordinateFormatter::formatX( value, format, flags ); + + case Latitude: + return QgsCoordinateFormatter::formatY( value, format, flags ); } + + return QString(); // no warnings } int QgsLayoutItemMapGrid::xGridLines( QList< QPair< double, QLineF > > &lines ) const diff --git a/src/core/qgscoordinateformatter.cpp b/src/core/qgscoordinateformatter.cpp new file mode 100644 index 000000000000..204a0b3f26b5 --- /dev/null +++ b/src/core/qgscoordinateformatter.cpp @@ -0,0 +1,448 @@ +/*************************************************************************** + qgscoordinateformatter.cpp + -------------------------- + begin : Decemeber 2015 + copyright : (C) 2015 by Nyall Dawson + email : nyall dot dawson at gmail dot com +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgscoordinateformatter.h" +#include "qgis.h" + +#include // for tr() + +QString QgsCoordinateFormatter::formatX( double x, QgsCoordinateFormatter::Format format, int precision, FormatFlags flags ) +{ + switch ( format ) + { + case FormatPair: + return formatAsPair( x, precision ); + + case FormatDegreesMinutesSeconds: + return formatXAsDegreesMinutesSeconds( x, precision, flags ); + + case FormatDegreesMinutes: + return formatXAsDegreesMinutes( x, precision, flags ); + + case FormatDecimalDegrees: + return formatXAsDegrees( x, precision, flags ); + } + return QString(); //avoid warnings +} + +QString QgsCoordinateFormatter::formatY( double y, QgsCoordinateFormatter::Format format, int precision, FormatFlags flags ) +{ + switch ( format ) + { + case FormatPair: + return formatAsPair( y, precision ); + + case FormatDegreesMinutesSeconds: + return formatYAsDegreesMinutesSeconds( y, precision, flags ); + + case FormatDegreesMinutes: + return formatYAsDegreesMinutes( y, precision, flags ); + + case FormatDecimalDegrees: + return formatYAsDegrees( y, precision, flags ); + } + return QString(); //avoid warnings +} + +QString QgsCoordinateFormatter::format( QgsPointXY point, QgsCoordinateFormatter::Format format, int precision, FormatFlags flags ) +{ + return QStringLiteral( "%1,%2" ).arg( formatX( point.x(), format, precision, flags ), + formatY( point.x(), format, precision, flags ) ); +} + +QString QgsCoordinateFormatter::asPair( double x, double y, int precision ) +{ + QString s = formatAsPair( x, precision ); + s += ','; + s += formatAsPair( y, precision ); + return s; +} + +QString QgsCoordinateFormatter::formatAsPair( double val, int precision ) +{ + return std::isfinite( val ) ? QString::number( val, 'f', precision ) : QObject::tr( "infinite" ); +} + +QString QgsCoordinateFormatter::formatXAsDegreesMinutesSeconds( double val, int precision, FormatFlags flags ) +{ + //first, limit longitude to -360 to 360 degree range + double wrappedX = std::fmod( val, 360.0 ); + //next, wrap around longitudes > 180 or < -180 degrees, so that eg "190E" -> "170W" + if ( wrappedX > 180.0 ) + { + wrappedX = wrappedX - 360.0; + } + else if ( wrappedX < -180.0 ) + { + wrappedX = wrappedX + 360.0; + } + + int precisionMultiplier = std::pow( 10.0, precision ); + + int degreesX = int( std::fabs( wrappedX ) ); + double floatMinutesX = ( std::fabs( wrappedX ) - degreesX ) * 60.0; + int intMinutesX = int( floatMinutesX ); + double secondsX = ( floatMinutesX - intMinutesX ) * 60.0; + + //make sure rounding to specified precision doesn't create seconds >= 60 + if ( std::round( secondsX * precisionMultiplier ) >= 60 * precisionMultiplier ) + { + secondsX = std::max( secondsX - 60, 0.0 ); + intMinutesX++; + if ( intMinutesX >= 60 ) + { + intMinutesX -= 60; + degreesX++; + } + } + + QString hemisphere; + QString sign; + if ( flags.testFlag( FlagDegreesUseStringSuffix ) ) + { + hemisphere = wrappedX < 0 ? QObject::tr( "W" ) : QObject::tr( "E" ); + } + else + { + if ( wrappedX < 0 ) + { + sign = QObject::tr( "-" ); + } + } + //check if coordinate is all zeros for the specified precision, and if so, + //remove the sign and hemisphere strings + if ( degreesX == 0 && intMinutesX == 0 && std::round( secondsX * precisionMultiplier ) == 0 ) + { + sign.clear(); + hemisphere.clear(); + } + + //also remove directional prefix from 180 degree longitudes + if ( degreesX == 180 && intMinutesX == 0 && std::round( secondsX * precisionMultiplier ) == 0 ) + { + hemisphere.clear(); + } + + QString minutesX; + QString strSecondsX; + + //pad with leading digits if required + if ( flags.testFlag( FlagDegreesPadMinutesSeconds ) ) + { + minutesX = QString( "%1" ).arg( intMinutesX, 2, 10, QChar( '0' ) ); + int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); //1 for decimal place if required + strSecondsX = QString( "%1" ).arg( secondsX, digits, 'f', precision, QChar( '0' ) ); + } + else + { + minutesX = QString::number( intMinutesX ); + strSecondsX = QString::number( secondsX, 'f', precision ); + } + + return sign + QString::number( degreesX ) + QChar( 176 ) + + minutesX + QChar( 0x2032 ) + + strSecondsX + QChar( 0x2033 ) + + hemisphere; +} + +QString QgsCoordinateFormatter::formatYAsDegreesMinutesSeconds( double val, int precision, FormatFlags flags ) +{ + //first, limit latitude to -180 to 180 degree range + double wrappedY = std::fmod( val, 180.0 ); + //next, wrap around latitudes > 90 or < -90 degrees, so that eg "110S" -> "70N" + if ( wrappedY > 90.0 ) + { + wrappedY = wrappedY - 180.0; + } + else if ( wrappedY < -90.0 ) + { + wrappedY = wrappedY + 180.0; + } + + int precisionMultiplier = std::pow( 10.0, precision ); + + int degreesY = int( std::fabs( wrappedY ) ); + double floatMinutesY = ( std::fabs( wrappedY ) - degreesY ) * 60.0; + int intMinutesY = int( floatMinutesY ); + double secondsY = ( floatMinutesY - intMinutesY ) * 60.0; + + //make sure rounding to specified precision doesn't create seconds >= 60 + if ( std::round( secondsY * precisionMultiplier ) >= 60 * precisionMultiplier ) + { + secondsY = std::max( secondsY - 60, 0.0 ); + intMinutesY++; + if ( intMinutesY >= 60 ) + { + intMinutesY -= 60; + degreesY++; + } + } + + QString hemisphere; + QString sign; + if ( flags.testFlag( FlagDegreesUseStringSuffix ) ) + { + hemisphere = wrappedY < 0 ? QObject::tr( "S" ) : QObject::tr( "N" ); + } + else + { + if ( wrappedY < 0 ) + { + sign = QObject::tr( "-" ); + } + } + //check if coordinate is all zeros for the specified precision, and if so, + //remove the sign and hemisphere strings + if ( degreesY == 0 && intMinutesY == 0 && std::round( secondsY * precisionMultiplier ) == 0 ) + { + sign = QString(); + hemisphere.clear(); + } + + QString strMinutesY; + QString strSecondsY; + + //pad with leading digits if required + if ( flags.testFlag( FlagDegreesPadMinutesSeconds ) ) + { + strMinutesY = QString( "%1" ).arg( intMinutesY, 2, 10, QChar( '0' ) ); + int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); //1 for decimal place if required + strSecondsY = QString( "%1" ).arg( secondsY, digits, 'f', precision, QChar( '0' ) ); + } + else + { + strMinutesY = QString::number( intMinutesY ); + strSecondsY = QString::number( secondsY, 'f', precision ); + } + + return sign + QString::number( degreesY ) + QChar( 176 ) + + strMinutesY + QChar( 0x2032 ) + + strSecondsY + QChar( 0x2033 ) + + hemisphere; +} + +QString QgsCoordinateFormatter::formatXAsDegreesMinutes( double val, int precision, FormatFlags flags ) +{ + //first, limit longitude to -360 to 360 degree range + double wrappedX = std::fmod( val, 360.0 ); + //next, wrap around longitudes > 180 or < -180 degrees, so that eg "190E" -> "170W" + if ( wrappedX > 180.0 ) + { + wrappedX = wrappedX - 360.0; + } + else if ( wrappedX < -180.0 ) + { + wrappedX = wrappedX + 360.0; + } + + int degreesX = int( std::fabs( wrappedX ) ); + double floatMinutesX = ( std::fabs( wrappedX ) - degreesX ) * 60.0; + + int precisionMultiplier = std::pow( 10.0, precision ); + + //make sure rounding to specified precision doesn't create minutes >= 60 + if ( std::round( floatMinutesX * precisionMultiplier ) >= 60 * precisionMultiplier ) + { + floatMinutesX = std::max( floatMinutesX - 60, 0.0 ); + degreesX++; + } + + QString hemisphere; + QString sign; + if ( flags.testFlag( FlagDegreesUseStringSuffix ) ) + { + hemisphere = wrappedX < 0 ? QObject::tr( "W" ) : QObject::tr( "E" ); + } + else + { + if ( wrappedX < 0 ) + { + sign = QObject::tr( "-" ); + } + } + //check if coordinate is all zeros for the specified precision, and if so, + //remove the sign and hemisphere strings + if ( degreesX == 0 && std::round( floatMinutesX * precisionMultiplier ) == 0 ) + { + sign.clear(); + hemisphere.clear(); + } + + //also remove directional prefix from 180 degree longitudes + if ( degreesX == 180 && std::round( floatMinutesX * precisionMultiplier ) == 0 ) + { + hemisphere.clear(); + } + + //pad minutes with leading digits if required + int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); //1 for decimal place if required + QString strMinutesX = flags.testFlag( FlagDegreesPadMinutesSeconds ) ? QString( "%1" ).arg( floatMinutesX, digits, 'f', precision, QChar( '0' ) ) + : QString::number( floatMinutesX, 'f', precision ); + + return sign + QString::number( degreesX ) + QChar( 176 ) + + strMinutesX + QChar( 0x2032 ) + + hemisphere; +} + +QString QgsCoordinateFormatter::formatYAsDegreesMinutes( double val, int precision, FormatFlags flags ) +{ + //first, limit latitude to -180 to 180 degree range + double wrappedY = std::fmod( val, 180.0 ); + //next, wrap around latitudes > 90 or < -90 degrees, so that eg "110S" -> "70N" + if ( wrappedY > 90.0 ) + { + wrappedY = wrappedY - 180.0; + } + else if ( wrappedY < -90.0 ) + { + wrappedY = wrappedY + 180.0; + } + + int degreesY = int( std::fabs( wrappedY ) ); + double floatMinutesY = ( std::fabs( wrappedY ) - degreesY ) * 60.0; + + int precisionMultiplier = std::pow( 10.0, precision ); + + //make sure rounding to specified precision doesn't create minutes >= 60 + if ( std::round( floatMinutesY * precisionMultiplier ) >= 60 * precisionMultiplier ) + { + floatMinutesY = std::max( floatMinutesY - 60, 0.0 ); + degreesY++; + } + + QString hemisphere; + QString sign; + if ( flags.testFlag( FlagDegreesUseStringSuffix ) ) + { + hemisphere = wrappedY < 0 ? QObject::tr( "S" ) : QObject::tr( "N" ); + } + else + { + if ( wrappedY < 0 ) + { + sign = QObject::tr( "-" ); + } + } + //check if coordinate is all zeros for the specified precision, and if so, + //remove the sign and hemisphere strings + if ( degreesY == 0 && std::round( floatMinutesY * precisionMultiplier ) == 0 ) + { + sign.clear(); + hemisphere.clear(); + } + + + //pad minutes with leading digits if required + int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); //1 for decimal place if required + QString strMinutesY = flags.testFlag( FlagDegreesPadMinutesSeconds ) ? QString( "%1" ).arg( floatMinutesY, digits, 'f', precision, QChar( '0' ) ) + : QString::number( floatMinutesY, 'f', precision ); + + return sign + QString::number( degreesY ) + QChar( 176 ) + + strMinutesY + QChar( 0x2032 ) + + hemisphere; +} + +QString QgsCoordinateFormatter::formatXAsDegrees( double val, int precision, FormatFlags flags ) +{ + //first, limit longitude to -360 to 360 degree range + double wrappedX = std::fmod( val, 360.0 ); + //next, wrap around longitudes > 180 or < -180 degrees, so that eg "190E" -> "170W" + if ( wrappedX > 180.0 ) + { + wrappedX = wrappedX - 360.0; + } + else if ( wrappedX < -180.0 ) + { + wrappedX = wrappedX + 360.0; + } + + double absX = std::fabs( wrappedX ); + + int precisionMultiplier = std::pow( 10.0, precision ); + + QString hemisphere; + QString sign; + if ( flags.testFlag( FlagDegreesUseStringSuffix ) ) + { + hemisphere = wrappedX < 0 ? QObject::tr( "W" ) : QObject::tr( "E" ); + } + else + { + if ( wrappedX < 0 ) + { + sign = QObject::tr( "-" ); + } + } + //check if coordinate is all zeros for the specified precision, and if so, + //remove the sign and hemisphere strings + if ( std::round( absX * precisionMultiplier ) == 0 ) + { + sign.clear(); + hemisphere.clear(); + } + + //also remove directional prefix from 180 degree longitudes + if ( std::round( absX * precisionMultiplier ) == 180 * precisionMultiplier ) + { + sign.clear(); + hemisphere.clear(); + } + + return sign + QString::number( absX, 'f', precision ) + QChar( 176 ) + hemisphere; +} + +QString QgsCoordinateFormatter::formatYAsDegrees( double val, int precision, FormatFlags flags ) +{ + //first, limit latitude to -180 to 180 degree range + double wrappedY = std::fmod( val, 180.0 ); + //next, wrap around latitudes > 90 or < -90 degrees, so that eg "110S" -> "70N" + if ( wrappedY > 90.0 ) + { + wrappedY = wrappedY - 180.0; + } + else if ( wrappedY < -90.0 ) + { + wrappedY = wrappedY + 180.0; + } + + double absY = std::fabs( wrappedY ); + + int precisionMultiplier = std::pow( 10.0, precision ); + + QString hemisphere; + QString sign; + if ( flags.testFlag( FlagDegreesUseStringSuffix ) ) + { + hemisphere = wrappedY < 0 ? QObject::tr( "S" ) : QObject::tr( "N" ); + } + else + { + if ( wrappedY < 0 ) + { + sign = QObject::tr( "-" ); + } + } + //check if coordinate is all zeros for the specified precision, and if so, + //remove the sign and hemisphere strings + if ( std::round( absY * precisionMultiplier ) == 0 ) + { + sign.clear(); + hemisphere.clear(); + } + + return sign + QString::number( absY, 'f', precision ) + QChar( 176 ) + hemisphere; +} diff --git a/src/core/qgscoordinateformatter.h b/src/core/qgscoordinateformatter.h new file mode 100644 index 000000000000..e5a4ed3c698e --- /dev/null +++ b/src/core/qgscoordinateformatter.h @@ -0,0 +1,124 @@ +/*************************************************************************** + qgscoordinateformatter.h + ------------------------ + begin : Decemeber 2015 + copyright : (C) 2015 by Nyall Dawson + email : nyall dot dawson at gmail dot com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSCOORDINATEFORMATTER_H +#define QGSCOORDINATEFORMATTER_H + +#include +#include "qgis.h" +#include "qgspointxy.h" + +/** + * \ingroup core + * \class QgsCoordinateFormatter + * \brief Contains methods for converting coordinates for display in various formats. + * + * QgsCoordinateFormatter contains static methods for converting numeric coordinates into different + * formats, for instance as degrees, minutes, seconds values. Note that QgsCoordinateFormatter has + * no consideration for the validity of converting coordinates to the various display formats, and it + * is up to the caller to ensure that sensible formats are used for particular coordinates. For instance, + * ensuring that only geographic coordinates and not projected coordinates are formatted to degree + * based formats. + * + * \since QGIS 3.0 + */ + +class CORE_EXPORT QgsCoordinateFormatter +{ + public: + + /** + * Available formats for displaying coordinates. + */ + enum Format + { + FormatPair, //!< Formats coordinates as an "x,y" pair + FormatDegreesMinutesSeconds, //!< Degrees, minutes and seconds, eg 30 degrees 45'30" + FormatDegreesMinutes, //!< Degrees and decimal minutes, eg 30degrees 45.55' + FormatDecimalDegrees, //!< Decimal degrees, eg 30.7555 degrees + }; + + /** + * Flags for controlling formatting of coordinates. + */ + enum FormatFlag + { + FlagDegreesUseStringSuffix = 1 << 1, //!< Include a direction suffix (eg 'N', 'E', 'S' or 'W'), otherwise a "-" prefix is used for west and south coordinates + FlagDegreesPadMinutesSeconds = 1 << 2, //!< Pad minute and second values with leading zeros, eg '05' instead of '5' + }; + Q_DECLARE_FLAGS( FormatFlags, FormatFlag ) + + /** + * Formats an \a x coordinate value according to the specified parameters. + * + * The \a format argument indicates the desired display format for the coordinate. + * + * The \a precision argument gives the number of decimal places to include for coordinates. + * + * Optional \a flags can be specified to control the output format. + * + * \see formatY() + */ + static QString formatX( double x, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix ); + + /** + * Formats a \a y coordinate value according to the specified parameters. + * + * The \a format argument indicates the desired display format for the coordinate. + * + * The \a precision argument gives the number of decimal places to include for coordinates. + * + * Optional \a flags can be specified to control the output format. + * + * \see formatX() + */ + static QString formatY( double y, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix ); + + /** + * Formats a \a point according to the specified parameters. + * + * The \a format argument indicates the desired display format for the coordinate. + * + * The \a precision argument gives the number of decimal places to include for coordinates. + * + * Optional \a flags can be specified to control the output format. + */ + static QString format( QgsPointXY point, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix ); + + /** + * Formats coordinates as an "\a x,\a y" pair, with optional decimal \a precision (number + * of decimal places to include). + */ + static QString asPair( double x, double y, int precision = 12 ); + + private: + + static QString formatAsPair( double val, int precision ); + + static QString formatXAsDegreesMinutesSeconds( double val, int precision, FormatFlags flags ); + static QString formatYAsDegreesMinutesSeconds( double val, int precision, FormatFlags flags ); + + static QString formatXAsDegreesMinutes( double val, int precision, FormatFlags flags ); + static QString formatYAsDegreesMinutes( double val, int precision, FormatFlags flags ); + + static QString formatXAsDegrees( double val, int precision, FormatFlags flags ); + static QString formatYAsDegrees( double val, int precision, FormatFlags flags ); +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS( QgsCoordinateFormatter::FormatFlags ) + +#endif // QGSCOORDINATEFORMATTER_H diff --git a/src/core/qgscoordinateutils.cpp b/src/core/qgscoordinateutils.cpp index 319666518aec..40082c37d77e 100644 --- a/src/core/qgscoordinateutils.cpp +++ b/src/core/qgscoordinateutils.cpp @@ -21,7 +21,7 @@ #include "qgsproject.h" #include "qgis.h" #include "qgsexception.h" - +#include "qgscoordinateformatter.h" ///@cond NOT_STABLE_API int QgsCoordinateUtils::calculateCoordinatePrecision( double mapUnitsPerPixel, const QgsCoordinateReferenceSystem &mapCrs ) @@ -85,16 +85,16 @@ QString QgsCoordinateUtils::formatCoordinateForProject( const QgsPointXY &point, } if ( format == QLatin1String( "DM" ) ) - return geo.toDegreesMinutes( precision, true, true ); + return QgsCoordinateFormatter::format( geo, QgsCoordinateFormatter::FormatDegreesMinutes, precision, QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter::FlagDegreesUseStringSuffix ); else if ( format == QLatin1String( "DMS" ) ) - return geo.toDegreesMinutesSeconds( precision, true, true ); + return QgsCoordinateFormatter::format( geo, QgsCoordinateFormatter::FormatDegreesMinutesSeconds, precision, QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter::FlagDegreesUseStringSuffix ); else - return geo.toString( precision ); + return QgsCoordinateFormatter::asPair( geo.x(), geo.y(), precision ); } else { // coordinates in map units - return point.toString( precision ); + return QgsCoordinateFormatter::asPair( point.x(), point.y(), precision ); } } diff --git a/src/core/qgsdistancearea.cpp b/src/core/qgsdistancearea.cpp index 0d97aa0f052a..099522022033 100644 --- a/src/core/qgsdistancearea.cpp +++ b/src/core/qgsdistancearea.cpp @@ -368,8 +368,8 @@ double QgsDistanceArea::measureLineProjected( const QgsPointXY &p1, double dista .arg( ( ( mCoordTransform.sourceCrs().isGeographic() ) == 1 ? QString( "Geographic" ) : QString( "Cartesian" ) ) ) .arg( QgsUnitTypes::toString( sourceCrs().mapUnits() ) ) .arg( azimuth ) - .arg( p1.wellKnownText() ) - .arg( p2.wellKnownText() ) + .arg( p1.asWkt() ) + .arg( p2.asWkt() ) .arg( sourceCrs().description() ) .arg( mEllipsoid ) .arg( sourceCrs().isGeographic() ) diff --git a/src/core/qgsfeature.cpp b/src/core/qgsfeature.cpp index 37d892d8e57c..a648036e6f04 100644 --- a/src/core/qgsfeature.cpp +++ b/src/core/qgsfeature.cpp @@ -317,7 +317,7 @@ uint qHash( const QgsFeature &key, uint seed ) hash ^= qHash( attr.toString() ); } - hash ^= qHash( key.geometry().exportToWkt() ); + hash ^= qHash( key.geometry().asWkt() ); hash ^= qHash( key.id() ); return hash; diff --git a/src/core/qgsjsonutils.cpp b/src/core/qgsjsonutils.cpp index 36d59554da9e..10412c9c40a3 100644 --- a/src/core/qgsjsonutils.cpp +++ b/src/core/qgsjsonutils.cpp @@ -101,7 +101,7 @@ QString QgsJsonExporter::exportFeature( const QgsFeature &feature, const QVarian qgsDoubleToString( box.yMaximum(), mPrecision ) ); } s += QLatin1String( " \"geometry\":\n " ); - s += geom.exportToGeoJSON( mPrecision ); + s += geom.asJson( mPrecision ); s += QLatin1String( ",\n" ); } else diff --git a/src/core/qgsofflineediting.cpp b/src/core/qgsofflineediting.cpp index 76318abfeb7c..f22b1d313e24 100644 --- a/src/core/qgsofflineediting.cpp +++ b/src/core/qgsofflineediting.cpp @@ -1377,7 +1377,7 @@ void QgsOfflineEditing::committedGeometriesChanges( const QString &qgisLayerId, .arg( layerId ) .arg( commitNo ) .arg( fid ) - .arg( geom.exportToWkt() ); + .arg( geom.asWkt() ); sqlExec( database.get(), sql ); // TODO: use WKB instead of WKT? diff --git a/src/core/qgsogcutils.cpp b/src/core/qgsogcutils.cpp index 52c36ca2483a..c0e41af62630 100644 --- a/src/core/qgsogcutils.cpp +++ b/src/core/qgsogcutils.cpp @@ -1146,7 +1146,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry &geometry, QDomDocumen bool hasZValue = false; - QByteArray wkb( geometry.exportToWkb() ); + QByteArray wkb( geometry.asWkb() ); QgsConstWkbPtr wkbPtr( wkb ); try { diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index cff1418d9065..68d8aad63a12 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -2912,7 +2912,7 @@ QgsGeometry QgsPalLabeling::prepareGeometry( const QgsGeometry &geometry, QgsRen if ( geom.rotate( m2p.mapRotation(), center ) ) { - QgsDebugMsg( QString( "Error rotating geometry" ).arg( geom.exportToWkt() ) ); + QgsDebugMsg( QString( "Error rotating geometry" ).arg( geom.asWkt() ) ); return QgsGeometry(); } } diff --git a/src/core/qgspointlocator.cpp b/src/core/qgspointlocator.cpp index e070bcc8a69d..9c87bd3c669b 100644 --- a/src/core/qgspointlocator.cpp +++ b/src/core/qgspointlocator.cpp @@ -331,7 +331,7 @@ static QgsPointLocator::MatchList _geometrySegmentsInRect( QgsGeometry *geom, co // we need iterator for segments... QgsPointLocator::MatchList lst; - QByteArray wkb( geom->exportToWkb() ); + QByteArray wkb( geom->asWkb() ); if ( wkb.isEmpty() ) return lst; diff --git a/src/core/qgspointxy.cpp b/src/core/qgspointxy.cpp index d416e400ef50..2e7c7e8cb056 100644 --- a/src/core/qgspointxy.cpp +++ b/src/core/qgspointxy.cpp @@ -42,221 +42,25 @@ QPointF QgsPointXY::toQPointF() const return QPointF( mX, mY ); } -QString QgsPointXY::toString() const -{ - QString rep; - QTextStream ot( &rep ); - ot.setRealNumberPrecision( 12 ); - ot << mX << ", " << mY; - return rep; -} - QString QgsPointXY::toString( int precision ) const { - QString x = std::isfinite( mX ) ? QString::number( mX, 'f', precision ) : QObject::tr( "infinite" ); - QString y = std::isfinite( mY ) ? QString::number( mY, 'f', precision ) : QObject::tr( "infinite" ); - return QStringLiteral( "%1,%2" ).arg( x, y ); -} - -QString QgsPointXY::toDegreesMinutesSeconds( int precision, const bool useSuffix, const bool padded ) const -{ - //first, limit longitude to -360 to 360 degree range - double myWrappedX = std::fmod( mX, 360.0 ); - //next, wrap around longitudes > 180 or < -180 degrees, so that, e.g., "190E" -> "170W" - if ( myWrappedX > 180.0 ) - { - myWrappedX = myWrappedX - 360.0; - } - else if ( myWrappedX < -180.0 ) - { - myWrappedX = myWrappedX + 360.0; - } - - //first, limit latitude to -180 to 180 degree range - double myWrappedY = std::fmod( mY, 180.0 ); - //next, wrap around latitudes > 90 or < -90 degrees, so that, e.g., "110S" -> "70N" - if ( myWrappedY > 90.0 ) - { - myWrappedY = myWrappedY - 180.0; - } - else if ( myWrappedY < -90.0 ) - { - myWrappedY = myWrappedY + 180.0; - } - - int myDegreesX = int( std::fabs( myWrappedX ) ); - double myFloatMinutesX = double( ( std::fabs( myWrappedX ) - myDegreesX ) * 60 ); - int myIntMinutesX = int( myFloatMinutesX ); - double mySecondsX = double( myFloatMinutesX - myIntMinutesX ) * 60; - - int myDegreesY = int( std::fabs( myWrappedY ) ); - double myFloatMinutesY = double( ( std::fabs( myWrappedY ) - myDegreesY ) * 60 ); - int myIntMinutesY = int( myFloatMinutesY ); - double mySecondsY = double( myFloatMinutesY - myIntMinutesY ) * 60; - - //make sure rounding to specified precision doesn't create seconds >= 60 - if ( std::round( mySecondsX * std::pow( 10.0, precision ) ) >= 60 * std::pow( 10.0, precision ) ) - { - mySecondsX = std::max( mySecondsX - 60, 0.0 ); - myIntMinutesX++; - if ( myIntMinutesX >= 60 ) - { - myIntMinutesX -= 60; - myDegreesX++; - } - } - if ( std::round( mySecondsY * std::pow( 10.0, precision ) ) >= 60 * std::pow( 10.0, precision ) ) - { - mySecondsY = std::max( mySecondsY - 60, 0.0 ); - myIntMinutesY++; - if ( myIntMinutesY >= 60 ) - { - myIntMinutesY -= 60; - myDegreesY++; - } - } - - QString myXHemisphere; - QString myYHemisphere; - QString myXSign; - QString myYSign; - if ( useSuffix ) - { - myXHemisphere = myWrappedX < 0 ? QObject::tr( "W" ) : QObject::tr( "E" ); - myYHemisphere = myWrappedY < 0 ? QObject::tr( "S" ) : QObject::tr( "N" ); - } - else - { - if ( myWrappedX < 0 ) - { - myXSign = QObject::tr( "-" ); - } - if ( myWrappedY < 0 ) - { - myYSign = QObject::tr( "-" ); - } - } - //check if coordinate is all zeros for the specified precision, and if so, - //remove the sign and hemisphere strings - if ( myDegreesX == 0 && myIntMinutesX == 0 && std::round( mySecondsX * std::pow( 10.0, precision ) ) == 0 ) - { - myXSign = QString(); - myXHemisphere = QString(); - } - if ( myDegreesY == 0 && myIntMinutesY == 0 && std::round( mySecondsY * std::pow( 10.0, precision ) ) == 0 ) - { - myYSign = QString(); - myYHemisphere = QString(); - } - //also remove directional prefix from 180 degree longitudes - if ( myDegreesX == 180 && myIntMinutesX == 0 && std::round( mySecondsX * std::pow( 10.0, precision ) ) == 0 ) - { - myXHemisphere = QString(); - } - //pad minutes with leading digits if required - QString myMinutesX = padded ? QStringLiteral( "%1" ).arg( myIntMinutesX, 2, 10, QChar( '0' ) ) : QString::number( myIntMinutesX ); - QString myMinutesY = padded ? QStringLiteral( "%1" ).arg( myIntMinutesY, 2, 10, QChar( '0' ) ) : QString::number( myIntMinutesY ); - //pad seconds with leading digits if required - int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); //1 for decimal place if required - QString myStrSecondsX = padded ? QStringLiteral( "%1" ).arg( mySecondsX, digits, 'f', precision, QChar( '0' ) ) : QString::number( mySecondsX, 'f', precision ); - QString myStrSecondsY = padded ? QStringLiteral( "%1" ).arg( mySecondsY, digits, 'f', precision, QChar( '0' ) ) : QString::number( mySecondsY, 'f', precision ); - - QString rep = myXSign + QString::number( myDegreesX ) + QChar( 176 ) + - myMinutesX + QChar( 0x2032 ) + - myStrSecondsX + QChar( 0x2033 ) + - myXHemisphere + ',' + - myYSign + QString::number( myDegreesY ) + QChar( 176 ) + - myMinutesY + QChar( 0x2032 ) + - myStrSecondsY + QChar( 0x2033 ) + - myYHemisphere; - return rep; -} - -QString QgsPointXY::toDegreesMinutes( int precision, const bool useSuffix, const bool padded ) const -{ - //first, limit longitude to -360 to 360 degree range - double myWrappedX = std::fmod( mX, 360.0 ); - //next, wrap around longitudes > 180 or < -180 degrees, so that, e.g., "190E" -> "170W" - if ( myWrappedX > 180.0 ) - { - myWrappedX = myWrappedX - 360.0; - } - else if ( myWrappedX < -180.0 ) + if ( precision < 0 ) { - myWrappedX = myWrappedX + 360.0; - } - - int myDegreesX = int( std::fabs( myWrappedX ) ); - double myFloatMinutesX = double( ( std::fabs( myWrappedX ) - myDegreesX ) * 60 ); - - int myDegreesY = int( std::fabs( mY ) ); - double myFloatMinutesY = double( ( std::fabs( mY ) - myDegreesY ) * 60 ); - - //make sure rounding to specified precision doesn't create minutes >= 60 - if ( std::round( myFloatMinutesX * std::pow( 10.0, precision ) ) >= 60 * std::pow( 10.0, precision ) ) - { - myFloatMinutesX = std::max( myFloatMinutesX - 60, 0.0 ); - myDegreesX++; - } - if ( std::round( myFloatMinutesY * std::pow( 10.0, precision ) ) >= 60 * std::pow( 10.0, precision ) ) - { - myFloatMinutesY = std::max( myFloatMinutesY - 60, 0.0 ); - myDegreesY++; - } - - QString myXHemisphere; - QString myYHemisphere; - QString myXSign; - QString myYSign; - if ( useSuffix ) - { - myXHemisphere = myWrappedX < 0 ? QObject::tr( "W" ) : QObject::tr( "E" ); - myYHemisphere = mY < 0 ? QObject::tr( "S" ) : QObject::tr( "N" ); + QString rep; + QTextStream ot( &rep ); + ot.setRealNumberPrecision( 12 ); + ot << mX << ", " << mY; + return rep; } else { - if ( myWrappedX < 0 ) - { - myXSign = QObject::tr( "-" ); - } - if ( mY < 0 ) - { - myYSign = QObject::tr( "-" ); - } - } - //check if coordinate is all zeros for the specified precision, and if so, - //remove the sign and hemisphere strings - if ( myDegreesX == 0 && std::round( myFloatMinutesX * std::pow( 10.0, precision ) ) == 0 ) - { - myXSign = QString(); - myXHemisphere = QString(); - } - if ( myDegreesY == 0 && std::round( myFloatMinutesY * std::pow( 10.0, precision ) ) == 0 ) - { - myYSign = QString(); - myYHemisphere = QString(); + QString x = std::isfinite( mX ) ? QString::number( mX, 'f', precision ) : QObject::tr( "infinite" ); + QString y = std::isfinite( mY ) ? QString::number( mY, 'f', precision ) : QObject::tr( "infinite" ); + return QStringLiteral( "%1,%2" ).arg( x, y ); } - //also remove directional prefix from 180 degree longitudes - if ( myDegreesX == 180 && std::round( myFloatMinutesX * std::pow( 10.0, precision ) ) == 0 ) - { - myXHemisphere = QString(); - } - - //pad minutes with leading digits if required - int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); //1 for decimal place if required - QString myStrMinutesX = padded ? QStringLiteral( "%1" ).arg( myFloatMinutesX, digits, 'f', precision, QChar( '0' ) ) : QString::number( myFloatMinutesX, 'f', precision ); - QString myStrMinutesY = padded ? QStringLiteral( "%1" ).arg( myFloatMinutesY, digits, 'f', precision, QChar( '0' ) ) : QString::number( myFloatMinutesY, 'f', precision ); - - QString rep = myXSign + QString::number( myDegreesX ) + QChar( 176 ) + - myStrMinutesX + QChar( 0x2032 ) + - myXHemisphere + ',' + - myYSign + QString::number( myDegreesY ) + QChar( 176 ) + - myStrMinutesY + QChar( 0x2032 ) + - myYHemisphere; - return rep; } -QString QgsPointXY::wellKnownText() const +QString QgsPointXY::asWkt() const { return QStringLiteral( "POINT(%1 %2)" ).arg( qgsDoubleToString( mX ), qgsDoubleToString( mY ) ); } diff --git a/src/core/qgspointxy.h b/src/core/qgspointxy.h index 7b8254c9fc52..88d0829fd0ec 100644 --- a/src/core/qgspointxy.h +++ b/src/core/qgspointxy.h @@ -147,43 +147,17 @@ class CORE_EXPORT QgsPointXY */ QPointF toQPointF() const; - //! String representation of the point (x,y) - QString toString() const; - - //! As above but with precision for string representation of a point - QString toString( int precision ) const; - - /** - * Return a string representation as degrees minutes seconds. - * Its up to the calling function to ensure that this point can - * be meaningfully represented in this form. - * \param precision number of decimal points to use for seconds - * \param useSuffix set to true to include a direction suffix (e.g., 'N'), - * set to false to use a "-" prefix for west and south coordinates - * \param padded set to true to force minutes and seconds to use two decimals, - * e.g., '05' instead of '5'. - */ - QString toDegreesMinutesSeconds( int precision, const bool useSuffix = true, const bool padded = false ) const; - /** - * Return a string representation as degrees minutes. - * Its up to the calling function to ensure that this point can - * be meaningfully represented in this form. - * \param precision number of decimal points to use for minutes - * \param useSuffix set to true to include a direction suffix (e.g., 'N'), - * set to false to use a "-" prefix for west and south coordinates - * \param padded set to true to force minutes to use two decimals, - * e.g., '05' instead of '5'. + * Returns a string representation of the point (x, y) with a preset \a precision. + * If \a precision is -1, then a default precision will be used. */ - QString toDegreesMinutes( int precision, const bool useSuffix = true, const bool padded = false ) const; - + QString toString( int precision = -1 ) const; /** - * Return the well known text representation for the point. + * Return the well known text representation for the point (e.g. "POINT(x y)"). * The wkt is created without an SRID. - * \returns Well known text in the form POINT(x y) */ - QString wellKnownText() const; + QString asWkt() const; /** * Returns the squared distance between this point a specified x, y coordinate. diff --git a/src/core/qgsvectorfilewriter.cpp b/src/core/qgsvectorfilewriter.cpp index b32f5f9dbf19..f0321333aea9 100644 --- a/src/core/qgsvectorfilewriter.cpp +++ b/src/core/qgsvectorfilewriter.cpp @@ -2154,7 +2154,7 @@ gdal::ogr_feature_unique_ptr QgsVectorFileWriter::createFeature( const QgsFeatur return nullptr; } - QByteArray wkb( geom.exportToWkb() ); + QByteArray wkb( geom.asWkb() ); OGRErr err = OGR_G_ImportFromWkb( mGeom2, reinterpret_cast( const_cast( wkb.constData() ) ), wkb.length() ); if ( err != OGRERR_NONE ) { @@ -2170,7 +2170,7 @@ gdal::ogr_feature_unique_ptr QgsVectorFileWriter::createFeature( const QgsFeatur } else // wkb type matches { - QByteArray wkb( geom.exportToWkb() ); + QByteArray wkb( geom.asWkb() ); OGRGeometryH ogrGeom = createEmptyGeometry( mWkbType ); OGRErr err = OGR_G_ImportFromWkb( ogrGeom, reinterpret_cast( const_cast( wkb.constData() ) ), wkb.length() ); if ( err != OGRERR_NONE ) diff --git a/src/providers/db2/qgsdb2provider.cpp b/src/providers/db2/qgsdb2provider.cpp index 4eecfa6c54ca..7f7980fe9806 100644 --- a/src/providers/db2/qgsdb2provider.cpp +++ b/src/providers/db2/qgsdb2provider.cpp @@ -1099,7 +1099,7 @@ bool QgsDb2Provider::addFeatures( QgsFeatureList &flist, Flags flags ) { QgsGeometry geom = it->geometry(); - QByteArray bytea = geom.exportToWkb(); + QByteArray bytea = geom.asWkb(); query.bindValue( bindIdx, bytea, QSql::In | QSql::Binary ); } @@ -1236,7 +1236,7 @@ bool QgsDb2Provider::changeGeometryValues( const QgsGeometryMap &geometry_map ) } // add geometry param - QByteArray bytea = it->exportToWkb(); + QByteArray bytea = it->asWkb(); query.addBindValue( bytea, QSql::In | QSql::Binary ); if ( !query.exec() ) diff --git a/src/providers/gpx/qgsgpxprovider.cpp b/src/providers/gpx/qgsgpxprovider.cpp index 7bad6e8dd022..627ddf97aae1 100644 --- a/src/providers/gpx/qgsgpxprovider.cpp +++ b/src/providers/gpx/qgsgpxprovider.cpp @@ -210,7 +210,7 @@ bool QgsGPXProvider::addFeatures( QgsFeatureList &flist, Flags flags ) bool QgsGPXProvider::addFeature( QgsFeature &f, Flags ) { - QByteArray wkb( f.geometry().exportToWkb() ); + QByteArray wkb( f.geometry().asWkb() ); const char *geo = wkb.constData(); QgsWkbTypes::Type wkbType = f.geometry().wkbType(); bool success = false; diff --git a/src/providers/mssql/qgsmssqlprovider.cpp b/src/providers/mssql/qgsmssqlprovider.cpp index 89645e930e2a..faa44c3e8cd6 100644 --- a/src/providers/mssql/qgsmssqlprovider.cpp +++ b/src/providers/mssql/qgsmssqlprovider.cpp @@ -1004,7 +1004,7 @@ bool QgsMssqlProvider::addFeatures( QgsFeatureList &flist, Flags flags ) QgsGeometry geom = it->geometry(); if ( mUseWkb ) { - QByteArray bytea = geom.exportToWkb(); + QByteArray bytea = geom.asWkb(); query.addBindValue( bytea, QSql::In | QSql::Binary ); } else @@ -1014,7 +1014,7 @@ bool QgsMssqlProvider::addFeatures( QgsFeatureList &flist, Flags flags ) { // Z and M on the end of a WKT string isn't valid for // SQL Server so we have to remove it first. - wkt = geom.exportToWkt(); + wkt = geom.asWkt(); wkt.replace( QRegExp( "[mzMZ]+\\s*\\(" ), QStringLiteral( "(" ) ); } query.addBindValue( wkt ); @@ -1343,12 +1343,12 @@ bool QgsMssqlProvider::changeGeometryValues( const QgsGeometryMap &geometry_map // add geometry param if ( mUseWkb ) { - QByteArray bytea = it->exportToWkb(); + QByteArray bytea = it->asWkb(); query.addBindValue( bytea, QSql::In | QSql::Binary ); } else { - QString wkt = it->exportToWkt(); + QString wkt = it->asWkt(); // Z and M on the end of a WKT string isn't valid for // SQL Server so we have to remove it first. wkt.replace( QRegExp( "[mzMZ]+\\s*\\(" ), QStringLiteral( "(" ) ); diff --git a/src/providers/ogr/qgsogrprovider.cpp b/src/providers/ogr/qgsogrprovider.cpp index f9d7f67b5c87..badad126689b 100644 --- a/src/providers/ogr/qgsogrprovider.cpp +++ b/src/providers/ogr/qgsogrprovider.cpp @@ -1263,7 +1263,7 @@ bool QgsOgrProvider::addFeaturePrivate( QgsFeature &f, Flags flags ) if ( f.hasGeometry() ) { - QByteArray wkb( f.geometry().exportToWkb() ); + QByteArray wkb( f.geometry().asWkb() ); OGRGeometryH geom = nullptr; if ( !wkb.isEmpty() ) @@ -1816,7 +1816,7 @@ bool QgsOgrProvider::changeGeometryValues( const QgsGeometryMap &geometry_map ) mOgrLayer->ResetReading(); // needed for SQLite-based to clear iterator OGRGeometryH newGeometry = nullptr; - QByteArray wkb = it->exportToWkb(); + QByteArray wkb = it->asWkb(); // We might receive null geometries. It is OK, but don't go through the // OGR_G_CreateFromWkb() route then if ( !wkb.isEmpty() ) diff --git a/src/providers/oracle/qgsoraclefeatureiterator.cpp b/src/providers/oracle/qgsoraclefeatureiterator.cpp index 17669b3582ed..7d39c649d4c7 100644 --- a/src/providers/oracle/qgsoraclefeatureiterator.cpp +++ b/src/providers/oracle/qgsoraclefeatureiterator.cpp @@ -393,7 +393,7 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature &feature ) { QgsGeometry g; g.fromWkb( ba ); - v = g.exportToWkt(); + v = g.asWkt(); } else { diff --git a/src/providers/oracle/qgsoracleprovider.cpp b/src/providers/oracle/qgsoracleprovider.cpp index 6adf1f5c0f4c..9b7787c9c347 100644 --- a/src/providers/oracle/qgsoracleprovider.cpp +++ b/src/providers/oracle/qgsoracleprovider.cpp @@ -1813,7 +1813,7 @@ void QgsOracleProvider::appendGeomParam( const QgsGeometry &geom, QSqlQuery &qry { QOCISpatialGeometry g; - QByteArray wkb = geom.exportToWkb(); + QByteArray wkb = geom.asWkb(); wkbPtr ptr; ptr.ucPtr = !geom.isEmpty() ? reinterpret_cast< unsigned char * >( const_cast( wkb.constData() ) ) : 0; diff --git a/src/providers/postgres/qgspostgresprovider.cpp b/src/providers/postgres/qgspostgresprovider.cpp index 343067f42f40..8380c4d10338 100644 --- a/src/providers/postgres/qgspostgresprovider.cpp +++ b/src/providers/postgres/qgspostgresprovider.cpp @@ -2681,7 +2681,7 @@ void QgsPostgresProvider::appendGeomParam( const QgsGeometry &geom, QStringList QString param; QgsGeometry convertedGeom( convertToProviderType( geom ) ); - QByteArray wkb( convertedGeom ? convertedGeom.exportToWkb() : geom.exportToWkb() ); + QByteArray wkb( convertedGeom ? convertedGeom.asWkb() : geom.asWkb() ); const unsigned char *buf = reinterpret_cast< const unsigned char * >( wkb.constData() ); int wkbSize = wkb.length(); diff --git a/src/providers/spatialite/qgsspatialiteprovider.cpp b/src/providers/spatialite/qgsspatialiteprovider.cpp index 16431668f865..e893e3be5f5a 100644 --- a/src/providers/spatialite/qgsspatialiteprovider.cpp +++ b/src/providers/spatialite/qgsspatialiteprovider.cpp @@ -3893,7 +3893,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList &flist, Flags flags ) { unsigned char *wkb = nullptr; int wkb_size; - QByteArray featureWkb = feature->geometry().exportToWkb(); + QByteArray featureWkb = feature->geometry().asWkb(); convertFromGeosWKB( reinterpret_cast( featureWkb.constData() ), featureWkb.length(), &wkb, &wkb_size, nDims ); @@ -4333,7 +4333,7 @@ bool QgsSpatiaLiteProvider::changeGeometryValues( const QgsGeometryMap &geometry // binding GEOMETRY to Prepared Statement unsigned char *wkb = nullptr; int wkb_size; - QByteArray iterWkb = iter->exportToWkb(); + QByteArray iterWkb = iter->asWkb(); convertFromGeosWKB( reinterpret_cast( iterWkb.constData() ), iterWkb.length(), &wkb, &wkb_size, nDims ); if ( !wkb ) sqlite3_bind_null( stmt, 1 ); diff --git a/src/providers/virtual/qgsvirtuallayerblob.cpp b/src/providers/virtual/qgsvirtuallayerblob.cpp index c89a5f4a8c9a..9c5a94432c0c 100644 --- a/src/providers/virtual/qgsvirtuallayerblob.cpp +++ b/src/providers/virtual/qgsvirtuallayerblob.cpp @@ -67,7 +67,7 @@ void qgsGeometryToSpatialiteBlob( const QgsGeometry &geom, int32_t srid, char *& { const int header_len = SpatialiteBlobHeader::LENGTH; - QByteArray wkb( geom.exportToWkb() ); + QByteArray wkb( geom.asWkb() ); const int wkb_size = wkb.length(); size = header_len + wkb_size; diff --git a/src/providers/wfs/qgswfsfeatureiterator.cpp b/src/providers/wfs/qgswfsfeatureiterator.cpp index 0860113a1288..39ea5f6bcb19 100644 --- a/src/providers/wfs/qgswfsfeatureiterator.cpp +++ b/src/providers/wfs/qgswfsfeatureiterator.cpp @@ -1252,7 +1252,7 @@ void QgsWFSFeatureIterator::copyFeature( const QgsFeature &srcFeature, QgsFeatur if ( !mShared->mGeometryAttribute.isEmpty() && !geometry.isNull() ) { QgsGeometry g; - g.fromWkb( geometry.exportToWkb() ); + g.fromWkb( geometry.asWkb() ); dstFeature.setGeometry( g ); } else diff --git a/src/providers/wfs/qgswfsshareddata.cpp b/src/providers/wfs/qgswfsshareddata.cpp index abd838f17cc1..6d357222ff57 100644 --- a/src/providers/wfs/qgswfsshareddata.cpp +++ b/src/providers/wfs/qgswfsshareddata.cpp @@ -714,7 +714,7 @@ bool QgsWFSSharedData::changeGeometryValues( const QgsGeometryMap &geometry_map QgsChangedAttributesMap newChangedAttrMap; for ( QgsGeometryMap::const_iterator iter = geometry_map.constBegin(); iter != geometry_map.constEnd(); ++iter ) { - QByteArray wkb = iter->exportToWkb(); + QByteArray wkb = iter->asWkb(); if ( !wkb.isEmpty() ) { QgsAttributeMap newAttrMap; @@ -850,7 +850,7 @@ void QgsWFSSharedData::serializeFeatures( QVector &featu QgsGeometry geometry = gmlFeature.geometry(); if ( !mGeometryAttribute.isEmpty() && !geometry.isNull() ) { - QByteArray array( geometry.exportToWkb() ); + QByteArray array( geometry.asWkb() ); cachedFeature.setAttribute( hexwkbGeomIdx, QVariant( QString( array.toHex().data() ) ) ); diff --git a/src/providers/wfs/qgswfsutils.cpp b/src/providers/wfs/qgswfsutils.cpp index eaffc0e91c87..de946fa255d8 100644 --- a/src/providers/wfs/qgswfsutils.cpp +++ b/src/providers/wfs/qgswfsutils.cpp @@ -359,7 +359,7 @@ QString QgsWFSUtils::getMD5( const QgsFeature &f ) QgsGeometry geometry = f.geometry(); if ( !geometry.isNull() ) { - hash.addData( geometry.exportToWkb() ); + hash.addData( geometry.asWkb() ); } return hash.result().toHex(); diff --git a/src/server/services/wfs/qgswfsgetfeature.cpp b/src/server/services/wfs/qgswfsgetfeature.cpp index 18df99fe5f34..35365682705c 100644 --- a/src/server/services/wfs/qgswfsgetfeature.cpp +++ b/src/server/services/wfs/qgswfsgetfeature.cpp @@ -1257,7 +1257,7 @@ namespace QgsWfs const QgsAbstractGeometry *abstractGeom = geom.constGet(); if ( abstractGeom ) { - gmlElem = abstractGeom->asGML2( doc, prec, "http://www.opengis.net/gml" ); + gmlElem = abstractGeom->asGml2( doc, prec, "http://www.opengis.net/gml" ); } } @@ -1358,7 +1358,7 @@ namespace QgsWfs const QgsAbstractGeometry *abstractGeom = geom.constGet(); if ( abstractGeom ) { - gmlElem = abstractGeom->asGML3( doc, prec, "http://www.opengis.net/gml" ); + gmlElem = abstractGeom->asGml3( doc, prec, "http://www.opengis.net/gml" ); } } diff --git a/src/server/services/wms/qgswmsrenderer.cpp b/src/server/services/wms/qgswmsrenderer.cpp index 3ffdc52ef736..5b519b814bd4 100644 --- a/src/server/services/wms/qgswmsrenderer.cpp +++ b/src/server/services/wms/qgswmsrenderer.cpp @@ -1455,7 +1455,7 @@ namespace QgsWms if ( filterGeom ) { - fReq.setFilterExpression( QString( "intersects( $geometry, geom_from_wkt('%1') )" ).arg( filterGeom->exportToWkt() ) ); + fReq.setFilterExpression( QString( "intersects( $geometry, geom_from_wkt('%1') )" ).arg( filterGeom->asWkt() ) ); } #ifdef HAVE_SERVER_PYTHON_PLUGINS @@ -1635,7 +1635,7 @@ namespace QgsWms } QDomElement geometryElement = infoDocument.createElement( QStringLiteral( "Attribute" ) ); geometryElement.setAttribute( QStringLiteral( "name" ), QStringLiteral( "geometry" ) ); - geometryElement.setAttribute( QStringLiteral( "value" ), geom.exportToWkt( getWMSPrecision() ) ); + geometryElement.setAttribute( QStringLiteral( "value" ), geom.asWkt( getWMSPrecision() ) ); geometryElement.setAttribute( QStringLiteral( "type" ), QStringLiteral( "derived" ) ); featureElement.appendChild( geometryElement ); } diff --git a/tests/src/analysis/testqgsgeometrysnapper.cpp b/tests/src/analysis/testqgsgeometrysnapper.cpp index c7c6e8144a34..cdc469e9501c 100644 --- a/tests/src/analysis/testqgsgeometrysnapper.cpp +++ b/tests/src/analysis/testqgsgeometrysnapper.cpp @@ -85,21 +85,21 @@ void TestQgsGeometrySnapper::snapPolygonToPolygon() QgsGeometry polygonGeom = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 10.1 0, 9.9 10.1, 0 10, 0.1 -0.1))" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( polygonGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))" ) ); QgsGeometry polygonGeom2 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 10.1 0, 0 10, 0.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom2, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 0 10, 0 0))" ) ); // insert new vertex QgsGeometry polygonGeom3 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 20.5 0.5, 20 10, 0 9.9, 0.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom3, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10, 0 0))" ) ); // remove vertex QgsGeometry polygonGeom4 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 10.1 0, 9.9 10.1, 5 10, 0 10, 0.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom4, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))" ) ); } void TestQgsGeometrySnapper::snapLineToLine() @@ -117,41 +117,41 @@ void TestQgsGeometrySnapper::snapLineToLine() QgsGeometry lineGeom = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 9.9 10.1, 0 10, 0.1 -0.1)" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( lineGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10, 0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10, 0 0)" ) ); QgsGeometry lineGeom2 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 0 10, 0.1 -0.1)" ) ); result = snapper.snapGeometry( lineGeom2, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 0 10, 0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 0 10, 0 0)" ) ); // insert new vertex QgsGeometry lineGeom3 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 20.5 0.5, 20 10, 0 9.9, 0.1 -0.1)" ) ); result = snapper.snapGeometry( lineGeom3, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10, 0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10, 0 0)" ) ); // remove vertex QgsGeometry lineGeom4 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 9.9 10.1, 5 10, 0 10, 0.1 -0.1)" ) ); result = snapper.snapGeometry( lineGeom4, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10, 0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10, 0 0)" ) ); // unclosed linestrings QgsGeometry lineGeom5 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 9.9 10.1, 0 10)" ) ); result = snapper.snapGeometry( lineGeom5, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10)" ) ); QgsGeometry lineGeom6 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 0 10)" ) ); result = snapper.snapGeometry( lineGeom6, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 0 10)" ) ); // insert new vertex QgsGeometry lineGeom7 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 20.5 0.5, 20 10, 0 9.9)" ) ); result = snapper.snapGeometry( lineGeom7, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10)" ) ); // remove vertex QgsGeometry lineGeom8 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 9.9 10.1, 5 10, 0 10)" ) ); result = snapper.snapGeometry( lineGeom8, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10)" ) ); } void TestQgsGeometrySnapper::snapLineToPolygon() @@ -169,41 +169,41 @@ void TestQgsGeometrySnapper::snapLineToPolygon() QgsGeometry lineGeom = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 9.9 10.1, 0 10, 0.1 -0.1)" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( lineGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10, 0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10, 0 0)" ) ); QgsGeometry lineGeom2 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 0 10, 0.1 -0.1)" ) ); result = snapper.snapGeometry( lineGeom2, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 0 10, 0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 0 10, 0 0)" ) ); // insert new vertex QgsGeometry lineGeom3 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 20.5 0.5, 20 10, 0 9.9, 0.1 -0.1)" ) ); result = snapper.snapGeometry( lineGeom3, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10, 0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10, 0 0)" ) ); // remove vertex QgsGeometry lineGeom4 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 9.9 10.1, 5 10, 0 10, 0.1 -0.1)" ) ); result = snapper.snapGeometry( lineGeom4, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10, 0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10, 0 0)" ) ); // unclosed linestrings QgsGeometry lineGeom5 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 9.9 10.1, 0 10)" ) ); result = snapper.snapGeometry( lineGeom5, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10)" ) ); QgsGeometry lineGeom6 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 0 10)" ) ); result = snapper.snapGeometry( lineGeom6, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 0 10)" ) ); // insert new vertex QgsGeometry lineGeom7 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 20.5 0.5, 20 10, 0 9.9)" ) ); result = snapper.snapGeometry( lineGeom7, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10)" ) ); // remove vertex QgsGeometry lineGeom8 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 9.9 10.1, 5 10, 0 10)" ) ); result = snapper.snapGeometry( lineGeom8, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10)" ) ); } void TestQgsGeometrySnapper::snapLineToPoint() @@ -223,16 +223,16 @@ void TestQgsGeometrySnapper::snapLineToPoint() QgsGeometry lineGeom = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 10 10, 0 10)" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( lineGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 10 10, 0 10)" ) ); QgsGeometry lineGeom2 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 10.1 0, 0 10)" ) ); result = snapper.snapGeometry( lineGeom2, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 0 10)" ) ); // insert new vertex QgsGeometry lineGeom3 = QgsGeometry::fromWkt( QStringLiteral( "LineString(0.1 -0.1, 20.0 0.0, 20 10, 0 10)" ) ); result = snapper.snapGeometry( lineGeom3, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 10 0, 20 0, 20 10, 0 10)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 10 0, 20 0, 20 10, 0 10)" ) ); } void TestQgsGeometrySnapper::snapPolygonToLine() @@ -256,41 +256,41 @@ void TestQgsGeometrySnapper::snapPolygonToLine() QgsGeometry polygonGeom = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 10.1 0, 9.9 10.1, 0 10, 0.1 -0.1))" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( polygonGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))" ) ); QgsGeometry polygonGeom2 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 10.1 0, 0 10, 0.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom2, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 0 10, 0 0))" ) ); // insert new vertex QgsGeometry polygonGeom3 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 20.5 0.5, 20 10, 0 9.9, 0.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom3, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 20.5 0.5, 20 10, 10 10, 0 10, 0 0))" ) ); // remove vertex QgsGeometry polygonGeom4 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 10.1 0, 9.9 10.1, 5 10, 0 10, 0.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom4, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))" ) ); // snapping to unclosed linestring QgsGeometry polygonGeom5 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((100.1 -0.1, 110.1 0, 109.9 10.1, 100 10, 100.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom5, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((100 0, 110 0, 110 10, 100 10, 100 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((100 0, 110 0, 110 10, 100 10, 100 0))" ) ); QgsGeometry polygonGeom6 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((100.1 -0.1, 110.1 0, 100 10, 100.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom6, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((100 0, 110 0, 100 10, 100 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((100 0, 110 0, 100 10, 100 0))" ) ); // insert new vertex QgsGeometry polygonGeom7 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((100.1 -0.1, 120.5 0.5, 120 10, 100 9.9, 100.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom7, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((100 0, 110 0, 120.5 0.5, 120 10, 110 10, 100 10, 100 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((100 0, 110 0, 120.5 0.5, 120 10, 110 10, 100 10, 100 0))" ) ); // remove vertex QgsGeometry polygonGeom8 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((100.1 -0.1, 110.1 0, 109.9 10.1, 105 10, 100 10, 100.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom8, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((100 0, 110 0, 110 10, 100 10, 100 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((100 0, 110 0, 110 10, 100 10, 100 0))" ) ); } void TestQgsGeometrySnapper::snapPolygonToPoint() @@ -310,16 +310,16 @@ void TestQgsGeometrySnapper::snapPolygonToPoint() QgsGeometry polygonGeom = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 10.1 0, 10 10, 0 10, 0.1 -0.1))" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( polygonGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))" ) ); QgsGeometry polygonGeom2 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 10.1 0, 0 10, 0.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom2, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 0 10, 0 0))" ) ); // insert new vertex QgsGeometry polygonGeom3 = QgsGeometry::fromWkt( QStringLiteral( "Polygon((0.1 -0.1, 20.0 0.0, 20 10, 0 10, 0.1 -0.1))" ) ); result = snapper.snapGeometry( polygonGeom3, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 20 0, 20 10, 0 10, 0 0))" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Polygon ((0 0, 10 0, 20 0, 20 10, 0 10, 0 0))" ) ); } void TestQgsGeometrySnapper::snapPointToPoint() @@ -339,11 +339,11 @@ void TestQgsGeometrySnapper::snapPointToPoint() QgsGeometry pointGeom = QgsGeometry::fromWkt( QStringLiteral( "Point(0.1 -0.1)" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( pointGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Point (0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Point (0 0)" ) ); pointGeom = QgsGeometry::fromWkt( QStringLiteral( "Point(0.6 -0.1)" ) ); result = snapper.snapGeometry( pointGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Point (1 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Point (1 0)" ) ); } void TestQgsGeometrySnapper::snapPointToLine() @@ -361,15 +361,15 @@ void TestQgsGeometrySnapper::snapPointToLine() QgsGeometry pointGeom = QgsGeometry::fromWkt( QStringLiteral( "Point(0.1 -0.1)" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( pointGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Point (0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Point (0 0)" ) ); pointGeom = QgsGeometry::fromWkt( QStringLiteral( "Point(10.6 -0.1)" ) ); result = snapper.snapGeometry( pointGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Point (10 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Point (10 0)" ) ); pointGeom = QgsGeometry::fromWkt( QStringLiteral( "Point(0.5 0.5)" ) ); result = snapper.snapGeometry( pointGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Point (0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Point (0 0)" ) ); } void TestQgsGeometrySnapper::snapPointToLinePreferNearest() @@ -387,7 +387,7 @@ void TestQgsGeometrySnapper::snapPointToLinePreferNearest() QgsGeometry pointGeom = QgsGeometry::fromWkt( QStringLiteral( "Point(0.5 0.5)" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( pointGeom, 1, QgsGeometrySnapper::PreferClosest ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Point (0.5 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Point (0.5 0)" ) ); } void TestQgsGeometrySnapper::snapPointToPolygon() @@ -405,11 +405,11 @@ void TestQgsGeometrySnapper::snapPointToPolygon() QgsGeometry pointGeom = QgsGeometry::fromWkt( QStringLiteral( "Point(0.1 -0.1)" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( pointGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Point (0 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Point (0 0)" ) ); pointGeom = QgsGeometry::fromWkt( QStringLiteral( "Point(10.6 -0.1)" ) ); result = snapper.snapGeometry( pointGeom, 1 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "Point (10 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "Point (10 0)" ) ); } void TestQgsGeometrySnapper::endPointSnap() @@ -426,15 +426,15 @@ void TestQgsGeometrySnapper::endPointSnap() QgsGeometry lineGeom = QgsGeometry::fromWkt( QStringLiteral( "LineString(1 -1, 102 0, 98 102, 0 101)" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( lineGeom, 10, QgsGeometrySnapper::EndPointPreferNodes ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 102 0, 98 102, 0 100)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 102 0, 98 102, 0 100)" ) ); QgsGeometry lineGeom2 = QgsGeometry::fromWkt( QStringLiteral( "LineString(50 0, 102 0, 98 102, 0 50)" ) ); result = snapper.snapGeometry( lineGeom2, 1, QgsGeometrySnapper::EndPointPreferNodes ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (50 0, 102 0, 98 102, 0 50)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (50 0, 102 0, 98 102, 0 50)" ) ); QgsGeometry lineGeom3 = QgsGeometry::fromWkt( QStringLiteral( "LineString(50 -10, 50 -1)" ) ); result = snapper.snapGeometry( lineGeom3, 2, QgsGeometrySnapper::EndPointPreferNodes ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (50 -10, 50 0)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (50 -10, 50 0)" ) ); } void TestQgsGeometrySnapper::endPointToEndPoint() @@ -452,15 +452,15 @@ void TestQgsGeometrySnapper::endPointToEndPoint() QgsGeometry lineGeom = QgsGeometry::fromWkt( QStringLiteral( "LineString(1 -1, 102 0, 98 102, 0 101)" ) ); QgsGeometrySnapper snapper( rl ); QgsGeometry result = snapper.snapGeometry( lineGeom, 10, QgsGeometrySnapper::EndPointToEndPoint ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 102 0, 98 102, 0 100)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 102 0, 98 102, 0 100)" ) ); QgsGeometry lineGeom2 = QgsGeometry::fromWkt( QStringLiteral( "LineString(50 0, 102 0, 98 102)" ) ); result = snapper.snapGeometry( lineGeom2, 1, QgsGeometrySnapper::EndPointToEndPoint ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (50 0, 102 0, 98 102)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (50 0, 102 0, 98 102)" ) ); QgsGeometry lineGeom3 = QgsGeometry::fromWkt( QStringLiteral( "LineString(50 -10, 50 -1)" ) ); result = snapper.snapGeometry( lineGeom3, 2, QgsGeometrySnapper::EndPointToEndPoint ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (50 -10, 50 -1)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (50 -10, 50 -1)" ) ); } void TestQgsGeometrySnapper::internalSnapper() @@ -471,32 +471,32 @@ void TestQgsGeometrySnapper::internalSnapper() QgsInternalGeometrySnapper snapper( 2 ); QgsGeometry result = snapper.snapFeature( f1 ); - QCOMPARE( result.exportToWkt(), f1.geometry().exportToWkt() ); + QCOMPARE( result.asWkt(), f1.geometry().asWkt() ); refGeom = QgsGeometry::fromWkt( QStringLiteral( "LineString(5 5, 10 11, 15 15)" ) ); QgsFeature f2( 2 ); f2.setGeometry( refGeom ); result = snapper.snapFeature( f2 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (5 5, 10 10, 15 15)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (5 5, 10 10, 15 15)" ) ); refGeom = QgsGeometry::fromWkt( QStringLiteral( "LineString(20 20, 30 20)" ) ); QgsFeature f3( 3 ); f3.setGeometry( refGeom ); result = snapper.snapFeature( f3 ); - QCOMPARE( result.exportToWkt(), f3.geometry().exportToWkt() ); + QCOMPARE( result.asWkt(), f3.geometry().asWkt() ); refGeom = QgsGeometry::fromWkt( QStringLiteral( "LineString(0 -1, 5.5 5, 9.8 10, 14.5 14.8)" ) ); QgsFeature f4( 4 ); f4.setGeometry( refGeom ); result = snapper.snapFeature( f4 ); - QCOMPARE( result.exportToWkt(), QStringLiteral( "LineString (0 0, 5 5, 10 10, 15 15)" ) ); + QCOMPARE( result.asWkt(), QStringLiteral( "LineString (0 0, 5 5, 10 10, 15 15)" ) ); QgsGeometryMap res = snapper.snappedGeometries(); QCOMPARE( res.count(), 4 ); - QCOMPARE( res.value( 1 ).exportToWkt(), f1.geometry().exportToWkt() ); - QCOMPARE( res.value( 2 ).exportToWkt(), QStringLiteral( "LineString (5 5, 10 10, 15 15)" ) ); - QCOMPARE( res.value( 3 ).exportToWkt(), f3.geometry().exportToWkt() ); - QCOMPARE( res.value( 4 ).exportToWkt(), QStringLiteral( "LineString (0 0, 5 5, 10 10, 15 15)" ) ); + QCOMPARE( res.value( 1 ).asWkt(), f1.geometry().asWkt() ); + QCOMPARE( res.value( 2 ).asWkt(), QStringLiteral( "LineString (5 5, 10 10, 15 15)" ) ); + QCOMPARE( res.value( 3 ).asWkt(), f3.geometry().asWkt() ); + QCOMPARE( res.value( 4 ).asWkt(), QStringLiteral( "LineString (0 0, 5 5, 10 10, 15 15)" ) ); } diff --git a/tests/src/analysis/testqgsprocessing.cpp b/tests/src/analysis/testqgsprocessing.cpp index efc1faa822c9..569edcad12f3 100644 --- a/tests/src/analysis/testqgsprocessing.cpp +++ b/tests/src/analysis/testqgsprocessing.cpp @@ -2064,7 +2064,7 @@ void TestQgsProcessing::parameterExtent() QGSCOMPARENEAR( ext.yMaximum(), 14.4, 0.001 ); gExt = QgsProcessingParameters::parameterAsExtentGeometry( def.get(), params, context, QgsCoordinateReferenceSystem( "EPSG:3785" ) ); - QCOMPARE( gExt.exportToWkt( 1 ), QStringLiteral( "Polygon ((11.1 12.2, 13.3 12.2, 13.3 14.4, 11.1 14.4, 11.1 12.2))" ) ); + QCOMPARE( gExt.asWkt( 1 ), QStringLiteral( "Polygon ((11.1 12.2, 13.3 12.2, 13.3 14.4, 11.1 14.4, 11.1 12.2))" ) ); p.setCrs( QgsCoordinateReferenceSystem( "EPSG:3785" ) ); QCOMPARE( QgsProcessingParameters::parameterAsExtentCrs( def.get(), params, context ).authid(), QStringLiteral( "EPSG:3785" ) ); diff --git a/tests/src/app/testqgsmaptooladdfeature.cpp b/tests/src/app/testqgsmaptooladdfeature.cpp index 44b128445e0e..e9543130dd38 100644 --- a/tests/src/app/testqgsmaptooladdfeature.cpp +++ b/tests/src/app/testqgsmaptooladdfeature.cpp @@ -39,7 +39,7 @@ namespace QTest // pretty printing of geometries in comparison tests template<> char *toString( const QgsGeometry &geom ) { - QByteArray ba = geom.exportToWkt().toAscii(); + QByteArray ba = geom.asWkt().toAscii(); return qstrdup( ba.data() ); } } diff --git a/tests/src/app/testqgsnodetool.cpp b/tests/src/app/testqgsnodetool.cpp index 56365dda76ad..4bdf82b1a6ca 100644 --- a/tests/src/app/testqgsnodetool.cpp +++ b/tests/src/app/testqgsnodetool.cpp @@ -37,7 +37,7 @@ namespace QTest // pretty printing of geometries in comparison tests template<> char *toString( const QgsGeometry &geom ) { - QByteArray ba = geom.exportToWkt().toAscii(); + QByteArray ba = geom.asWkt().toAscii(); return qstrdup( ba.data() ); } } diff --git a/tests/src/core/testqgsexpression.cpp b/tests/src/core/testqgsexpression.cpp index 90e59ce0b0a1..3c7547feef3a 100644 --- a/tests/src/core/testqgsexpression.cpp +++ b/tests/src/core/testqgsexpression.cpp @@ -2157,13 +2157,13 @@ class TestQgsExpression: public QObject polygon << polygon_ring; QgsGeometry sourcePoint( QgsGeometry::fromPointXY( point ) ); - QTest::newRow( "geomFromWKT Point" ) << "geom_from_wkt('" + sourcePoint.exportToWkt() + "')" << QgsGeometry::fromPointXY( point ) << false; + QTest::newRow( "geomFromWKT Point" ) << "geom_from_wkt('" + sourcePoint.asWkt() + "')" << QgsGeometry::fromPointXY( point ) << false; QgsGeometry sourceLine( QgsGeometry::fromPolylineXY( line ) ); - QTest::newRow( "geomFromWKT Line" ) << "geomFromWKT('" + sourceLine.exportToWkt() + "')" << QgsGeometry::fromPolylineXY( line ) << false; + QTest::newRow( "geomFromWKT Line" ) << "geomFromWKT('" + sourceLine.asWkt() + "')" << QgsGeometry::fromPolylineXY( line ) << false; QgsGeometry sourcePolyline( QgsGeometry::fromPolylineXY( polyline ) ); - QTest::newRow( "geomFromWKT Polyline" ) << "geomFromWKT('" + sourcePolyline.exportToWkt() + "')" << QgsGeometry::fromPolylineXY( polyline ) << false; + QTest::newRow( "geomFromWKT Polyline" ) << "geomFromWKT('" + sourcePolyline.asWkt() + "')" << QgsGeometry::fromPolylineXY( polyline ) << false; QgsGeometry sourcePolygon( QgsGeometry::fromPolygonXY( polygon ) ); - QTest::newRow( "geomFromWKT Polygon" ) << "geomFromWKT('" + sourcePolygon.exportToWkt() + "')" << QgsGeometry::fromPolygonXY( polygon ) << false; + QTest::newRow( "geomFromWKT Polygon" ) << "geomFromWKT('" + sourcePolygon.asWkt() + "')" << QgsGeometry::fromPolygonXY( polygon ) << false; // GML Point QTest::newRow( "GML Point (coordinates)" ) << "geomFromGML('123,456')" << QgsGeometry::fromPointXY( point ) << false; @@ -2238,8 +2238,8 @@ class TestQgsExpression: public QObject QgsGeometry oLine = QgsGeometry::fromPolylineXY( line ); QgsGeometry oPolygon = QgsGeometry::fromPolygonXY( polygon ); - QTest::newRow( "transform Line" ) << "transform( geomFromWKT('" + oLine.exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << tLine << false << false; - QTest::newRow( "transform Polygon" ) << "transform( geomFromWKT('" + oPolygon.exportToWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << tPolygon << false << false; + QTest::newRow( "transform Line" ) << "transform( geomFromWKT('" + oLine.asWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << tLine << false << false; + QTest::newRow( "transform Polygon" ) << "transform( geomFromWKT('" + oPolygon.asWkt() + "'), 'EPSG:4326', 'EPSG:3857' )" << tPolygon << false << false; } void eval_geometry_access_transform() @@ -2346,7 +2346,7 @@ class TestQgsExpression: public QObject QgsPointXY point2( 30, 20 ); QgsGeometry pnt1 = QgsGeometry::fromPointXY( point1 ); QgsGeometry pnt2 = QgsGeometry::fromPointXY( point2 ); - QTest::newRow( "union" ) << "union( $geometry, geomFromWKT('" + pnt2.exportToWkt() + "') )" << pnt1 << false << true << pnt1.combine( pnt2 ); + QTest::newRow( "union" ) << "union( $geometry, geomFromWKT('" + pnt2.asWkt() + "') )" << pnt1 << false << true << pnt1.combine( pnt2 ); geom = QgsGeometry::fromPolygonXY( polygon ); QTest::newRow( "intersection" ) << "intersection( $geometry, geomFromWKT('POLYGON((0 0, 0 10, 10 0, 0 0))') )" << geom << false << true << QgsGeometry::fromWkt( QStringLiteral( "POLYGON ((0 0,5 5,10 0,0 0))" ) ); @@ -2396,7 +2396,7 @@ class TestQgsExpression: public QObject QCOMPARE( out.canConvert(), true ); QgsGeometry outGeom = out.value(); - QVERIFY( compareWkt( outGeom.exportToWkt(), result.exportToWkt() ) ); + QVERIFY( compareWkt( outGeom.asWkt(), result.asWkt() ) ); } void eval_eval() diff --git a/tests/src/core/testqgsfeature.cpp b/tests/src/core/testqgsfeature.cpp index a921716f3a9e..4ed3e07d63cb 100644 --- a/tests/src/core/testqgsfeature.cpp +++ b/tests/src/core/testqgsfeature.cpp @@ -274,14 +274,14 @@ void TestQgsFeature::geometry() feature.setGeometry( QgsGeometry( mGeometry2 ) ); QVERIFY( feature.hasGeometry() ); feature.setGeometry( QgsGeometry( mGeometry ) ); - QCOMPARE( feature.geometry().exportToWkb(), mGeometry.exportToWkb() ); + QCOMPARE( feature.geometry().asWkb(), mGeometry.asWkb() ); //test implicit sharing detachment QgsFeature copy( feature ); - QCOMPARE( copy.geometry().exportToWkb(), feature.geometry().exportToWkb() ); + QCOMPARE( copy.geometry().asWkb(), feature.geometry().asWkb() ); copy.clearGeometry(); QVERIFY( ! copy.hasGeometry() ); - QCOMPARE( feature.geometry().exportToWkb(), mGeometry.exportToWkb() ); + QCOMPARE( feature.geometry().asWkb(), mGeometry.asWkb() ); //test no crash when setting an empty geometry and triggering a detach QgsFeature emptyGeomFeature; @@ -293,18 +293,18 @@ void TestQgsFeature::geometry() //setGeometry //always start with a copy so that we can test implicit sharing detachment is working copy = feature; - QCOMPARE( copy.geometry().exportToWkb(), mGeometry.exportToWkb() ); + QCOMPARE( copy.geometry().asWkb(), mGeometry.asWkb() ); copy.setGeometry( QgsGeometry( mGeometry2 ) ); - QCOMPARE( copy.geometry().exportToWkb(), mGeometry2.exportToWkb() ); - QCOMPARE( feature.geometry().exportToWkb(), mGeometry.exportToWkb() ); + QCOMPARE( copy.geometry().asWkb(), mGeometry2.asWkb() ); + QCOMPARE( feature.geometry().asWkb(), mGeometry.asWkb() ); //setGeometry using reference copy = feature; - QCOMPARE( copy.geometry().exportToWkb(), mGeometry.exportToWkb() ); + QCOMPARE( copy.geometry().asWkb(), mGeometry.asWkb() ); QgsGeometry geomByRef( mGeometry2 ); copy.setGeometry( geomByRef ); - QCOMPARE( copy.geometry().exportToWkb(), geomByRef.exportToWkb() ); - QCOMPARE( feature.geometry().exportToWkb(), mGeometry.exportToWkb() ); + QCOMPARE( copy.geometry().asWkb(), geomByRef.asWkb() ); + QCOMPARE( feature.geometry().asWkb(), mGeometry.asWkb() ); //clearGeometry QgsFeature geomFeature; @@ -500,7 +500,7 @@ void TestQgsFeature::dataStream() QCOMPARE( resultFeature.id(), originalFeature.id() ); QCOMPARE( resultFeature.attributes(), originalFeature.attributes() ); - QCOMPARE( resultFeature.geometry().exportToWkb(), originalFeature.geometry().exportToWkb() ); + QCOMPARE( resultFeature.geometry().asWkb(), originalFeature.geometry().asWkb() ); QCOMPARE( resultFeature.isValid(), originalFeature.isValid() ); //also test with feature empty geometry diff --git a/tests/src/core/testqgsgeometry.cpp b/tests/src/core/testqgsgeometry.cpp index 67a7b076f839..f5ca1e5adc8e 100644 --- a/tests/src/core/testqgsgeometry.cpp +++ b/tests/src/core/testqgsgeometry.cpp @@ -674,24 +674,24 @@ void TestQgsGeometry::point() QgsPoint exportPointFloat( 1 / 3.0, 2 / 3.0 ); QDomDocument doc( QStringLiteral( "gml" ) ); QString expectedGML2( QStringLiteral( "1,2" ) ); - QGSCOMPAREGML( elemToString( exportPoint.asGML2( doc ) ), expectedGML2 ); + QGSCOMPAREGML( elemToString( exportPoint.asGml2( doc ) ), expectedGML2 ); QString expectedGML2prec3( QStringLiteral( "0.333,0.667" ) ); - QGSCOMPAREGML( elemToString( exportPointFloat.asGML2( doc, 3 ) ), expectedGML2prec3 ); + QGSCOMPAREGML( elemToString( exportPointFloat.asGml2( doc, 3 ) ), expectedGML2prec3 ); //asGML3 QString expectedGML3( QStringLiteral( "1 2" ) ); - QCOMPARE( elemToString( exportPoint.asGML3( doc ) ), expectedGML3 ); + QCOMPARE( elemToString( exportPoint.asGml3( doc ) ), expectedGML3 ); QString expectedGML3prec3( QStringLiteral( "0.333 0.667" ) ); - QCOMPARE( elemToString( exportPointFloat.asGML3( doc, 3 ) ), expectedGML3prec3 ); + QCOMPARE( elemToString( exportPointFloat.asGml3( doc, 3 ) ), expectedGML3prec3 ); QgsPoint exportPointZ( 1, 2, 3 ); QString expectedGML2Z( QStringLiteral( "1 2 3" ) ); - QGSCOMPAREGML( elemToString( exportPointZ.asGML3( doc, 3 ) ), expectedGML2Z ); + QGSCOMPAREGML( elemToString( exportPointZ.asGml3( doc, 3 ) ), expectedGML2Z ); //asJSON QString expectedJson( QStringLiteral( "{\"type\": \"Point\", \"coordinates\": [1, 2]}" ) ); - QCOMPARE( exportPoint.asJSON(), expectedJson ); + QCOMPARE( exportPoint.asJson(), expectedJson ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"Point\", \"coordinates\": [0.333, 0.667]}" ) ); - QCOMPARE( exportPointFloat.asJSON( 3 ), expectedJsonPrec3 ); + QCOMPARE( exportPointFloat.asJson( 3 ), expectedJsonPrec3 ); //bounding box QgsPoint p15( 1.0, 2.0 ); @@ -1515,25 +1515,25 @@ void TestQgsGeometry::circularString() << QgsPoint( 2 + 1 / 3.0, 2 + 2 / 3.0 ) ); QDomDocument doc( QStringLiteral( "gml" ) ); QString expectedGML2( QStringLiteral( "31,32 41,42 51,52" ) ); - QGSCOMPAREGML( elemToString( exportLine.asGML2( doc ) ), expectedGML2 ); + QGSCOMPAREGML( elemToString( exportLine.asGml2( doc ) ), expectedGML2 ); QString expectedGML2prec3( QStringLiteral( "0.333,0.667 1.333,1.667 2.333,2.667" ) ); - QGSCOMPAREGML( elemToString( exportLineFloat.asGML2( doc, 3 ) ), expectedGML2prec3 ); + QGSCOMPAREGML( elemToString( exportLineFloat.asGml2( doc, 3 ) ), expectedGML2prec3 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsCircularString().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsCircularString().asGml2( doc ) ), expectedGML2empty ); //asGML3 QString expectedGML3( QStringLiteral( "31 32 41 42 51 52" ) ); - QCOMPARE( elemToString( exportLine.asGML3( doc ) ), expectedGML3 ); + QCOMPARE( elemToString( exportLine.asGml3( doc ) ), expectedGML3 ); QString expectedGML3prec3( QStringLiteral( "0.333 0.667 1.333 1.667 2.333 2.667" ) ); - QCOMPARE( elemToString( exportLineFloat.asGML3( doc, 3 ) ), expectedGML3prec3 ); + QCOMPARE( elemToString( exportLineFloat.asGml3( doc, 3 ) ), expectedGML3prec3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsCircularString().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsCircularString().asGml3( doc ) ), expectedGML3empty ); //asJSON QString expectedJson( QStringLiteral( "{\"type\": \"LineString\", \"coordinates\": [ [31, 32], [41, 42], [51, 52]]}" ) ); - QCOMPARE( exportLine.asJSON(), expectedJson ); + QCOMPARE( exportLine.asJson(), expectedJson ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"LineString\", \"coordinates\": [ [0.333, 0.667], [1.333, 1.667], [2.333, 2.667]]}" ) ); - QCOMPARE( exportLineFloat.asJSON( 3 ), expectedJsonPrec3 ); + QCOMPARE( exportLineFloat.asJson( 3 ), expectedJsonPrec3 ); //length QgsCircularString l19; @@ -3188,25 +3188,25 @@ void TestQgsGeometry::lineString() << QgsPoint( 2 + 1 / 3.0, 2 + 2 / 3.0 ) ); QDomDocument doc( QStringLiteral( "gml" ) ); QString expectedGML2( QStringLiteral( "31,32 41,42 51,52" ) ); - QGSCOMPAREGML( elemToString( exportLine.asGML2( doc ) ), expectedGML2 ); + QGSCOMPAREGML( elemToString( exportLine.asGml2( doc ) ), expectedGML2 ); QString expectedGML2prec3( QStringLiteral( "0.333,0.667 1.333,1.667 2.333,2.667" ) ); - QGSCOMPAREGML( elemToString( exportLineFloat.asGML2( doc, 3 ) ), expectedGML2prec3 ); + QGSCOMPAREGML( elemToString( exportLineFloat.asGml2( doc, 3 ) ), expectedGML2prec3 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsLineString().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsLineString().asGml2( doc ) ), expectedGML2empty ); //asGML3 QString expectedGML3( QStringLiteral( "31 32 41 42 51 52" ) ); - QCOMPARE( elemToString( exportLine.asGML3( doc ) ), expectedGML3 ); + QCOMPARE( elemToString( exportLine.asGml3( doc ) ), expectedGML3 ); QString expectedGML3prec3( QStringLiteral( "0.333 0.667 1.333 1.667 2.333 2.667" ) ); - QCOMPARE( elemToString( exportLineFloat.asGML3( doc, 3 ) ), expectedGML3prec3 ); + QCOMPARE( elemToString( exportLineFloat.asGml3( doc, 3 ) ), expectedGML3prec3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsLineString().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsLineString().asGml3( doc ) ), expectedGML3empty ); //asJSON QString expectedJson( QStringLiteral( "{\"type\": \"LineString\", \"coordinates\": [ [31, 32], [41, 42], [51, 52]]}" ) ); - QCOMPARE( exportLine.asJSON(), expectedJson ); + QCOMPARE( exportLine.asJson(), expectedJson ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"LineString\", \"coordinates\": [ [0.333, 0.667], [1.333, 1.667], [2.333, 2.667]]}" ) ); - QCOMPARE( exportLineFloat.asJSON( 3 ), expectedJsonPrec3 ); + QCOMPARE( exportLineFloat.asJson( 3 ), expectedJsonPrec3 ); //length QgsLineString l19; @@ -4798,19 +4798,19 @@ void TestQgsGeometry::polygon() // as GML2 QString expectedSimpleGML2( QStringLiteral( "0,0 0,10 10,10 10,0 0,0" ) ); - QGSCOMPAREGML( elemToString( exportPolygon.asGML2( doc ) ), expectedSimpleGML2 ); + QGSCOMPAREGML( elemToString( exportPolygon.asGml2( doc ) ), expectedSimpleGML2 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsPolygon().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsPolygon().asGml2( doc ) ), expectedGML2empty ); //as GML3 QString expectedSimpleGML3( QStringLiteral( "0 0 0 10 10 10 10 0 0 0" ) ); - QCOMPARE( elemToString( exportPolygon.asGML3( doc ) ), expectedSimpleGML3 ); + QCOMPARE( elemToString( exportPolygon.asGml3( doc ) ), expectedSimpleGML3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsPolygon().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsPolygon().asGml3( doc ) ), expectedGML3empty ); // as JSON QString expectedSimpleJson( QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]] }" ) ); - QCOMPARE( exportPolygon.asJSON(), expectedSimpleJson ); + QCOMPARE( exportPolygon.asJson(), expectedSimpleJson ); ring = new QgsLineString(); ring->setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::Point, 1, 1 ) @@ -4819,7 +4819,7 @@ void TestQgsGeometry::polygon() exportPolygon.addInteriorRing( ring ); QString expectedJson( QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [[ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0]], [ [1, 1], [1, 9], [9, 9], [9, 1], [1, 1]]] }" ) ); - QCOMPARE( exportPolygon.asJSON(), expectedJson ); + QCOMPARE( exportPolygon.asJson(), expectedJson ); QgsPolygon exportPolygonFloat; ext = new QgsLineString(); @@ -4834,24 +4834,24 @@ void TestQgsGeometry::polygon() exportPolygonFloat.addInteriorRing( ring ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [[ [1.111, 1.111], [1.111, 11.111], [11.111, 11.111], [11.111, 1.111], [1.111, 1.111]], [ [0.667, 0.667], [0.667, 1.333], [1.333, 1.333], [1.333, 0.667], [0.667, 0.667]]] }" ) ); - QCOMPARE( exportPolygonFloat.asJSON( 3 ), expectedJsonPrec3 ); + QCOMPARE( exportPolygonFloat.asJson( 3 ), expectedJsonPrec3 ); // as GML2 QString expectedGML2( QStringLiteral( "0,0 0,10 10,10 10,0 0,0" ) ); expectedGML2 += QStringLiteral( "1,1 1,9 9,9 9,1 1,1" ); - QGSCOMPAREGML( elemToString( exportPolygon.asGML2( doc ) ), expectedGML2 ); + QGSCOMPAREGML( elemToString( exportPolygon.asGml2( doc ) ), expectedGML2 ); QString expectedGML2prec3( QStringLiteral( "1.111,1.111 1.111,11.111 11.111,11.111 11.111,1.111 1.111,1.111" ) ); expectedGML2prec3 += QStringLiteral( "0.667,0.667 0.667,1.333 1.333,1.333 1.333,0.667 0.667,0.667" ); - QGSCOMPAREGML( elemToString( exportPolygonFloat.asGML2( doc, 3 ) ), expectedGML2prec3 ); + QGSCOMPAREGML( elemToString( exportPolygonFloat.asGml2( doc, 3 ) ), expectedGML2prec3 ); //as GML3 QString expectedGML3( QStringLiteral( "0 0 0 10 10 10 10 0 0 0" ) ); expectedGML3 += QStringLiteral( "1 1 1 9 9 9 9 1 1 1" ); - QCOMPARE( elemToString( exportPolygon.asGML3( doc ) ), expectedGML3 ); + QCOMPARE( elemToString( exportPolygon.asGml3( doc ) ), expectedGML3 ); QString expectedGML3prec3( QStringLiteral( "1.111 1.111 1.111 11.111 11.111 11.111 11.111 1.111 1.111 1.111" ) ); expectedGML3prec3 += QStringLiteral( "0.667 0.667 0.667 1.333 1.333 1.333 1.333 0.667 0.667 0.667" ); - QCOMPARE( elemToString( exportPolygonFloat.asGML3( doc, 3 ) ), expectedGML3prec3 ); + QCOMPARE( elemToString( exportPolygonFloat.asGml3( doc, 3 ) ), expectedGML3prec3 ); //removing the fourth to last vertex removes the whole ring QgsPolygon p20; @@ -6166,21 +6166,21 @@ void TestQgsGeometry::triangle() QgsPoint( 6 + 1 / 3.0, 5 + 2 / 3.0 ) ); QDomDocument doc( QStringLiteral( "gml" ) ); QString expectedGML2( QStringLiteral( "1,2 3,4 6,5 1,2" ) ); - QGSCOMPAREGML( elemToString( exportTriangle.asGML2( doc ) ), expectedGML2 ); + QGSCOMPAREGML( elemToString( exportTriangle.asGml2( doc ) ), expectedGML2 ); QString expectedGML2prec3( QStringLiteral( "1.333,2.667 3.333,4.667 6.333,5.667 1.333,2.667" ) ); - QGSCOMPAREGML( elemToString( exportTriangleFloat.asGML2( doc, 3 ) ), expectedGML2prec3 ); + QGSCOMPAREGML( elemToString( exportTriangleFloat.asGml2( doc, 3 ) ), expectedGML2prec3 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsTriangle().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsTriangle().asGml2( doc ) ), expectedGML2empty ); //asGML3 QString expectedGML3( QStringLiteral( "1 2 3 4 6 5 1 2" ) ); - QCOMPARE( elemToString( exportTriangle.asGML3( doc ) ), expectedGML3 ); + QCOMPARE( elemToString( exportTriangle.asGml3( doc ) ), expectedGML3 ); QString expectedGML3prec3( QStringLiteral( "1.333 2.667 3.333 4.667 6.333 5.667 1.333 2.667" ) ); - QCOMPARE( elemToString( exportTriangleFloat.asGML3( doc, 3 ) ), expectedGML3prec3 ); + QCOMPARE( elemToString( exportTriangleFloat.asGml3( doc, 3 ) ), expectedGML3prec3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsTriangle().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsTriangle().asGml3( doc ) ), expectedGML3empty ); QString expectedGML3Z( QStringLiteral( "1 2 3 11 12 13 1 12 23 1 2 3" ) ); - QCOMPARE( elemToString( exportTriangleZ.asGML3( doc ) ), expectedGML3Z ); + QCOMPARE( elemToString( exportTriangleZ.asGml3( doc ) ), expectedGML3Z ); // lengths and angles @@ -7778,21 +7778,21 @@ void TestQgsGeometry::curvePolygon() // as GML2 QString expectedSimpleGML2( QStringLiteral( "0,0 1,0 2,0 2,0 2,0 2,0.1 1.9,0.1 1.9,0.1 1.9,0.1 1.9,0.1 1.9,0.1 1.9,0.1 1.9,0.2 1.8,0.2 1.8,0.2 1.8,0.2 1.8,0.2 1.8,0.2 1.8,0.2 1.7,0.3 1.7,0.3 1.7,0.3 1.7,0.3 1.7,0.3 1.6,0.3 1.6,0.3 1.6,0.3 1.6,0.4 1.6,0.4 1.6,0.4 1.5,0.4 1.5,0.4 1.5,0.4 1.5,0.4 1.5,0.4 1.4,0.4 1.4,0.4 1.4,0.4 1.4,0.4 1.4,0.4 1.3,0.5 1.3,0.5 1.3,0.5 1.3,0.5 1.2,0.5 1.2,0.5 1.2,0.5 1.2,0.5 1.2,0.5 1.1,0.5 1.1,0.5 1.1,0.5 1.1,0.5 1.1,0.5 1,0.5 1,0.5 1,0.5 1,0.5 0.9,0.5 0.9,0.5 0.9,0.5 0.9,0.5 0.9,0.5 0.8,0.5 0.8,0.5 0.8,0.5 0.8,0.5 0.8,0.5 0.7,0.5 0.7,0.5 0.7,0.5 0.7,0.5 0.6,0.4 0.6,0.4 0.6,0.4 0.6,0.4 0.6,0.4 0.5,0.4 0.5,0.4 0.5,0.4 0.5,0.4 0.5,0.4 0.4,0.4 0.4,0.4 0.4,0.4 0.4,0.3 0.4,0.3 0.4,0.3 0.3,0.3 0.3,0.3 0.3,0.3 0.3,0.3 0.3,0.3 0.2,0.2 0.2,0.2 0.2,0.2 0.2,0.2 0.2,0.2 0.2,0.2 0.1,0.2 0.1,0.1 0.1,0.1 0.1,0.1 0.1,0.1 0.1,0.1 0.1,0.1 0,0.1 0,0 0,0 0,0" ) ); - QString res = elemToString( exportPolygon.asGML2( doc, 1 ) ); + QString res = elemToString( exportPolygon.asGml2( doc, 1 ) ); QGSCOMPAREGML( res, expectedSimpleGML2 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsCurvePolygon().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsCurvePolygon().asGml2( doc ) ), expectedGML2empty ); //as GML3 QString expectedSimpleGML3( QStringLiteral( "0 0 10 1 0 11 2 0 12 1 0.5 13 0 0 10" ) ); - res = elemToString( exportPolygon.asGML3( doc, 2 ) ); - QCOMPARE( elemToString( exportPolygon.asGML3( doc ) ), expectedSimpleGML3 ); + res = elemToString( exportPolygon.asGml3( doc, 2 ) ); + QCOMPARE( elemToString( exportPolygon.asGml3( doc ) ), expectedSimpleGML3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsCurvePolygon().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsCurvePolygon().asGml3( doc ) ), expectedGML3empty ); // as JSON QString expectedSimpleJson( QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [[ [0, 0], [1, 0], [2, 0], [2, 0], [2, 0], [2, 0.1], [1.9, 0.1], [1.9, 0.1], [1.9, 0.1], [1.9, 0.1], [1.9, 0.1], [1.9, 0.1], [1.9, 0.2], [1.8, 0.2], [1.8, 0.2], [1.8, 0.2], [1.8, 0.2], [1.8, 0.2], [1.8, 0.2], [1.7, 0.3], [1.7, 0.3], [1.7, 0.3], [1.7, 0.3], [1.7, 0.3], [1.6, 0.3], [1.6, 0.3], [1.6, 0.3], [1.6, 0.4], [1.6, 0.4], [1.6, 0.4], [1.5, 0.4], [1.5, 0.4], [1.5, 0.4], [1.5, 0.4], [1.5, 0.4], [1.4, 0.4], [1.4, 0.4], [1.4, 0.4], [1.4, 0.4], [1.4, 0.4], [1.3, 0.5], [1.3, 0.5], [1.3, 0.5], [1.3, 0.5], [1.2, 0.5], [1.2, 0.5], [1.2, 0.5], [1.2, 0.5], [1.2, 0.5], [1.1, 0.5], [1.1, 0.5], [1.1, 0.5], [1.1, 0.5], [1.1, 0.5], [1, 0.5], [1, 0.5], [1, 0.5], [1, 0.5], [0.9, 0.5], [0.9, 0.5], [0.9, 0.5], [0.9, 0.5], [0.9, 0.5], [0.8, 0.5], [0.8, 0.5], [0.8, 0.5], [0.8, 0.5], [0.8, 0.5], [0.7, 0.5], [0.7, 0.5], [0.7, 0.5], [0.7, 0.5], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.5, 0.4], [0.5, 0.4], [0.5, 0.4], [0.5, 0.4], [0.5, 0.4], [0.4, 0.4], [0.4, 0.4], [0.4, 0.4], [0.4, 0.3], [0.4, 0.3], [0.4, 0.3], [0.3, 0.3], [0.3, 0.3], [0.3, 0.3], [0.3, 0.3], [0.3, 0.3], [0.2, 0.2], [0.2, 0.2], [0.2, 0.2], [0.2, 0.2], [0.2, 0.2], [0.2, 0.2], [0.1, 0.2], [0.1, 0.1], [0.1, 0.1], [0.1, 0.1], [0.1, 0.1], [0.1, 0.1], [0.1, 0.1], [0, 0.1], [0, 0], [0, 0], [0, 0]]] }" ) ); - res = exportPolygon.asJSON( 1 ); + res = exportPolygon.asJson( 1 ); QCOMPARE( res, expectedSimpleJson ); ring = new QgsCircularString(); @@ -7801,7 +7801,7 @@ void TestQgsGeometry::curvePolygon() exportPolygon.addInteriorRing( ring ); QString expectedJson( QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [[ [0, 0], [1, 0], [2, 0], [2, 0], [2, 0], [2, 0.1], [1.9, 0.1], [1.9, 0.1], [1.9, 0.1], [1.9, 0.1], [1.9, 0.1], [1.9, 0.1], [1.9, 0.2], [1.8, 0.2], [1.8, 0.2], [1.8, 0.2], [1.8, 0.2], [1.8, 0.2], [1.8, 0.2], [1.7, 0.3], [1.7, 0.3], [1.7, 0.3], [1.7, 0.3], [1.7, 0.3], [1.6, 0.3], [1.6, 0.3], [1.6, 0.3], [1.6, 0.4], [1.6, 0.4], [1.6, 0.4], [1.5, 0.4], [1.5, 0.4], [1.5, 0.4], [1.5, 0.4], [1.5, 0.4], [1.4, 0.4], [1.4, 0.4], [1.4, 0.4], [1.4, 0.4], [1.4, 0.4], [1.3, 0.5], [1.3, 0.5], [1.3, 0.5], [1.3, 0.5], [1.2, 0.5], [1.2, 0.5], [1.2, 0.5], [1.2, 0.5], [1.2, 0.5], [1.1, 0.5], [1.1, 0.5], [1.1, 0.5], [1.1, 0.5], [1.1, 0.5], [1, 0.5], [1, 0.5], [1, 0.5], [1, 0.5], [0.9, 0.5], [0.9, 0.5], [0.9, 0.5], [0.9, 0.5], [0.9, 0.5], [0.8, 0.5], [0.8, 0.5], [0.8, 0.5], [0.8, 0.5], [0.8, 0.5], [0.7, 0.5], [0.7, 0.5], [0.7, 0.5], [0.7, 0.5], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.6, 0.4], [0.5, 0.4], [0.5, 0.4], [0.5, 0.4], [0.5, 0.4], [0.5, 0.4], [0.4, 0.4], [0.4, 0.4], [0.4, 0.4], [0.4, 0.3], [0.4, 0.3], [0.4, 0.3], [0.3, 0.3], [0.3, 0.3], [0.3, 0.3], [0.3, 0.3], [0.3, 0.3], [0.2, 0.2], [0.2, 0.2], [0.2, 0.2], [0.2, 0.2], [0.2, 0.2], [0.2, 0.2], [0.1, 0.2], [0.1, 0.1], [0.1, 0.1], [0.1, 0.1], [0.1, 0.1], [0.1, 0.1], [0.1, 0.1], [0, 0.1], [0, 0], [0, 0], [0, 0]], [ [0, 0], [0.1, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.2, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0.1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]] }" ) ); - res = exportPolygon.asJSON( 1 ); + res = exportPolygon.asJson( 1 ); QCOMPARE( res, expectedJson ); @@ -7816,25 +7816,25 @@ void TestQgsGeometry::curvePolygon() exportPolygonFloat.addInteriorRing( ring ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [[ [0, 0], [0.333, 0], [0.667, 0], [0.669, 0.006], [0.671, 0.012], [0.673, 0.018], [0.676, 0.024], [0.677, 0.029], [0.679, 0.035], [0.681, 0.042], [0.683, 0.048], [0.684, 0.054], [0.686, 0.06], [0.687, 0.066], [0.688, 0.072], [0.689, 0.078], [0.69, 0.084], [0.691, 0.091], [0.692, 0.097], [0.693, 0.103], [0.693, 0.109], [0.694, 0.116], [0.694, 0.122], [0.694, 0.128], [0.694, 0.135], [0.694, 0.141], [0.694, 0.147], [0.694, 0.153], [0.694, 0.16], [0.693, 0.166], [0.693, 0.172], [0.692, 0.178], [0.692, 0.185], [0.691, 0.191], [0.69, 0.197], [0.689, 0.203], [0.687, 0.209], [0.686, 0.216], [0.685, 0.222], [0.683, 0.228], [0.682, 0.234], [0.68, 0.24], [0.678, 0.246], [0.676, 0.252], [0.674, 0.258], [0.672, 0.264], [0.67, 0.27], [0.668, 0.275], [0.665, 0.281], [0.663, 0.287], [0.66, 0.293], [0.657, 0.298], [0.654, 0.304], [0.652, 0.31], [0.649, 0.315], [0.645, 0.321], [0.642, 0.326], [0.639, 0.331], [0.636, 0.337], [0.632, 0.342], [0.628, 0.347], [0.625, 0.352], [0.621, 0.357], [0.617, 0.362], [0.613, 0.367], [0.609, 0.372], [0.605, 0.377], [0.601, 0.381], [0.597, 0.386], [0.592, 0.39], [0.588, 0.395], [0.584, 0.399], [0.579, 0.404], [0.574, 0.408], [0.57, 0.412], [0.565, 0.416], [0.56, 0.42], [0.555, 0.424], [0.55, 0.428], [0.545, 0.431], [0.54, 0.435], [0.535, 0.439], [0.529, 0.442], [0.524, 0.445], [0.519, 0.449], [0.513, 0.452], [0.508, 0.455], [0.502, 0.458], [0.497, 0.461], [0.491, 0.464], [0.485, 0.466], [0.48, 0.469], [0.474, 0.471], [0.468, 0.474], [0.462, 0.476], [0.456, 0.478], [0.451, 0.48], [0.445, 0.482], [0.439, 0.484], [0.433, 0.486], [0.426, 0.488], [0.42, 0.489], [0.414, 0.491], [0.408, 0.492], [0.402, 0.493], [0.396, 0.495], [0.39, 0.496], [0.383, 0.497], [0.377, 0.497], [0.371, 0.498], [0.365, 0.499], [0.358, 0.499], [0.352, 0.5], [0.346, 0.5], [0.34, 0.5], [0.333, 0.5], [0.327, 0.5], [0.321, 0.5], [0.314, 0.5], [0.308, 0.499], [0.302, 0.499], [0.296, 0.498], [0.289, 0.497], [0.283, 0.497], [0.277, 0.496], [0.271, 0.495], [0.265, 0.493], [0.259, 0.492], [0.252, 0.491], [0.246, 0.489], [0.24, 0.488], [0.234, 0.486], [0.228, 0.484], [0.222, 0.482], [0.216, 0.48], [0.21, 0.478], [0.204, 0.476], [0.198, 0.474], [0.193, 0.471], [0.187, 0.469], [0.181, 0.466], [0.176, 0.464], [0.17, 0.461], [0.164, 0.458], [0.159, 0.455], [0.153, 0.452], [0.148, 0.449], [0.143, 0.445], [0.137, 0.442], [0.132, 0.439], [0.127, 0.435], [0.122, 0.431], [0.117, 0.428], [0.112, 0.424], [0.107, 0.42], [0.102, 0.416], [0.097, 0.412], [0.092, 0.408], [0.088, 0.404], [0.083, 0.399], [0.079, 0.395], [0.074, 0.39], [0.07, 0.386], [0.066, 0.381], [0.061, 0.377], [0.057, 0.372], [0.053, 0.367], [0.049, 0.362], [0.046, 0.357], [0.042, 0.352], [0.038, 0.347], [0.035, 0.342], [0.031, 0.337], [0.028, 0.331], [0.024, 0.326], [0.021, 0.321], [0.018, 0.315], [0.015, 0.31], [0.012, 0.304], [0.009, 0.298], [0.007, 0.293], [0.004, 0.287], [0.001, 0.281], [-0.001, 0.275], [-0.003, 0.27], [-0.005, 0.264], [-0.008, 0.258], [-0.01, 0.252], [-0.012, 0.246], [-0.013, 0.24], [-0.015, 0.234], [-0.017, 0.228], [-0.018, 0.222], [-0.02, 0.216], [-0.021, 0.209], [-0.022, 0.203], [-0.023, 0.197], [-0.024, 0.191], [-0.025, 0.185], [-0.026, 0.178], [-0.026, 0.172], [-0.027, 0.166], [-0.027, 0.16], [-0.027, 0.153], [-0.028, 0.147], [-0.028, 0.141], [-0.028, 0.135], [-0.028, 0.128], [-0.027, 0.122], [-0.027, 0.116], [-0.027, 0.109], [-0.026, 0.103], [-0.025, 0.097], [-0.025, 0.091], [-0.024, 0.084], [-0.023, 0.078], [-0.022, 0.072], [-0.02, 0.066], [-0.019, 0.06], [-0.018, 0.054], [-0.016, 0.048], [-0.014, 0.042], [-0.013, 0.035], [-0.011, 0.029], [-0.009, 0.024], [-0.007, 0.018], [-0.005, 0.012], [-0.002, 0.006], [0, 0]], [ [0, 0], [0.033, 0], [0.067, 0], [0.066, 0.001], [0.066, 0.001], [0.065, 0.002], [0.065, 0.002], [0.064, 0.003], [0.064, 0.003], [0.063, 0.004], [0.063, 0.004], [0.062, 0.005], [0.062, 0.005], [0.061, 0.006], [0.061, 0.006], [0.06, 0.007], [0.06, 0.007], [0.059, 0.008], [0.059, 0.008], [0.058, 0.009], [0.057, 0.009], [0.057, 0.009], [0.056, 0.01], [0.056, 0.01], [0.055, 0.011], [0.054, 0.011], [0.054, 0.011], [0.053, 0.012], [0.052, 0.012], [0.052, 0.012], [0.051, 0.013], [0.051, 0.013], [0.05, 0.013], [0.049, 0.014], [0.049, 0.014], [0.048, 0.014], [0.047, 0.014], [0.046, 0.015], [0.046, 0.015], [0.045, 0.015], [0.044, 0.015], [0.044, 0.015], [0.043, 0.016], [0.042, 0.016], [0.042, 0.016], [0.041, 0.016], [0.04, 0.016], [0.039, 0.016], [0.039, 0.016], [0.038, 0.016], [0.037, 0.016], [0.037, 0.017], [0.036, 0.017], [0.035, 0.017], [0.034, 0.017], [0.034, 0.017], [0.033, 0.017], [0.032, 0.017], [0.032, 0.017], [0.031, 0.017], [0.03, 0.017], [0.029, 0.016], [0.029, 0.016], [0.028, 0.016], [0.027, 0.016], [0.027, 0.016], [0.026, 0.016], [0.025, 0.016], [0.024, 0.016], [0.024, 0.016], [0.023, 0.015], [0.022, 0.015], [0.022, 0.015], [0.021, 0.015], [0.02, 0.015], [0.02, 0.014], [0.019, 0.014], [0.018, 0.014], [0.017, 0.014], [0.017, 0.013], [0.016, 0.013], [0.016, 0.013], [0.015, 0.012], [0.014, 0.012], [0.014, 0.012], [0.013, 0.011], [0.012, 0.011], [0.012, 0.011], [0.011, 0.01], [0.01, 0.01], [0.01, 0.009], [0.009, 0.009], [0.009, 0.009], [0.008, 0.008], [0.008, 0.008], [0.007, 0.007], [0.006, 0.007], [0.006, 0.006], [0.005, 0.006], [0.005, 0.005], [0.004, 0.005], [0.004, 0.004], [0.003, 0.004], [0.003, 0.003], [0.002, 0.003], [0.002, 0.002], [0.001, 0.002], [0.001, 0.001], [0, 0.001], [0, 0]]] }" ) ); - res = exportPolygonFloat.asJSON( 3 ); - QCOMPARE( exportPolygonFloat.asJSON( 3 ), expectedJsonPrec3 ); + res = exportPolygonFloat.asJson( 3 ); + QCOMPARE( exportPolygonFloat.asJson( 3 ), expectedJsonPrec3 ); // as GML2 QString expectedGML2( QStringLiteral( "0,0 1,0 2,0 1.98685,0.01722 1.97341,0.03421 1.95967,0.05096 1.94564,0.06747 1.93133,0.08374 1.91674,0.09976 1.90188,0.11552 1.88674,0.13102 1.87134,0.14625 1.85567,0.16122 1.83975,0.17592 1.82358,0.19033 1.80716,0.20446 1.79049,0.21831 1.77359,0.23186 1.75646,0.24512 1.7391,0.25809 1.72151,0.27074 1.70371,0.2831 1.6857,0.29514 1.66748,0.30687 1.64907,0.31828 1.63045,0.32936 1.61165,0.34013 1.59267,0.35057 1.5735,0.36067 1.55417,0.37045 1.53466,0.37988 1.515,0.38898 1.49518,0.39773 1.47522,0.40614 1.45511,0.41421 1.43486,0.42192 1.41448,0.42928 1.39398,0.43629 1.37336,0.44294 1.35263,0.44923 1.33179,0.45516 1.31086,0.46073 1.28983,0.46594 1.26871,0.47078 1.24751,0.47525 1.22624,0.47936 1.2049,0.48309 1.18349,0.48646 1.16204,0.48945 1.14053,0.49208 1.11898,0.49432 1.0974,0.4962 1.07578,0.4977 1.05415,0.49883 1.0325,0.49958 1.01083,0.49995 0.98917,0.49995 0.9675,0.49958 0.94585,0.49883 0.92422,0.4977 0.9026,0.4962 0.88102,0.49432 0.85947,0.49208 0.83796,0.48945 0.81651,0.48646 0.7951,0.48309 0.77376,0.47936 0.75249,0.47525 0.73129,0.47078 0.71017,0.46594 0.68914,0.46073 0.66821,0.45516 0.64737,0.44923 0.62664,0.44294 0.60602,0.43629 0.58552,0.42928 0.56514,0.42192 0.54489,0.41421 0.52478,0.40614 0.50482,0.39773 0.485,0.38898 0.46534,0.37988 0.44583,0.37045 0.4265,0.36067 0.40733,0.35057 0.38835,0.34013 0.36955,0.32936 0.35093,0.31828 0.33252,0.30687 0.3143,0.29514 0.29629,0.2831 0.27849,0.27074 0.2609,0.25809 0.24354,0.24512 0.22641,0.23186 0.20951,0.21831 0.19284,0.20446 0.17642,0.19033 0.16025,0.17592 0.14433,0.16122 0.12866,0.14625 0.11326,0.13102 0.09812,0.11552 0.08326,0.09976 0.06867,0.08374 0.05436,0.06747 0.04033,0.05096 0.02659,0.03421 0.01315,0.01722 0,00,0 0.1,0 0.2,0 0.19869,0.00172 0.19734,0.00342 0.19597,0.0051 0.19456,0.00675 0.19313,0.00837 0.19167,0.00998 0.19019,0.01155 0.18867,0.0131 0.18713,0.01463 0.18557,0.01612 0.18398,0.01759 0.18236,0.01903 0.18072,0.02045 0.17905,0.02183 0.17736,0.02319 0.17565,0.02451 0.17391,0.02581 0.17215,0.02707 0.17037,0.02831 0.16857,0.02951 0.16675,0.03069 0.16491,0.03183 0.16305,0.03294 0.16117,0.03401 0.15927,0.03506 0.15735,0.03607 0.15542,0.03704 0.15347,0.03799 0.1515,0.0389 0.14952,0.03977 0.14752,0.04061 0.14551,0.04142 0.14349,0.04219 0.14145,0.04293 0.1394,0.04363 0.13734,0.04429 0.13526,0.04492 0.13318,0.04552 0.13109,0.04607 0.12898,0.04659 0.12687,0.04708 0.12475,0.04753 0.12262,0.04794 0.12049,0.04831 0.11835,0.04865 0.1162,0.04895 0.11405,0.04921 0.1119,0.04943 0.10974,0.04962 0.10758,0.04977 0.10541,0.04988 0.10325,0.04996 0.10108,0.05 0.09892,0.05 0.09675,0.04996 0.09459,0.04988 0.09242,0.04977 0.09026,0.04962 0.0881,0.04943 0.08595,0.04921 0.0838,0.04895 0.08165,0.04865 0.07951,0.04831 0.07738,0.04794 0.07525,0.04753 0.07313,0.04708 0.07102,0.04659 0.06891,0.04607 0.06682,0.04552 0.06474,0.04492 0.06266,0.04429 0.0606,0.04363 0.05855,0.04293 0.05651,0.04219 0.05449,0.04142 0.05248,0.04061 0.05048,0.03977 0.0485,0.0389 0.04653,0.03799 0.04458,0.03704 0.04265,0.03607 0.04073,0.03506 0.03883,0.03401 0.03695,0.03294 0.03509,0.03183 0.03325,0.03069 0.03143,0.02951 0.02963,0.02831 0.02785,0.02707 0.02609,0.02581 0.02435,0.02451 0.02264,0.02319 0.02095,0.02183 0.01928,0.02045 0.01764,0.01903 0.01602,0.01759 0.01443,0.01612 0.01287,0.01463 0.01133,0.0131 0.00981,0.01155 0.00833,0.00998 0.00687,0.00837 0.00544,0.00675 0.00403,0.0051 0.00266,0.00342 0.00131,0.00172 0,0" ) ); - res = elemToString( exportPolygon.asGML2( doc, 5 ) ); + res = elemToString( exportPolygon.asGml2( doc, 5 ) ); QGSCOMPAREGML( res, expectedGML2 ); QString expectedGML2prec2( QStringLiteral( "0,0 1,0 2,0 1.99,0.02 1.97,0.03 1.96,0.05 1.95,0.07 1.93,0.08 1.92,0.1 1.9,0.12 1.89,0.13 1.87,0.15 1.86,0.16 1.84,0.18 1.82,0.19 1.81,0.2 1.79,0.22 1.77,0.23 1.76,0.25 1.74,0.26 1.72,0.27 1.7,0.28 1.69,0.3 1.67,0.31 1.65,0.32 1.63,0.33 1.61,0.34 1.59,0.35 1.57,0.36 1.55,0.37 1.53,0.38 1.52,0.39 1.5,0.4 1.48,0.41 1.46,0.41 1.43,0.42 1.41,0.43 1.39,0.44 1.37,0.44 1.35,0.45 1.33,0.46 1.31,0.46 1.29,0.47 1.27,0.47 1.25,0.48 1.23,0.48 1.2,0.48 1.18,0.49 1.16,0.49 1.14,0.49 1.12,0.49 1.1,0.5 1.08,0.5 1.05,0.5 1.03,0.5 1.01,0.5 0.99,0.5 0.97,0.5 0.95,0.5 0.92,0.5 0.9,0.5 0.88,0.49 0.86,0.49 0.84,0.49 0.82,0.49 0.8,0.48 0.77,0.48 0.75,0.48 0.73,0.47 0.71,0.47 0.69,0.46 0.67,0.46 0.65,0.45 0.63,0.44 0.61,0.44 0.59,0.43 0.57,0.42 0.54,0.41 0.52,0.41 0.5,0.4 0.48,0.39 0.47,0.38 0.45,0.37 0.43,0.36 0.41,0.35 0.39,0.34 0.37,0.33 0.35,0.32 0.33,0.31 0.31,0.3 0.3,0.28 0.28,0.27 0.26,0.26 0.24,0.25 0.23,0.23 0.21,0.22 0.19,0.2 0.18,0.19 0.16,0.18 0.14,0.16 0.13,0.15 0.11,0.13 0.1,0.12 0.08,0.1 0.07,0.08 0.05,0.07 0.04,0.05 0.03,0.03 0.01,0.02 0,00,0 0.1,0 0.2,0 0.2,0 0.2,0 0.2,0.01 0.19,0.01 0.19,0.01 0.19,0.01 0.19,0.01 0.19,0.01 0.19,0.01 0.19,0.02 0.18,0.02 0.18,0.02 0.18,0.02 0.18,0.02 0.18,0.02 0.18,0.02 0.17,0.03 0.17,0.03 0.17,0.03 0.17,0.03 0.17,0.03 0.16,0.03 0.16,0.03 0.16,0.03 0.16,0.04 0.16,0.04 0.16,0.04 0.15,0.04 0.15,0.04 0.15,0.04 0.15,0.04 0.15,0.04 0.14,0.04 0.14,0.04 0.14,0.04 0.14,0.04 0.14,0.04 0.13,0.05 0.13,0.05 0.13,0.05 0.13,0.05 0.12,0.05 0.12,0.05 0.12,0.05 0.12,0.05 0.12,0.05 0.11,0.05 0.11,0.05 0.11,0.05 0.11,0.05 0.11,0.05 0.1,0.05 0.1,0.05 0.1,0.05 0.1,0.05 0.09,0.05 0.09,0.05 0.09,0.05 0.09,0.05 0.09,0.05 0.08,0.05 0.08,0.05 0.08,0.05 0.08,0.05 0.08,0.05 0.07,0.05 0.07,0.05 0.07,0.05 0.07,0.05 0.06,0.04 0.06,0.04 0.06,0.04 0.06,0.04 0.06,0.04 0.05,0.04 0.05,0.04 0.05,0.04 0.05,0.04 0.05,0.04 0.04,0.04 0.04,0.04 0.04,0.04 0.04,0.03 0.04,0.03 0.04,0.03 0.03,0.03 0.03,0.03 0.03,0.03 0.03,0.03 0.03,0.03 0.02,0.02 0.02,0.02 0.02,0.02 0.02,0.02 0.02,0.02 0.02,0.02 0.01,0.02 0.01,0.01 0.01,0.01 0.01,0.01 0.01,0.01 0.01,0.01 0.01,0.01 0,0.01 0,0 0,0 0,0" ) ); - res = elemToString( exportPolygon.asGML2( doc, 2 ) ); + res = elemToString( exportPolygon.asGml2( doc, 2 ) ); QGSCOMPAREGML( res, expectedGML2prec2 ); //as GML3 QString expectedGML3( QStringLiteral( "0 0 10 1 0 11 2 0 12 1 0.5 13 0 0 100 0 10 0.10000000000000001 0 11 0.20000000000000001 0 12 0.10000000000000001 0.05 13 0 0 10" ) ); - res = elemToString( exportPolygon.asGML3( doc ) ); + res = elemToString( exportPolygon.asGml3( doc ) ); QCOMPARE( res, expectedGML3 ); QString expectedGML3prec3( QStringLiteral( "0 0 10 1 0 11 2 0 12 1 0.5 13 0 0 100 0 10 0.1 0 11 0.2 0 12 0.1 0.05 13 0 0 10" ) ); - res = elemToString( exportPolygon.asGML3( doc, 3 ) ); + res = elemToString( exportPolygon.asGml3( doc, 3 ) ); QCOMPARE( res, expectedGML3prec3 ); //removing the fourth to last vertex removes the whole ring @@ -9118,31 +9118,31 @@ void TestQgsGeometry::compoundCurve() QDomDocument doc( QStringLiteral( "gml" ) ); QString expectedGML2( QStringLiteral( "31,32 41,42 51,52 61,62" ) ); - QString result = elemToString( exportCurve.asGML2( doc ) ); + QString result = elemToString( exportCurve.asGml2( doc ) ); QGSCOMPAREGML( result, expectedGML2 ); QString expectedGML2prec3( QStringLiteral( "0.333,0.667 1.333,1.667 2.333,2.667 3.333,3.667" ) ); - result = elemToString( exportCurveFloat.asGML2( doc, 3 ) ); + result = elemToString( exportCurveFloat.asGml2( doc, 3 ) ); QGSCOMPAREGML( result, expectedGML2prec3 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsCompoundCurve().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsCompoundCurve().asGml2( doc ) ), expectedGML2empty ); //asGML3 QString expectedGML3( QStringLiteral( "31 32 41 42 51 5251 52 61 62" ) ); - result = elemToString( exportCurve.asGML3( doc ) ); + result = elemToString( exportCurve.asGml3( doc ) ); QCOMPARE( result, expectedGML3 ); QString expectedGML3prec3( QStringLiteral( "0.333 0.667 1.333 1.667 2.333 2.6672.333 2.667 3.333 3.667" ) ); - result = elemToString( exportCurveFloat.asGML3( doc, 3 ) ); + result = elemToString( exportCurveFloat.asGml3( doc, 3 ) ); QCOMPARE( result, expectedGML3prec3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsCompoundCurve().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsCompoundCurve().asGml3( doc ) ), expectedGML3empty ); //asJSON QString expectedJson( QStringLiteral( "{\"type\": \"LineString\", \"coordinates\": [ [31, 32], [41, 42], [51, 52], [61, 62]]}" ) ); - result = exportCurve.asJSON(); + result = exportCurve.asJson(); QCOMPARE( result, expectedJson ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"LineString\", \"coordinates\": [ [0.333, 0.667], [1.333, 1.667], [2.333, 2.667], [3.333, 3.667]]}" ) ); - result = exportCurveFloat.asJSON( 3 ); + result = exportCurveFloat.asJson( 3 ); QCOMPARE( result, expectedJsonPrec3 ); //length @@ -10791,21 +10791,21 @@ void TestQgsGeometry::multiPoint() // as GML2 QString expectedSimpleGML2( QStringLiteral( "0,1010,0" ) ); - QString res = elemToString( exportC.asGML2( doc ) ); + QString res = elemToString( exportC.asGml2( doc ) ); QGSCOMPAREGML( res, expectedSimpleGML2 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsMultiPoint().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsMultiPoint().asGml2( doc ) ), expectedGML2empty ); //as GML3 QString expectedSimpleGML3( QStringLiteral( "0 1010 0" ) ); - res = elemToString( exportC.asGML3( doc ) ); + res = elemToString( exportC.asGml3( doc ) ); QCOMPARE( res, expectedSimpleGML3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsMultiPoint().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsMultiPoint().asGml3( doc ) ), expectedGML3empty ); // as JSON QString expectedSimpleJson( "{\"type\": \"MultiPoint\", \"coordinates\": [ [0, 10], [10, 0]] }" ); - res = exportC.asJSON(); + res = exportC.asJson(); QCOMPARE( res, expectedSimpleJson ); QgsMultiPoint exportFloat; @@ -10814,17 +10814,17 @@ void TestQgsGeometry::multiPoint() QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"MultiPoint\", \"coordinates\": [ [1.111, 11.111], [1.333, 0.667]] }" ) ); - res = exportFloat.asJSON( 3 ); + res = exportFloat.asJson( 3 ); QCOMPARE( res, expectedJsonPrec3 ); // as GML2 QString expectedGML2prec3( QStringLiteral( "1.111,11.1111.333,0.667" ) ); - res = elemToString( exportFloat.asGML2( doc, 3 ) ); + res = elemToString( exportFloat.asGml2( doc, 3 ) ); QGSCOMPAREGML( res, expectedGML2prec3 ); //as GML3 QString expectedGML3prec3( QStringLiteral( "1.111 11.1111.333 0.667" ) ); - res = elemToString( exportFloat.asGML3( doc, 3 ) ); + res = elemToString( exportFloat.asGml3( doc, 3 ) ); QCOMPARE( res, expectedGML3prec3 ); // insert geometry @@ -11315,21 +11315,21 @@ void TestQgsGeometry::multiLineString() // as GML2 QString expectedSimpleGML2( QStringLiteral( "7,17 3,1327,37 43,43" ) ); - QString res = elemToString( exportC.asGML2( doc ) ); + QString res = elemToString( exportC.asGml2( doc ) ); QGSCOMPAREGML( res, expectedSimpleGML2 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsMultiLineString().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsMultiLineString().asGml2( doc ) ), expectedGML2empty ); //as GML3 QString expectedSimpleGML3( QStringLiteral( "7 17 3 1327 37 43 43" ) ); - res = elemToString( exportC.asGML3( doc ) ); + res = elemToString( exportC.asGml3( doc ) ); QCOMPARE( res, expectedSimpleGML3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsMultiLineString().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsMultiLineString().asGml3( doc ) ), expectedGML3empty ); // as JSON QString expectedSimpleJson( "{\"type\": \"MultiLineString\", \"coordinates\": [[ [7, 17], [3, 13]], [ [27, 37], [43, 43]]] }" ); - res = exportC.asJSON(); + res = exportC.asJson(); QCOMPARE( res, expectedSimpleJson ); QgsMultiLineString exportFloat; @@ -11339,17 +11339,17 @@ void TestQgsGeometry::multiLineString() exportFloat.addGeometry( part.clone() ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"MultiLineString\", \"coordinates\": [[ [2.333, 5.667], [0.6, 4.333]], [ [9, 4.111], [1.049, 1.024]]] }" ) ); - res = exportFloat.asJSON( 3 ); + res = exportFloat.asJson( 3 ); QCOMPARE( res, expectedJsonPrec3 ); // as GML2 QString expectedGML2prec3( QStringLiteral( "2.333,5.667 0.6,4.3339,4.111 1.049,1.024" ) ); - res = elemToString( exportFloat.asGML2( doc, 3 ) ); + res = elemToString( exportFloat.asGml2( doc, 3 ) ); QGSCOMPAREGML( res, expectedGML2prec3 ); //as GML3 QString expectedGML3prec3( QStringLiteral( "2.333 5.667 0.6 4.3339 4.111 1.049 1.024" ) ); - res = elemToString( exportFloat.asGML3( doc, 3 ) ); + res = elemToString( exportFloat.asGml3( doc, 3 ) ); QCOMPARE( res, expectedGML3prec3 ); // insert geometry @@ -11973,21 +11973,21 @@ void TestQgsGeometry::multiCurve() // as GML2 QString expectedSimpleGML2( QStringLiteral( "7,17 6.9,17 6.9,17 6.8,17 6.8,17.1 6.7,17.1 6.7,17.1 6.6,17.1 6.6,17.1 6.5,17.1 6.5,17.1 6.4,17.1 6.4,17.1 6.3,17.1 6.2,17.2 6.2,17.2 6.1,17.2 6.1,17.2 6,17.2 6,17.2 5.9,17.2 5.9,17.2 5.8,17.2 5.7,17.2 5.7,17.1 5.6,17.1 5.6,17.1 5.5,17.1 5.5,17.1 5.4,17.1 5.4,17.1 5.3,17.1 5.3,17.1 5.2,17.1 5.2,17 5.1,17 5,17 5,17 4.9,17 4.9,17 4.8,16.9 4.8,16.9 4.7,16.9 4.7,16.9 4.6,16.9 4.6,16.8 4.5,16.8 4.5,16.8 4.4,16.8 4.4,16.7 4.3,16.7 4.3,16.7 4.3,16.6 4.2,16.6 4.2,16.6 4.1,16.5 4.1,16.5 4,16.5 4,16.4 3.9,16.4 3.9,16.4 3.9,16.3 3.8,16.3 3.8,16.3 3.7,16.2 3.7,16.2 3.7,16.1 3.6,16.1 3.6,16.1 3.6,16 3.5,16 3.5,15.9 3.5,15.9 3.4,15.8 3.4,15.8 3.4,15.7 3.3,15.7 3.3,15.7 3.3,15.6 3.2,15.6 3.2,15.5 3.2,15.5 3.2,15.4 3.1,15.4 3.1,15.3 3.1,15.3 3.1,15.2 3.1,15.2 3,15.1 3,15.1 3,15 3,15 3,14.9 3,14.8 2.9,14.8 2.9,14.7 2.9,14.7 2.9,14.6 2.9,14.6 2.9,14.5 2.9,14.5 2.9,14.4 2.9,14.4 2.9,14.3 2.8,14.2 2.8,14.2 2.8,14.1 2.8,14.1 2.8,14 2.8,14 2.8,13.9 2.8,13.9 2.8,13.8 2.8,13.8 2.9,13.7 2.9,13.6 2.9,13.6 2.9,13.5 2.9,13.5 2.9,13.4 2.9,13.4 2.9,13.3 2.9,13.3 2.9,13.2 3,13.2 3,13.1 3,13 3,13 3,12.9 3,12.9 3.1,12.8 3.1,12.8 3.1,12.7 3.1,12.7 3.1,12.6 3.2,12.6 3.2,12.5 3.2,12.5 3.2,12.4 3.3,12.4 3.3,12.3 3.3,12.3 3.4,12.3 3.4,12.2 3.4,12.2 3.5,12.1 3.5,12.1 3.5,12 3.6,12 3.6,11.9 3.6,11.9 3.7,11.9 3.7,11.8 3.7,11.8 3.8,11.7 3.8,11.7 3.9,11.7 3.9,11.6 3.9,11.6 4,11.6 4,11.5 4.1,11.5 4.1,11.5 4.2,11.4 4.2,11.4 4.3,11.4 4.3,11.3 4.3,11.3 4.4,11.3 4.4,11.2 4.5,11.2 4.5,11.2 4.6,11.2 4.6,11.1 4.7,11.1 4.7,11.1 4.8,11.1 4.8,11.1 4.9,11 4.9,11 5,11 5,11 5.1,11 5.2,11 5.2,10.9 5.3,10.9 5.3,10.9 5.4,10.9 5.4,10.9 5.5,10.9 5.5,10.9 5.6,10.9 5.6,10.9 5.7,10.9 5.7,10.8 5.8,10.8 5.9,10.8 5.9,10.8 6,10.8 6,10.8 6.1,10.8 6.1,10.8 6.2,10.8 6.2,10.8 6.3,10.9 6.4,10.9 6.4,10.9 6.5,10.9 6.5,10.9 6.6,10.9 6.6,10.9 6.7,10.9 6.7,10.9 6.8,10.9 6.8,11 6.9,11 6.9,11 7,1127,37 27.1,36.9 27.2,36.8 27.3,36.6 27.4,36.5 27.5,36.4 27.6,36.3 27.7,36.2 27.8,36 27.9,35.9 28,35.8 28.1,35.7 28.2,35.6 28.3,35.5 28.4,35.4 28.5,35.3 28.7,35.2 28.8,35.1 28.9,35 29,34.9 29.1,34.8 29.3,34.7 29.4,34.6 29.5,34.6 29.7,34.5 29.8,34.4 29.9,34.3 30.1,34.3 30.2,34.2 30.3,34.1 30.5,34 30.6,34 30.7,33.9 30.9,33.9 31,33.8 31.2,33.7 31.3,33.7 31.5,33.6 31.6,33.6 31.8,33.6 31.9,33.5 32.1,33.5 32.2,33.4 32.4,33.4 32.5,33.4 32.7,33.3 32.8,33.3 33,33.3 33.1,33.3 33.3,33.2 33.4,33.2 33.6,33.2 33.7,33.2 33.9,33.2 34,33.2 34.2,33.2 34.3,33.2 34.5,33.2 34.6,33.2 34.8,33.2 34.9,33.2 35.1,33.2 35.3,33.3 35.4,33.3 35.6,33.3 35.7,33.3 35.9,33.3 36,33.4 36.2,33.4 36.3,33.4 36.5,33.5 36.6,33.5 36.8,33.6 36.9,33.6 37.1,33.7 37.2,33.7 37.3,33.8 37.5,33.8 37.6,33.9 37.8,33.9 37.9,34 38,34.1 38.2,34.1 38.3,34.2 38.5,34.3 38.6,34.3 38.7,34.4 38.9,34.5 39,34.6 39.1,34.7 39.2,34.7 39.4,34.8 39.5,34.9 39.6,35 39.7,35.1 39.9,35.2 40,35.3 40.1,35.4 40.2,35.5 40.3,35.6 40.4,35.7 40.5,35.8 40.6,35.9 40.7,36.1 40.8,36.2 40.9,36.3 41,36.4 41.1,36.5 41.2,36.6 41.3,36.8 41.4,36.9 41.5,37 41.6,37.1 41.7,37.3 41.8,37.4 41.8,37.5 41.9,37.7 42,37.8 42.1,37.9 42.1,38.1 42.2,38.2 42.3,38.3 42.3,38.5 42.4,38.6 42.4,38.8 42.5,38.9 42.6,39.1 42.6,39.2 42.6,39.4 42.7,39.5 42.7,39.6 42.8,39.8 42.8,39.9 42.8,40.1 42.9,40.2 42.9,40.4 42.9,40.5 43,40.7 43,40.9 43,41 43,41.2 43,41.3 43,41.5 43,41.6 43.1,41.8 43.1,41.9 43.1,42.1 43.1,42.2 43,42.4 43,42.5 43,42.7 43,42.8 43,43 43,43.1 43,43.3 42.9,43.5 42.9,43.6 42.9,43.8 42.8,43.9 42.8,44.1 42.8,44.2 42.7,44.4 42.7,44.5 42.6,44.6 42.6,44.8 42.6,44.9 42.5,45.1 42.4,45.2 42.4,45.4 42.3,45.5 42.3,45.7 42.2,45.8 42.1,45.9 42.1,46.1 42,46.2 41.9,46.3 41.8,46.5 41.8,46.6 41.7,46.7 41.6,46.9 41.5,47 41.4,47.1 41.3,47.2 41.2,47.4 41.1,47.5 41,47.6 40.9,47.7 40.8,47.8 40.7,47.9 40.6,48.1 40.5,48.2 40.4,48.3 40.3,48.4 40.2,48.5 40.1,48.6 40,48.7 39.9,48.8 39.7,48.9 39.6,49 39.5,49.1 39.4,49.2 39.2,49.3 39.1,49.3 39,49.4 38.9,49.5 38.7,49.6 38.6,49.7 38.5,49.7 38.3,49.8 38.2,49.9 38,49.9 37.9,50 37.8,50.1 37.6,50.1 37.5,50.2 37.3,50.2 37.2,50.3 37.1,50.3 36.9,50.4 36.8,50.4 36.6,50.5 36.5,50.5 36.3,50.6 36.2,50.6 36,50.6 35.9,50.7 35.7,50.7 35.6,50.7 35.4,50.7 35.3,50.7 35.1,50.8 34.9,50.8 34.8,50.8 34.6,50.8 34.5,50.8 34.3,50.8 34.2,50.8 34,50.8 33.9,50.8 33.7,50.8 33.6,50.8 33.4,50.8 33.3,50.8 33.1,50.7 33,50.7 32.8,50.7 32.7,50.7 32.5,50.6 32.4,50.6 32.2,50.6 32.1,50.5 31.9,50.5 31.8,50.4 31.6,50.4 31.5,50.4 31.3,50.3 31.2,50.3 31,50.2 30.9,50.1 30.7,50.1 30.6,50 30.5,50 30.3,49.9 30.2,49.8 30.1,49.7 29.9,49.7 29.8,49.6 29.7,49.5 29.5,49.4 29.4,49.4 29.3,49.3 29.1,49.2 29,49.1 28.9,49 28.8,48.9 28.7,48.8 28.5,48.7 28.4,48.6 28.3,48.5 28.2,48.4 28.1,48.3 28,48.2 27.9,48.1 27.8,48 27.7,47.8 27.6,47.7 27.5,47.6 27.4,47.5 27.3,47.4 27.2,47.2 27.1,47.1 27,47" ) ); - QString res = elemToString( exportC.asGML2( doc, 1 ) ); + QString res = elemToString( exportC.asGml2( doc, 1 ) ); QGSCOMPAREGML( res, expectedSimpleGML2 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsMultiCurve().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsMultiCurve().asGml2( doc ) ), expectedGML2empty ); //as GML3 QString expectedSimpleGML3( QStringLiteral( "7 17 3 13 7 1127 37 43 43 27 47" ) ); - res = elemToString( exportC.asGML3( doc ) ); + res = elemToString( exportC.asGml3( doc ) ); QCOMPARE( res, expectedSimpleGML3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsMultiCurve().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsMultiCurve().asGml3( doc ) ), expectedGML3empty ); // as JSON QString expectedSimpleJson( "{\"type\": \"MultiLineString\", \"coordinates\": [[ [7, 17], [6.9, 17], [6.9, 17], [6.8, 17], [6.8, 17.1], [6.7, 17.1], [6.7, 17.1], [6.6, 17.1], [6.6, 17.1], [6.5, 17.1], [6.5, 17.1], [6.4, 17.1], [6.4, 17.1], [6.3, 17.1], [6.2, 17.2], [6.2, 17.2], [6.1, 17.2], [6.1, 17.2], [6, 17.2], [6, 17.2], [5.9, 17.2], [5.9, 17.2], [5.8, 17.2], [5.7, 17.2], [5.7, 17.1], [5.6, 17.1], [5.6, 17.1], [5.5, 17.1], [5.5, 17.1], [5.4, 17.1], [5.4, 17.1], [5.3, 17.1], [5.3, 17.1], [5.2, 17.1], [5.2, 17], [5.1, 17], [5, 17], [5, 17], [4.9, 17], [4.9, 17], [4.8, 16.9], [4.8, 16.9], [4.7, 16.9], [4.7, 16.9], [4.6, 16.9], [4.6, 16.8], [4.5, 16.8], [4.5, 16.8], [4.4, 16.8], [4.4, 16.7], [4.3, 16.7], [4.3, 16.7], [4.3, 16.6], [4.2, 16.6], [4.2, 16.6], [4.1, 16.5], [4.1, 16.5], [4, 16.5], [4, 16.4], [3.9, 16.4], [3.9, 16.4], [3.9, 16.3], [3.8, 16.3], [3.8, 16.3], [3.7, 16.2], [3.7, 16.2], [3.7, 16.1], [3.6, 16.1], [3.6, 16.1], [3.6, 16], [3.5, 16], [3.5, 15.9], [3.5, 15.9], [3.4, 15.8], [3.4, 15.8], [3.4, 15.7], [3.3, 15.7], [3.3, 15.7], [3.3, 15.6], [3.2, 15.6], [3.2, 15.5], [3.2, 15.5], [3.2, 15.4], [3.1, 15.4], [3.1, 15.3], [3.1, 15.3], [3.1, 15.2], [3.1, 15.2], [3, 15.1], [3, 15.1], [3, 15], [3, 15], [3, 14.9], [3, 14.8], [2.9, 14.8], [2.9, 14.7], [2.9, 14.7], [2.9, 14.6], [2.9, 14.6], [2.9, 14.5], [2.9, 14.5], [2.9, 14.4], [2.9, 14.4], [2.9, 14.3], [2.8, 14.2], [2.8, 14.2], [2.8, 14.1], [2.8, 14.1], [2.8, 14], [2.8, 14], [2.8, 13.9], [2.8, 13.9], [2.8, 13.8], [2.8, 13.8], [2.9, 13.7], [2.9, 13.6], [2.9, 13.6], [2.9, 13.5], [2.9, 13.5], [2.9, 13.4], [2.9, 13.4], [2.9, 13.3], [2.9, 13.3], [2.9, 13.2], [3, 13.2], [3, 13.1], [3, 13], [3, 13], [3, 12.9], [3, 12.9], [3.1, 12.8], [3.1, 12.8], [3.1, 12.7], [3.1, 12.7], [3.1, 12.6], [3.2, 12.6], [3.2, 12.5], [3.2, 12.5], [3.2, 12.4], [3.3, 12.4], [3.3, 12.3], [3.3, 12.3], [3.4, 12.3], [3.4, 12.2], [3.4, 12.2], [3.5, 12.1], [3.5, 12.1], [3.5, 12], [3.6, 12], [3.6, 11.9], [3.6, 11.9], [3.7, 11.9], [3.7, 11.8], [3.7, 11.8], [3.8, 11.7], [3.8, 11.7], [3.9, 11.7], [3.9, 11.6], [3.9, 11.6], [4, 11.6], [4, 11.5], [4.1, 11.5], [4.1, 11.5], [4.2, 11.4], [4.2, 11.4], [4.3, 11.4], [4.3, 11.3], [4.3, 11.3], [4.4, 11.3], [4.4, 11.2], [4.5, 11.2], [4.5, 11.2], [4.6, 11.2], [4.6, 11.1], [4.7, 11.1], [4.7, 11.1], [4.8, 11.1], [4.8, 11.1], [4.9, 11], [4.9, 11], [5, 11], [5, 11], [5.1, 11], [5.2, 11], [5.2, 10.9], [5.3, 10.9], [5.3, 10.9], [5.4, 10.9], [5.4, 10.9], [5.5, 10.9], [5.5, 10.9], [5.6, 10.9], [5.6, 10.9], [5.7, 10.9], [5.7, 10.8], [5.8, 10.8], [5.9, 10.8], [5.9, 10.8], [6, 10.8], [6, 10.8], [6.1, 10.8], [6.1, 10.8], [6.2, 10.8], [6.2, 10.8], [6.3, 10.9], [6.4, 10.9], [6.4, 10.9], [6.5, 10.9], [6.5, 10.9], [6.6, 10.9], [6.6, 10.9], [6.7, 10.9], [6.7, 10.9], [6.8, 10.9], [6.8, 11], [6.9, 11], [6.9, 11], [7, 11]], [ [27, 37], [27.1, 36.9], [27.2, 36.8], [27.3, 36.6], [27.4, 36.5], [27.5, 36.4], [27.6, 36.3], [27.7, 36.2], [27.8, 36], [27.9, 35.9], [28, 35.8], [28.1, 35.7], [28.2, 35.6], [28.3, 35.5], [28.4, 35.4], [28.5, 35.3], [28.7, 35.2], [28.8, 35.1], [28.9, 35], [29, 34.9], [29.1, 34.8], [29.3, 34.7], [29.4, 34.6], [29.5, 34.6], [29.7, 34.5], [29.8, 34.4], [29.9, 34.3], [30.1, 34.3], [30.2, 34.2], [30.3, 34.1], [30.5, 34], [30.6, 34], [30.7, 33.9], [30.9, 33.9], [31, 33.8], [31.2, 33.7], [31.3, 33.7], [31.5, 33.6], [31.6, 33.6], [31.8, 33.6], [31.9, 33.5], [32.1, 33.5], [32.2, 33.4], [32.4, 33.4], [32.5, 33.4], [32.7, 33.3], [32.8, 33.3], [33, 33.3], [33.1, 33.3], [33.3, 33.2], [33.4, 33.2], [33.6, 33.2], [33.7, 33.2], [33.9, 33.2], [34, 33.2], [34.2, 33.2], [34.3, 33.2], [34.5, 33.2], [34.6, 33.2], [34.8, 33.2], [34.9, 33.2], [35.1, 33.2], [35.3, 33.3], [35.4, 33.3], [35.6, 33.3], [35.7, 33.3], [35.9, 33.3], [36, 33.4], [36.2, 33.4], [36.3, 33.4], [36.5, 33.5], [36.6, 33.5], [36.8, 33.6], [36.9, 33.6], [37.1, 33.7], [37.2, 33.7], [37.3, 33.8], [37.5, 33.8], [37.6, 33.9], [37.8, 33.9], [37.9, 34], [38, 34.1], [38.2, 34.1], [38.3, 34.2], [38.5, 34.3], [38.6, 34.3], [38.7, 34.4], [38.9, 34.5], [39, 34.6], [39.1, 34.7], [39.2, 34.7], [39.4, 34.8], [39.5, 34.9], [39.6, 35], [39.7, 35.1], [39.9, 35.2], [40, 35.3], [40.1, 35.4], [40.2, 35.5], [40.3, 35.6], [40.4, 35.7], [40.5, 35.8], [40.6, 35.9], [40.7, 36.1], [40.8, 36.2], [40.9, 36.3], [41, 36.4], [41.1, 36.5], [41.2, 36.6], [41.3, 36.8], [41.4, 36.9], [41.5, 37], [41.6, 37.1], [41.7, 37.3], [41.8, 37.4], [41.8, 37.5], [41.9, 37.7], [42, 37.8], [42.1, 37.9], [42.1, 38.1], [42.2, 38.2], [42.3, 38.3], [42.3, 38.5], [42.4, 38.6], [42.4, 38.8], [42.5, 38.9], [42.6, 39.1], [42.6, 39.2], [42.6, 39.4], [42.7, 39.5], [42.7, 39.6], [42.8, 39.8], [42.8, 39.9], [42.8, 40.1], [42.9, 40.2], [42.9, 40.4], [42.9, 40.5], [43, 40.7], [43, 40.9], [43, 41], [43, 41.2], [43, 41.3], [43, 41.5], [43, 41.6], [43.1, 41.8], [43.1, 41.9], [43.1, 42.1], [43.1, 42.2], [43, 42.4], [43, 42.5], [43, 42.7], [43, 42.8], [43, 43], [43, 43.1], [43, 43.3], [42.9, 43.5], [42.9, 43.6], [42.9, 43.8], [42.8, 43.9], [42.8, 44.1], [42.8, 44.2], [42.7, 44.4], [42.7, 44.5], [42.6, 44.6], [42.6, 44.8], [42.6, 44.9], [42.5, 45.1], [42.4, 45.2], [42.4, 45.4], [42.3, 45.5], [42.3, 45.7], [42.2, 45.8], [42.1, 45.9], [42.1, 46.1], [42, 46.2], [41.9, 46.3], [41.8, 46.5], [41.8, 46.6], [41.7, 46.7], [41.6, 46.9], [41.5, 47], [41.4, 47.1], [41.3, 47.2], [41.2, 47.4], [41.1, 47.5], [41, 47.6], [40.9, 47.7], [40.8, 47.8], [40.7, 47.9], [40.6, 48.1], [40.5, 48.2], [40.4, 48.3], [40.3, 48.4], [40.2, 48.5], [40.1, 48.6], [40, 48.7], [39.9, 48.8], [39.7, 48.9], [39.6, 49], [39.5, 49.1], [39.4, 49.2], [39.2, 49.3], [39.1, 49.3], [39, 49.4], [38.9, 49.5], [38.7, 49.6], [38.6, 49.7], [38.5, 49.7], [38.3, 49.8], [38.2, 49.9], [38, 49.9], [37.9, 50], [37.8, 50.1], [37.6, 50.1], [37.5, 50.2], [37.3, 50.2], [37.2, 50.3], [37.1, 50.3], [36.9, 50.4], [36.8, 50.4], [36.6, 50.5], [36.5, 50.5], [36.3, 50.6], [36.2, 50.6], [36, 50.6], [35.9, 50.7], [35.7, 50.7], [35.6, 50.7], [35.4, 50.7], [35.3, 50.7], [35.1, 50.8], [34.9, 50.8], [34.8, 50.8], [34.6, 50.8], [34.5, 50.8], [34.3, 50.8], [34.2, 50.8], [34, 50.8], [33.9, 50.8], [33.7, 50.8], [33.6, 50.8], [33.4, 50.8], [33.3, 50.8], [33.1, 50.7], [33, 50.7], [32.8, 50.7], [32.7, 50.7], [32.5, 50.6], [32.4, 50.6], [32.2, 50.6], [32.1, 50.5], [31.9, 50.5], [31.8, 50.4], [31.6, 50.4], [31.5, 50.4], [31.3, 50.3], [31.2, 50.3], [31, 50.2], [30.9, 50.1], [30.7, 50.1], [30.6, 50], [30.5, 50], [30.3, 49.9], [30.2, 49.8], [30.1, 49.7], [29.9, 49.7], [29.8, 49.6], [29.7, 49.5], [29.5, 49.4], [29.4, 49.4], [29.3, 49.3], [29.1, 49.2], [29, 49.1], [28.9, 49], [28.8, 48.9], [28.7, 48.8], [28.5, 48.7], [28.4, 48.6], [28.3, 48.5], [28.2, 48.4], [28.1, 48.3], [28, 48.2], [27.9, 48.1], [27.8, 48], [27.7, 47.8], [27.6, 47.7], [27.5, 47.6], [27.4, 47.5], [27.3, 47.4], [27.2, 47.2], [27.1, 47.1], [27, 47]]] }" ); - res = exportC.asJSON( 1 ); + res = exportC.asJson( 1 ); QCOMPARE( res, expectedSimpleJson ); QgsMultiCurve exportFloat; @@ -11997,17 +11997,17 @@ void TestQgsGeometry::multiCurve() exportFloat.addGeometry( part.clone() ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"MultiLineString\", \"coordinates\": [[ [2.333, 5.667], [2.316, 5.677], [2.298, 5.687], [2.28, 5.697], [2.262, 5.707], [2.244, 5.716], [2.226, 5.725], [2.207, 5.734], [2.188, 5.742], [2.17, 5.75], [2.151, 5.757], [2.131, 5.765], [2.112, 5.772], [2.093, 5.778], [2.074, 5.785], [2.054, 5.79], [2.034, 5.796], [2.015, 5.801], [1.995, 5.806], [1.975, 5.811], [1.955, 5.815], [1.935, 5.819], [1.915, 5.822], [1.894, 5.826], [1.874, 5.828], [1.854, 5.831], [1.834, 5.833], [1.813, 5.835], [1.793, 5.836], [1.773, 5.837], [1.752, 5.838], [1.732, 5.838], [1.711, 5.838], [1.691, 5.838], [1.67, 5.837], [1.65, 5.836], [1.63, 5.834], [1.609, 5.833], [1.589, 5.83], [1.569, 5.828], [1.548, 5.825], [1.528, 5.822], [1.508, 5.818], [1.488, 5.814], [1.468, 5.81], [1.448, 5.805], [1.428, 5.801], [1.409, 5.795], [1.389, 5.79], [1.37, 5.784], [1.35, 5.777], [1.331, 5.771], [1.312, 5.764], [1.293, 5.756], [1.274, 5.749], [1.255, 5.741], [1.236, 5.732], [1.218, 5.724], [1.199, 5.715], [1.181, 5.705], [1.163, 5.696], [1.145, 5.686], [1.128, 5.676], [1.11, 5.665], [1.093, 5.654], [1.076, 5.643], [1.059, 5.632], [1.042, 5.62], [1.025, 5.608], [1.009, 5.596], [0.993, 5.583], [0.977, 5.57], [0.962, 5.557], [0.946, 5.543], [0.931, 5.53], [0.916, 5.516], [0.901, 5.502], [0.887, 5.487], [0.873, 5.473], [0.859, 5.458], [0.845, 5.442], [0.832, 5.427], [0.819, 5.411], [0.806, 5.395], [0.793, 5.379], [0.781, 5.363], [0.769, 5.346], [0.757, 5.33], [0.746, 5.313], [0.735, 5.296], [0.724, 5.278], [0.713, 5.261], [0.703, 5.243], [0.693, 5.225], [0.684, 5.207], [0.674, 5.189], [0.666, 5.171], [0.657, 5.152], [0.649, 5.133], [0.641, 5.115], [0.633, 5.096], [0.626, 5.077], [0.619, 5.057], [0.612, 5.038], [0.606, 5.019], [0.6, 4.999], [0.594, 4.979], [0.589, 4.96], [0.584, 4.94], [0.579, 4.92], [0.575, 4.9], [0.571, 4.88], [0.568, 4.86], [0.564, 4.84], [0.562, 4.819], [0.559, 4.799], [0.557, 4.779], [0.555, 4.759], [0.554, 4.738], [0.553, 4.718], [0.552, 4.697], [0.552, 4.677], [0.552, 4.656], [0.552, 4.636], [0.553, 4.616], [0.554, 4.595], [0.555, 4.575], [0.557, 4.554], [0.559, 4.534], [0.562, 4.514], [0.564, 4.494], [0.568, 4.473], [0.571, 4.453], [0.575, 4.433], [0.579, 4.413], [0.584, 4.393], [0.589, 4.374], [0.594, 4.354], [0.6, 4.334], [0.606, 4.315], [0.612, 4.295], [0.619, 4.276], [0.626, 4.257], [0.633, 4.238], [0.641, 4.219], [0.649, 4.2], [0.657, 4.181], [0.666, 4.163], [0.674, 4.144], [0.684, 4.126], [0.693, 4.108], [0.703, 4.09], [0.713, 4.073], [0.724, 4.055], [0.735, 4.038], [0.746, 4.021], [0.757, 4.004], [0.769, 3.987], [0.781, 3.97], [0.793, 3.954], [0.806, 3.938], [0.819, 3.922], [0.832, 3.906], [0.845, 3.891], [0.859, 3.876], [0.873, 3.861], [0.887, 3.846], [0.901, 3.832], [0.916, 3.817], [0.931, 3.804], [0.946, 3.79], [0.962, 3.776], [0.977, 3.763], [0.993, 3.75], [1.009, 3.738], [1.025, 3.726], [1.042, 3.713], [1.059, 3.702], [1.076, 3.69], [1.093, 3.679], [1.11, 3.668], [1.128, 3.658], [1.145, 3.648], [1.163, 3.638], [1.181, 3.628], [1.199, 3.619], [1.218, 3.61], [1.236, 3.601], [1.255, 3.593], [1.274, 3.585], [1.293, 3.577], [1.312, 3.57], [1.331, 3.563], [1.35, 3.556], [1.37, 3.55], [1.389, 3.544], [1.409, 3.538], [1.428, 3.533], [1.448, 3.528], [1.468, 3.523], [1.488, 3.519], [1.508, 3.515], [1.528, 3.511], [1.548, 3.508], [1.569, 3.505], [1.589, 3.503], [1.609, 3.501], [1.63, 3.499], [1.65, 3.497], [1.67, 3.496], [1.691, 3.496], [1.711, 3.495], [1.732, 3.495], [1.752, 3.496], [1.773, 3.496], [1.793, 3.497], [1.813, 3.499], [1.834, 3.5], [1.854, 3.503], [1.874, 3.505], [1.894, 3.508], [1.915, 3.511], [1.935, 3.514], [1.955, 3.518], [1.975, 3.523], [1.995, 3.527], [2.015, 3.532], [2.034, 3.537], [2.054, 3.543], [2.074, 3.549], [2.093, 3.555], [2.112, 3.562], [2.131, 3.569], [2.151, 3.576], [2.17, 3.584], [2.188, 3.592], [2.207, 3.6], [2.226, 3.608], [2.244, 3.617], [2.262, 3.627], [2.28, 3.636], [2.298, 3.646], [2.316, 3.656], [2.333, 3.667]], [ [9, 4.111], [8.966, 4.178], [8.932, 4.244], [8.896, 4.309], [8.859, 4.374], [8.821, 4.438], [8.782, 4.502], [8.742, 4.565], [8.7, 4.627], [8.658, 4.688], [8.614, 4.749], [8.57, 4.809], [8.524, 4.868], [8.477, 4.926], [8.43, 4.983], [8.381, 5.04], [8.331, 5.096], [8.281, 5.151], [8.229, 5.205], [8.177, 5.258], [8.124, 5.31], [8.069, 5.361], [8.014, 5.411], [7.958, 5.461], [7.901, 5.509], [7.844, 5.556], [7.785, 5.603], [7.726, 5.648], [7.666, 5.692], [7.605, 5.735], [7.543, 5.777], [7.481, 5.818], [7.418, 5.858], [7.354, 5.897], [7.29, 5.935], [7.225, 5.971], [7.159, 6.007], [7.093, 6.041], [7.026, 6.074], [6.958, 6.106], [6.89, 6.137], [6.822, 6.167], [6.753, 6.195], [6.683, 6.222], [6.613, 6.248], [6.543, 6.273], [6.472, 6.296], [6.401, 6.319], [6.329, 6.34], [6.257, 6.36], [6.185, 6.378], [6.112, 6.395], [6.04, 6.411], [5.966, 6.426], [5.893, 6.44], [5.819, 6.452], [5.746, 6.463], [5.672, 6.472], [5.597, 6.48], [5.523, 6.487], [5.449, 6.493], [5.374, 6.498], [5.3, 6.501], [5.225, 6.503], [5.15, 6.503], [5.076, 6.502], [5.001, 6.5], [4.927, 6.497], [4.852, 6.492], [4.778, 6.486], [4.704, 6.479], [4.629, 6.47], [4.555, 6.46], [4.482, 6.449], [4.408, 6.437], [4.335, 6.423], [4.262, 6.408], [4.189, 6.392], [4.116, 6.374], [4.044, 6.355], [3.972, 6.335], [3.901, 6.314], [3.83, 6.292], [3.759, 6.268], [3.688, 6.243], [3.619, 6.217], [3.549, 6.189], [3.48, 6.16], [3.412, 6.131], [3.344, 6.1], [3.277, 6.067], [3.21, 6.034], [3.144, 5.999], [3.078, 5.964], [3.013, 5.927], [2.949, 5.889], [2.886, 5.85], [2.823, 5.81], [2.761, 5.768], [2.699, 5.726], [2.638, 5.683], [2.578, 5.638], [2.519, 5.593], [2.461, 5.546], [2.403, 5.499], [2.347, 5.45], [2.291, 5.401], [2.236, 5.35], [2.182, 5.299], [2.129, 5.246], [2.076, 5.193], [2.025, 5.139], [1.975, 5.084], [1.925, 5.028], [1.877, 4.971], [1.829, 4.914], [1.783, 4.855], [1.738, 4.796], [1.693, 4.736], [1.65, 4.675], [1.608, 4.614], [1.567, 4.551], [1.527, 4.488], [1.488, 4.425], [1.45, 4.36], [1.413, 4.295], [1.378, 4.23], [1.343, 4.164], [1.31, 4.097], [1.278, 4.029], [1.247, 3.961], [1.217, 3.893], [1.189, 3.824], [1.161, 3.755], [1.135, 3.685], [1.11, 3.614], [1.087, 3.544], [1.064, 3.472], [1.043, 3.401], [1.023, 3.329], [1.004, 3.257], [0.987, 3.184], [0.971, 3.111], [0.956, 3.038], [0.942, 2.965], [0.93, 2.891], [0.919, 2.817], [0.909, 2.743], [0.901, 2.669], [0.894, 2.595], [0.888, 2.52], [0.883, 2.446], [0.88, 2.371], [0.878, 2.297], [0.878, 2.222], [0.878, 2.148], [0.88, 2.073], [0.883, 1.998], [0.888, 1.924], [0.894, 1.85], [0.901, 1.775], [0.909, 1.701], [0.919, 1.627], [0.93, 1.553], [0.942, 1.48], [0.956, 1.406], [0.971, 1.333], [0.987, 1.26], [1.004, 1.188], [1.023, 1.116], [1.043, 1.044], [1.064, 0.972], [1.087, 0.901], [1.11, 0.83], [1.135, 0.76], [1.161, 0.69], [1.189, 0.62], [1.217, 0.551], [1.247, 0.483], [1.278, 0.415], [1.31, 0.348], [1.343, 0.281], [1.378, 0.215], [1.413, 0.149], [1.45, 0.084], [1.488, 0.02], [1.527, -0.044], [1.567, -0.107], [1.608, -0.169], [1.65, -0.231], [1.693, -0.291], [1.738, -0.351], [1.783, -0.411], [1.829, -0.469], [1.877, -0.527], [1.925, -0.584], [1.975, -0.639], [2.025, -0.694], [2.076, -0.749], [2.129, -0.802], [2.182, -0.854], [2.236, -0.906], [2.291, -0.956], [2.347, -1.006], [2.403, -1.054], [2.461, -1.102], [2.519, -1.148], [2.578, -1.194], [2.638, -1.238], [2.699, -1.282], [2.761, -1.324], [2.823, -1.365], [2.886, -1.405], [2.949, -1.444], [3.013, -1.482], [3.078, -1.519], [3.144, -1.555], [3.21, -1.589], [3.277, -1.623], [3.344, -1.655], [3.412, -1.686], [3.48, -1.716], [3.549, -1.745], [3.619, -1.772], [3.688, -1.798], [3.759, -1.823], [3.83, -1.847], [3.901, -1.87], [3.972, -1.891], [4.044, -1.911], [4.116, -1.93], [4.189, -1.947], [4.262, -1.964], [4.335, -1.979], [4.408, -1.992], [4.482, -2.005], [4.555, -2.016], [4.629, -2.026], [4.704, -2.034], [4.778, -2.042], [4.852, -2.048], [4.927, -2.052], [5.001, -2.056], [5.076, -2.058], [5.15, -2.059], [5.225, -2.058], [5.3, -2.056], [5.374, -2.053], [5.449, -2.049], [5.523, -2.043], [5.597, -2.036], [5.672, -2.028], [5.746, -2.018], [5.819, -2.007], [5.893, -1.995], [5.966, -1.982], [6.04, -1.967], [6.112, -1.951], [6.185, -1.934], [6.257, -1.915], [6.329, -1.895], [6.401, -1.874], [6.472, -1.852], [6.543, -1.829], [6.613, -1.804], [6.683, -1.778], [6.753, -1.751], [6.822, -1.722], [6.89, -1.693], [6.958, -1.662], [7.026, -1.63], [7.093, -1.597], [7.159, -1.562], [7.225, -1.527], [7.29, -1.49], [7.354, -1.453], [7.418, -1.414], [7.481, -1.374], [7.543, -1.333], [7.605, -1.291], [7.666, -1.248], [7.726, -1.203], [7.785, -1.158], [7.844, -1.112], [7.901, -1.065], [7.958, -1.016], [8.014, -0.967], [8.069, -0.917], [8.124, -0.865], [8.177, -0.813], [8.229, -0.76], [8.281, -0.706], [8.331, -0.651], [8.381, -0.596], [8.43, -0.539], [8.477, -0.482], [8.524, -0.423], [8.57, -0.364], [8.614, -0.304], [8.658, -0.244], [8.7, -0.182], [8.742, -0.12], [8.782, -0.057], [8.821, 0.006], [8.859, 0.07], [8.896, 0.135], [8.932, 0.201], [8.966, 0.267], [9, 0.333]]] }" ) ); - res = exportFloat.asJSON( 3 ); + res = exportFloat.asJson( 3 ); QCOMPARE( res, expectedJsonPrec3 ); // as GML2 QString expectedGML2prec3( QStringLiteral( "2.333,5.667 2.316,5.677 2.298,5.687 2.28,5.697 2.262,5.707 2.244,5.716 2.226,5.725 2.207,5.734 2.188,5.742 2.17,5.75 2.151,5.757 2.131,5.765 2.112,5.772 2.093,5.778 2.074,5.785 2.054,5.79 2.034,5.796 2.015,5.801 1.995,5.806 1.975,5.811 1.955,5.815 1.935,5.819 1.915,5.822 1.894,5.826 1.874,5.828 1.854,5.831 1.834,5.833 1.813,5.835 1.793,5.836 1.773,5.837 1.752,5.838 1.732,5.838 1.711,5.838 1.691,5.838 1.67,5.837 1.65,5.836 1.63,5.834 1.609,5.833 1.589,5.83 1.569,5.828 1.548,5.825 1.528,5.822 1.508,5.818 1.488,5.814 1.468,5.81 1.448,5.805 1.428,5.801 1.409,5.795 1.389,5.79 1.37,5.784 1.35,5.777 1.331,5.771 1.312,5.764 1.293,5.756 1.274,5.749 1.255,5.741 1.236,5.732 1.218,5.724 1.199,5.715 1.181,5.705 1.163,5.696 1.145,5.686 1.128,5.676 1.11,5.665 1.093,5.654 1.076,5.643 1.059,5.632 1.042,5.62 1.025,5.608 1.009,5.596 0.993,5.583 0.977,5.57 0.962,5.557 0.946,5.543 0.931,5.53 0.916,5.516 0.901,5.502 0.887,5.487 0.873,5.473 0.859,5.458 0.845,5.442 0.832,5.427 0.819,5.411 0.806,5.395 0.793,5.379 0.781,5.363 0.769,5.346 0.757,5.33 0.746,5.313 0.735,5.296 0.724,5.278 0.713,5.261 0.703,5.243 0.693,5.225 0.684,5.207 0.674,5.189 0.666,5.171 0.657,5.152 0.649,5.133 0.641,5.115 0.633,5.096 0.626,5.077 0.619,5.057 0.612,5.038 0.606,5.019 0.6,4.999 0.594,4.979 0.589,4.96 0.584,4.94 0.579,4.92 0.575,4.9 0.571,4.88 0.568,4.86 0.564,4.84 0.562,4.819 0.559,4.799 0.557,4.779 0.555,4.759 0.554,4.738 0.553,4.718 0.552,4.697 0.552,4.677 0.552,4.656 0.552,4.636 0.553,4.616 0.554,4.595 0.555,4.575 0.557,4.554 0.559,4.534 0.562,4.514 0.564,4.494 0.568,4.473 0.571,4.453 0.575,4.433 0.579,4.413 0.584,4.393 0.589,4.374 0.594,4.354 0.6,4.334 0.606,4.315 0.612,4.295 0.619,4.276 0.626,4.257 0.633,4.238 0.641,4.219 0.649,4.2 0.657,4.181 0.666,4.163 0.674,4.144 0.684,4.126 0.693,4.108 0.703,4.09 0.713,4.073 0.724,4.055 0.735,4.038 0.746,4.021 0.757,4.004 0.769,3.987 0.781,3.97 0.793,3.954 0.806,3.938 0.819,3.922 0.832,3.906 0.845,3.891 0.859,3.876 0.873,3.861 0.887,3.846 0.901,3.832 0.916,3.817 0.931,3.804 0.946,3.79 0.962,3.776 0.977,3.763 0.993,3.75 1.009,3.738 1.025,3.726 1.042,3.713 1.059,3.702 1.076,3.69 1.093,3.679 1.11,3.668 1.128,3.658 1.145,3.648 1.163,3.638 1.181,3.628 1.199,3.619 1.218,3.61 1.236,3.601 1.255,3.593 1.274,3.585 1.293,3.577 1.312,3.57 1.331,3.563 1.35,3.556 1.37,3.55 1.389,3.544 1.409,3.538 1.428,3.533 1.448,3.528 1.468,3.523 1.488,3.519 1.508,3.515 1.528,3.511 1.548,3.508 1.569,3.505 1.589,3.503 1.609,3.501 1.63,3.499 1.65,3.497 1.67,3.496 1.691,3.496 1.711,3.495 1.732,3.495 1.752,3.496 1.773,3.496 1.793,3.497 1.813,3.499 1.834,3.5 1.854,3.503 1.874,3.505 1.894,3.508 1.915,3.511 1.935,3.514 1.955,3.518 1.975,3.523 1.995,3.527 2.015,3.532 2.034,3.537 2.054,3.543 2.074,3.549 2.093,3.555 2.112,3.562 2.131,3.569 2.151,3.576 2.17,3.584 2.188,3.592 2.207,3.6 2.226,3.608 2.244,3.617 2.262,3.627 2.28,3.636 2.298,3.646 2.316,3.656 2.333,3.6679,4.111 8.966,4.178 8.932,4.244 8.896,4.309 8.859,4.374 8.821,4.438 8.782,4.502 8.742,4.565 8.7,4.627 8.658,4.688 8.614,4.749 8.57,4.809 8.524,4.868 8.477,4.926 8.43,4.983 8.381,5.04 8.331,5.096 8.281,5.151 8.229,5.205 8.177,5.258 8.124,5.31 8.069,5.361 8.014,5.411 7.958,5.461 7.901,5.509 7.844,5.556 7.785,5.603 7.726,5.648 7.666,5.692 7.605,5.735 7.543,5.777 7.481,5.818 7.418,5.858 7.354,5.897 7.29,5.935 7.225,5.971 7.159,6.007 7.093,6.041 7.026,6.074 6.958,6.106 6.89,6.137 6.822,6.167 6.753,6.195 6.683,6.222 6.613,6.248 6.543,6.273 6.472,6.296 6.401,6.319 6.329,6.34 6.257,6.36 6.185,6.378 6.112,6.395 6.04,6.411 5.966,6.426 5.893,6.44 5.819,6.452 5.746,6.463 5.672,6.472 5.597,6.48 5.523,6.487 5.449,6.493 5.374,6.498 5.3,6.501 5.225,6.503 5.15,6.503 5.076,6.502 5.001,6.5 4.927,6.497 4.852,6.492 4.778,6.486 4.704,6.479 4.629,6.47 4.555,6.46 4.482,6.449 4.408,6.437 4.335,6.423 4.262,6.408 4.189,6.392 4.116,6.374 4.044,6.355 3.972,6.335 3.901,6.314 3.83,6.292 3.759,6.268 3.688,6.243 3.619,6.217 3.549,6.189 3.48,6.16 3.412,6.131 3.344,6.1 3.277,6.067 3.21,6.034 3.144,5.999 3.078,5.964 3.013,5.927 2.949,5.889 2.886,5.85 2.823,5.81 2.761,5.768 2.699,5.726 2.638,5.683 2.578,5.638 2.519,5.593 2.461,5.546 2.403,5.499 2.347,5.45 2.291,5.401 2.236,5.35 2.182,5.299 2.129,5.246 2.076,5.193 2.025,5.139 1.975,5.084 1.925,5.028 1.877,4.971 1.829,4.914 1.783,4.855 1.738,4.796 1.693,4.736 1.65,4.675 1.608,4.614 1.567,4.551 1.527,4.488 1.488,4.425 1.45,4.36 1.413,4.295 1.378,4.23 1.343,4.164 1.31,4.097 1.278,4.029 1.247,3.961 1.217,3.893 1.189,3.824 1.161,3.755 1.135,3.685 1.11,3.614 1.087,3.544 1.064,3.472 1.043,3.401 1.023,3.329 1.004,3.257 0.987,3.184 0.971,3.111 0.956,3.038 0.942,2.965 0.93,2.891 0.919,2.817 0.909,2.743 0.901,2.669 0.894,2.595 0.888,2.52 0.883,2.446 0.88,2.371 0.878,2.297 0.878,2.222 0.878,2.148 0.88,2.073 0.883,1.998 0.888,1.924 0.894,1.85 0.901,1.775 0.909,1.701 0.919,1.627 0.93,1.553 0.942,1.48 0.956,1.406 0.971,1.333 0.987,1.26 1.004,1.188 1.023,1.116 1.043,1.044 1.064,0.972 1.087,0.901 1.11,0.83 1.135,0.76 1.161,0.69 1.189,0.62 1.217,0.551 1.247,0.483 1.278,0.415 1.31,0.348 1.343,0.281 1.378,0.215 1.413,0.149 1.45,0.084 1.488,0.02 1.527,-0.044 1.567,-0.107 1.608,-0.169 1.65,-0.231 1.693,-0.291 1.738,-0.351 1.783,-0.411 1.829,-0.469 1.877,-0.527 1.925,-0.584 1.975,-0.639 2.025,-0.694 2.076,-0.749 2.129,-0.802 2.182,-0.854 2.236,-0.906 2.291,-0.956 2.347,-1.006 2.403,-1.054 2.461,-1.102 2.519,-1.148 2.578,-1.194 2.638,-1.238 2.699,-1.282 2.761,-1.324 2.823,-1.365 2.886,-1.405 2.949,-1.444 3.013,-1.482 3.078,-1.519 3.144,-1.555 3.21,-1.589 3.277,-1.623 3.344,-1.655 3.412,-1.686 3.48,-1.716 3.549,-1.745 3.619,-1.772 3.688,-1.798 3.759,-1.823 3.83,-1.847 3.901,-1.87 3.972,-1.891 4.044,-1.911 4.116,-1.93 4.189,-1.947 4.262,-1.964 4.335,-1.979 4.408,-1.992 4.482,-2.005 4.555,-2.016 4.629,-2.026 4.704,-2.034 4.778,-2.042 4.852,-2.048 4.927,-2.052 5.001,-2.056 5.076,-2.058 5.15,-2.059 5.225,-2.058 5.3,-2.056 5.374,-2.053 5.449,-2.049 5.523,-2.043 5.597,-2.036 5.672,-2.028 5.746,-2.018 5.819,-2.007 5.893,-1.995 5.966,-1.982 6.04,-1.967 6.112,-1.951 6.185,-1.934 6.257,-1.915 6.329,-1.895 6.401,-1.874 6.472,-1.852 6.543,-1.829 6.613,-1.804 6.683,-1.778 6.753,-1.751 6.822,-1.722 6.89,-1.693 6.958,-1.662 7.026,-1.63 7.093,-1.597 7.159,-1.562 7.225,-1.527 7.29,-1.49 7.354,-1.453 7.418,-1.414 7.481,-1.374 7.543,-1.333 7.605,-1.291 7.666,-1.248 7.726,-1.203 7.785,-1.158 7.844,-1.112 7.901,-1.065 7.958,-1.016 8.014,-0.967 8.069,-0.917 8.124,-0.865 8.177,-0.813 8.229,-0.76 8.281,-0.706 8.331,-0.651 8.381,-0.596 8.43,-0.539 8.477,-0.482 8.524,-0.423 8.57,-0.364 8.614,-0.304 8.658,-0.244 8.7,-0.182 8.742,-0.12 8.782,-0.057 8.821,0.006 8.859,0.07 8.896,0.135 8.932,0.201 8.966,0.267 9,0.333" ) ); - res = elemToString( exportFloat.asGML2( doc, 3 ) ); + res = elemToString( exportFloat.asGml2( doc, 3 ) ); QGSCOMPAREGML( res, expectedGML2prec3 ); //as GML3 QString expectedGML3prec3( QStringLiteral( "2.333 5.667 0.6 4.333 2.333 3.6679 4.111 1.049 1.024 9 0.333" ) ); - res = elemToString( exportFloat.asGML3( doc, 3 ) ); + res = elemToString( exportFloat.asGml3( doc, 3 ) ); QCOMPARE( res, expectedGML3prec3 ); // insert geometry @@ -12622,21 +12622,21 @@ void TestQgsGeometry::multiSurface() // as GML2 QString expectedSimpleGML2( QStringLiteral( "7,17 7,1727,37 27,37" ) ); - QString res = elemToString( exportC.asGML2( doc, 1 ) ); + QString res = elemToString( exportC.asGml2( doc, 1 ) ); QGSCOMPAREGML( res, expectedSimpleGML2 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsMultiSurface().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsMultiSurface().asGml2( doc ) ), expectedGML2empty ); //as GML3 QString expectedSimpleGML3( QStringLiteral( "7 17 3 13 7 1727 37 43 43 27 37" ) ); - res = elemToString( exportC.asGML3( doc ) ); + res = elemToString( exportC.asGml3( doc ) ); QCOMPARE( res, expectedSimpleGML3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsMultiSurface().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsMultiSurface().asGml3( doc ) ), expectedGML3empty ); // as JSON QString expectedSimpleJson( "{\"type\": \"MultiPolygon\", \"coordinates\": [[[ [7, 17], [7, 17]]], [[ [27, 37], [27, 37]]]] }" ); - res = exportC.asJSON( 1 ); + res = exportC.asJson( 1 ); QCOMPARE( res, expectedSimpleJson ); ring.setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::Point, 17, 27 ) << QgsPoint( QgsWkbTypes::Point, 18, 28 ) << QgsPoint( QgsWkbTypes::Point, 17, 27 ) ) ; @@ -12644,7 +12644,7 @@ void TestQgsGeometry::multiSurface() exportC.addGeometry( part.clone() ); QString expectedJsonWithRings( "{\"type\": \"MultiPolygon\", \"coordinates\": [[[ [7, 17], [7, 17]]], [[ [27, 37], [27, 37]]], [[ [27, 37], [27, 37]], [ [17, 27], [17, 27]]]] }" ); - res = exportC.asJSON( 1 ); + res = exportC.asJson( 1 ); QCOMPARE( res, expectedJsonWithRings ); QgsMultiSurface exportFloat; @@ -12658,17 +12658,17 @@ void TestQgsGeometry::multiSurface() exportFloat.addGeometry( part.clone() ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"MultiPolygon\", \"coordinates\": [[[ [2.333, 5.667], [2.333, 5.667]]], [[ [9, 4.111], [9, 4.111]]]] }" ) ); - res = exportFloat.asJSON( 3 ); + res = exportFloat.asJson( 3 ); QCOMPARE( res, expectedJsonPrec3 ); // as GML2 QString expectedGML2prec3( QStringLiteral( "2.333,5.667 2.333,5.6679,4.111 9,4.111" ) ); - res = elemToString( exportFloat.asGML2( doc, 3 ) ); + res = elemToString( exportFloat.asGml2( doc, 3 ) ); QGSCOMPAREGML( res, expectedGML2prec3 ); //as GML3 QString expectedGML3prec3( QStringLiteral( "2.333 5.667 0.6 4.333 2.333 5.6679 4.111 1.049 1.024 9 4.111" ) ); - res = elemToString( exportFloat.asGML3( doc, 3 ) ); + res = elemToString( exportFloat.asGml3( doc, 3 ) ); QCOMPARE( res, expectedGML3prec3 ); // insert geometry @@ -13253,21 +13253,21 @@ void TestQgsGeometry::multiPolygon() // as GML2 QString expectedSimpleGML2( QStringLiteral( "7,17 3,13 7,21 7,1727,37 43,43 41,39 27,37" ) ); - QString res = elemToString( exportC.asGML2( doc, 1 ) ); + QString res = elemToString( exportC.asGml2( doc, 1 ) ); QGSCOMPAREGML( res, expectedSimpleGML2 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsMultiPolygon().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsMultiPolygon().asGml2( doc ) ), expectedGML2empty ); //as GML3 QString expectedSimpleGML3( QStringLiteral( "7 17 3 13 7 21 7 1727 37 43 43 41 39 27 37" ) ); - res = elemToString( exportC.asGML3( doc ) ); + res = elemToString( exportC.asGml3( doc ) ); QCOMPARE( res, expectedSimpleGML3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsMultiPolygon().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsMultiPolygon().asGml3( doc ) ), expectedGML3empty ); // as JSON QString expectedSimpleJson( "{\"type\": \"MultiPolygon\", \"coordinates\": [[[ [7, 17], [3, 13], [7, 21], [7, 17]]], [[ [27, 37], [43, 43], [41, 39], [27, 37]]]] }" ); - res = exportC.asJSON( 1 ); + res = exportC.asJson( 1 ); QCOMPARE( res, expectedSimpleJson ); ring.setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::Point, 17, 27 ) << QgsPoint( QgsWkbTypes::Point, 18, 28 ) << QgsPoint( QgsWkbTypes::Point, 19, 37 ) << QgsPoint( QgsWkbTypes::Point, 17, 27 ) ) ; @@ -13275,7 +13275,7 @@ void TestQgsGeometry::multiPolygon() exportC.addGeometry( part.clone() ); QString expectedJsonWithRings( "{\"type\": \"MultiPolygon\", \"coordinates\": [[[ [7, 17], [3, 13], [7, 21], [7, 17]]], [[ [27, 37], [43, 43], [41, 39], [27, 37]]], [[ [27, 37], [43, 43], [41, 39], [27, 37]], [ [17, 27], [18, 28], [19, 37], [17, 27]]]] }" ); - res = exportC.asJSON( 1 ); + res = exportC.asJson( 1 ); QCOMPARE( res, expectedJsonWithRings ); QgsMultiPolygon exportFloat; @@ -13290,17 +13290,17 @@ void TestQgsGeometry::multiPolygon() exportFloat.addGeometry( part.clone() ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"MultiPolygon\", \"coordinates\": [[[ [2.333, 5.667], [0.6, 4.333], [2.667, 9], [2.333, 5.667]]], [[ [9, 4.111], [1.049, 1.024], [9, 4.111]]]] }" ) ); - res = exportFloat.asJSON( 3 ); + res = exportFloat.asJson( 3 ); QCOMPARE( res, expectedJsonPrec3 ); // as GML2 QString expectedGML2prec3( QStringLiteral( "2.333,5.667 0.6,4.333 2.667,9 2.333,5.6679,4.111 1.049,1.024 9,4.111" ) ); - res = elemToString( exportFloat.asGML2( doc, 3 ) ); + res = elemToString( exportFloat.asGml2( doc, 3 ) ); QGSCOMPAREGML( res, expectedGML2prec3 ); //as GML3 QString expectedGML3prec3( QStringLiteral( "2.333 5.667 0.6 4.333 2.667 9 2.333 5.6679 4.111 1.049 1.024 9 4.111" ) ); - res = elemToString( exportFloat.asGML3( doc, 3 ) ); + res = elemToString( exportFloat.asGml3( doc, 3 ) ); QCOMPARE( res, expectedGML3prec3 ); // insert geometry @@ -13839,21 +13839,21 @@ void TestQgsGeometry::geometryCollection() // as GML2 QString expectedSimpleGML2( QStringLiteral( "0,0 0,10 10,10 10,0 0,0" ) ); - QString res = elemToString( exportC.asGML2( doc ) ); + QString res = elemToString( exportC.asGml2( doc ) ); QGSCOMPAREGML( res, expectedSimpleGML2 ); QString expectedGML2empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsGeometryCollection().asGML2( doc ) ), expectedGML2empty ); + QGSCOMPAREGML( elemToString( QgsGeometryCollection().asGml2( doc ) ), expectedGML2empty ); //as GML3 QString expectedSimpleGML3( QStringLiteral( "0 0 0 10 10 10 10 0 0 0" ) ); - res = elemToString( exportC.asGML3( doc ) ); + res = elemToString( exportC.asGml3( doc ) ); QCOMPARE( res, expectedSimpleGML3 ); QString expectedGML3empty( QStringLiteral( "" ) ); - QGSCOMPAREGML( elemToString( QgsGeometryCollection().asGML3( doc ) ), expectedGML3empty ); + QGSCOMPAREGML( elemToString( QgsGeometryCollection().asGml3( doc ) ), expectedGML3empty ); // as JSON QString expectedSimpleJson( "{\"type\": \"GeometryCollection\", \"geometries\": [{\"type\": \"LineString\", \"coordinates\": [ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]}] }" ); - res = exportC.asJSON(); + res = exportC.asJson(); QCOMPARE( res, expectedSimpleJson ); part.setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::Point, 1, 1 ) @@ -13862,7 +13862,7 @@ void TestQgsGeometry::geometryCollection() exportC.addGeometry( part.clone() ); QString expectedJson( QStringLiteral( "{\"type\": \"GeometryCollection\", \"geometries\": [{\"type\": \"LineString\", \"coordinates\": [ [0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]}, {\"type\": \"LineString\", \"coordinates\": [ [1, 1], [1, 9], [9, 9], [9, 1], [1, 1]]}] }" ) ); - res = exportC.asJSON(); + res = exportC.asJson(); QCOMPARE( res, expectedJson ); QgsGeometryCollection exportFloat; @@ -13876,23 +13876,23 @@ void TestQgsGeometry::geometryCollection() exportFloat.addGeometry( part.clone() ); QString expectedJsonPrec3( QStringLiteral( "{\"type\": \"GeometryCollection\", \"geometries\": [{\"type\": \"LineString\", \"coordinates\": [ [1.111, 1.111], [1.111, 11.111], [11.111, 11.111], [11.111, 1.111], [1.111, 1.111]]}, {\"type\": \"LineString\", \"coordinates\": [ [0.667, 0.667], [0.667, 1.333], [1.333, 1.333], [1.333, 0.667], [0.667, 0.667]]}] }" ) ); - res = exportFloat.asJSON( 3 ); + res = exportFloat.asJson( 3 ); QCOMPARE( res, expectedJsonPrec3 ); // as GML2 QString expectedGML2( QStringLiteral( "0,0 0,10 10,10 10,0 0,01,1 1,9 9,9 9,1 1,1" ) ); - res = elemToString( exportC.asGML2( doc ) ); + res = elemToString( exportC.asGml2( doc ) ); QGSCOMPAREGML( res, expectedGML2 ); QString expectedGML2prec3( QStringLiteral( "1.111,1.111 1.111,11.111 11.111,11.111 11.111,1.111 1.111,1.1110.667,0.667 0.667,1.333 1.333,1.333 1.333,0.667 0.667,0.667" ) ); - res = elemToString( exportFloat.asGML2( doc, 3 ) ); + res = elemToString( exportFloat.asGml2( doc, 3 ) ); QGSCOMPAREGML( res, expectedGML2prec3 ); //as GML3 QString expectedGML3( QStringLiteral( "0 0 0 10 10 10 10 0 0 01 1 1 9 9 9 9 1 1 1" ) ); - res = elemToString( exportC.asGML3( doc ) ); + res = elemToString( exportC.asGml3( doc ) ); QCOMPARE( res, expectedGML3 ); QString expectedGML3prec3( QStringLiteral( "1.111 1.111 1.111 11.111 11.111 11.111 11.111 1.111 1.111 1.1110.667 0.667 0.667 1.333 1.333 1.333 1.333 0.667 0.667 0.667" ) ); - res = elemToString( exportFloat.asGML3( doc, 3 ) ); + res = elemToString( exportFloat.asGml3( doc, 3 ) ); QCOMPARE( res, expectedGML3prec3 ); // remove geometry @@ -14836,19 +14836,19 @@ void TestQgsGeometry::fromPolyline() QCOMPARE( fromPolyline.wkbType(), QgsWkbTypes::LineString ); polyline << QgsPoint( 10, 20 ) << QgsPoint( 30, 40 ); fromPolyline = QgsGeometry::fromPolyline( polyline ); - QCOMPARE( fromPolyline.exportToWkt(), QStringLiteral( "LineString (10 20, 30 40)" ) ); + QCOMPARE( fromPolyline.asWkt(), QStringLiteral( "LineString (10 20, 30 40)" ) ); QgsPolyline polyline3d; polyline3d << QgsPoint( QgsWkbTypes::PointZ, 10, 20, 100 ) << QgsPoint( QgsWkbTypes::PointZ, 30, 40, 200 ); fromPolyline = QgsGeometry::fromPolyline( polyline3d ); - QCOMPARE( fromPolyline.exportToWkt(), QStringLiteral( "LineStringZ (10 20 100, 30 40 200)" ) ); + QCOMPARE( fromPolyline.asWkt(), QStringLiteral( "LineStringZ (10 20 100, 30 40 200)" ) ); QgsPolyline polylineM; polylineM << QgsPoint( QgsWkbTypes::PointM, 10, 20, 0, 100 ) << QgsPoint( QgsWkbTypes::PointM, 30, 40, 0, 200 ); fromPolyline = QgsGeometry::fromPolyline( polylineM ); - QCOMPARE( fromPolyline.exportToWkt(), QStringLiteral( "LineStringM (10 20 100, 30 40 200)" ) ); + QCOMPARE( fromPolyline.asWkt(), QStringLiteral( "LineStringM (10 20 100, 30 40 200)" ) ); QgsPolyline polylineZM; polylineZM << QgsPoint( QgsWkbTypes::PointZM, 10, 20, 4, 100 ) << QgsPoint( QgsWkbTypes::PointZM, 30, 40, 5, 200 ); fromPolyline = QgsGeometry::fromPolyline( polylineZM ); - QCOMPARE( fromPolyline.exportToWkt(), QStringLiteral( "LineStringZM (10 20 4 100, 30 40 5 200)" ) ); + QCOMPARE( fromPolyline.asWkt(), QStringLiteral( "LineStringZM (10 20 4 100, 30 40 5 200)" ) ); } void TestQgsGeometry::asQPointF() @@ -15050,31 +15050,31 @@ void TestQgsGeometry::translateCheck1() QString wkt = QStringLiteral( "LineString (0 0, 10 0, 10 10)" ); QgsGeometry geom( QgsGeometry::fromWkt( wkt ) ); geom.translate( 10, -5 ); - QString obtained = geom.exportToWkt(); + QString obtained = geom.asWkt(); QString expected = QStringLiteral( "LineString (10 -5, 20 -5, 20 5)" ); QCOMPARE( obtained, expected ); geom.translate( -10, 5 ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); QCOMPARE( obtained, wkt ); wkt = QStringLiteral( "Polygon ((-2 4, -2 -10, 2 3, -2 4),(1 1, -1 1, -1 -1, 1 1))" ); geom = QgsGeometry::fromWkt( wkt ); geom.translate( -2, 10 ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); expected = QStringLiteral( "Polygon ((-4 14, -4 0, 0 13, -4 14),(-1 11, -3 11, -3 9, -1 11))" ); QCOMPARE( obtained, expected ); geom.translate( 2, -10 ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); QCOMPARE( obtained, wkt ); wkt = QStringLiteral( "Point (40 50)" ); geom = QgsGeometry::fromWkt( wkt ); geom.translate( -2, 10 ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); expected = QStringLiteral( "Point (38 60)" ); QCOMPARE( obtained, expected ); geom.translate( 2, -10 ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); QCOMPARE( obtained, wkt ); } @@ -15084,38 +15084,38 @@ void TestQgsGeometry::rotateCheck1() QString wkt = QStringLiteral( "LineString (0 0, 10 0, 10 10)" ); QgsGeometry geom( QgsGeometry::fromWkt( wkt ) ); geom.rotate( 90, QgsPointXY( 0, 0 ) ); - QString obtained = geom.exportToWkt(); + QString obtained = geom.asWkt(); QString expected = QStringLiteral( "LineString (0 0, 0 -10, 10 -10)" ); QCOMPARE( obtained, expected ); geom.rotate( -90, QgsPointXY( 0, 0 ) ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); QCOMPARE( obtained, wkt ); wkt = QStringLiteral( "Polygon ((-2 4, -2 -10, 2 3, -2 4),(1 1, -1 1, -1 -1, 1 1))" ); geom = QgsGeometry::fromWkt( wkt ); geom.rotate( 90, QgsPointXY( 0, 0 ) ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); expected = QStringLiteral( "Polygon ((4 2, -10 2, 3 -2, 4 2),(1 -1, 1 1, -1 1, 1 -1))" ); QCOMPARE( obtained, expected ); geom.rotate( -90, QgsPointXY( 0, 0 ) ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); QCOMPARE( obtained, wkt ); wkt = QStringLiteral( "Point (40 50)" ); geom = QgsGeometry::fromWkt( wkt ); geom.rotate( 90, QgsPointXY( 0, 0 ) ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); expected = QStringLiteral( "Point (50 -40)" ); QCOMPARE( obtained, expected ); geom.rotate( -90, QgsPointXY( 0, 0 ) ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); QCOMPARE( obtained, wkt ); geom.rotate( 180, QgsPointXY( 40, 0 ) ); expected = QStringLiteral( "Point (40 -50)" ); - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); QCOMPARE( obtained, expected ); geom.rotate( 180, QgsPointXY( 40, 0 ) ); // round-trip - obtained = geom.exportToWkt(); + obtained = geom.asWkt(); QCOMPARE( obtained, wkt ); } @@ -15185,7 +15185,7 @@ void TestQgsGeometry::smoothCheck() QString wkt = QStringLiteral( "Point (40 50)" ); QgsGeometry geom( QgsGeometry::fromWkt( wkt ) ); QgsGeometry result = geom.smooth( 1, 0.25 ); - QString obtained = result.exportToWkt(); + QString obtained = result.asWkt(); QCOMPARE( obtained, wkt ); //linestring @@ -15336,48 +15336,48 @@ void TestQgsGeometry::exportToGeoJSON() //Point QString wkt = QStringLiteral( "Point (40 50)" ); QgsGeometry geom( QgsGeometry::fromWkt( wkt ) ); - QString obtained = geom.exportToGeoJSON(); + QString obtained = geom.asJson(); QString geojson = QStringLiteral( "{\"type\": \"Point\", \"coordinates\": [40, 50]}" ); QCOMPARE( obtained, geojson ); //MultiPoint wkt = QStringLiteral( "MultiPoint (0 0, 10 0, 10 10, 20 10)" ); geom = QgsGeometry::fromWkt( wkt ); - obtained = geom.exportToGeoJSON(); + obtained = geom.asJson(); geojson = QStringLiteral( "{\"type\": \"MultiPoint\", \"coordinates\": [ [0, 0], [10, 0], [10, 10], [20, 10]] }" ); QCOMPARE( obtained, geojson ); //Linestring wkt = QStringLiteral( "LineString(0 0, 10 0, 10 10, 20 10)" ); geom = QgsGeometry::fromWkt( wkt ); - obtained = geom.exportToGeoJSON(); + obtained = geom.asJson(); geojson = QStringLiteral( "{\"type\": \"LineString\", \"coordinates\": [ [0, 0], [10, 0], [10, 10], [20, 10]]}" ); QCOMPARE( obtained, geojson ); //MultiLineString wkt = QStringLiteral( "MultiLineString ((0 0, 10 0, 10 10, 20 10),(30 30, 40 30, 40 40, 50 40))" ); geom = QgsGeometry::fromWkt( wkt ); - obtained = geom.exportToGeoJSON(); + obtained = geom.asJson(); geojson = QStringLiteral( "{\"type\": \"MultiLineString\", \"coordinates\": [[ [0, 0], [10, 0], [10, 10], [20, 10]], [ [30, 30], [40, 30], [40, 40], [50, 40]]] }" ); QCOMPARE( obtained, geojson ); //Polygon wkt = QStringLiteral( "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0 ),(2 2, 4 2, 4 4, 2 4, 2 2))" ); geom = QgsGeometry::fromWkt( wkt ); - obtained = geom.exportToGeoJSON(); + obtained = geom.asJson(); geojson = QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [[ [0, 0], [10, 0], [10, 10], [0, 10], [0, 0]], [ [2, 2], [4, 2], [4, 4], [2, 4], [2, 2]]] }" ); QCOMPARE( obtained, geojson ); //MultiPolygon wkt = QStringLiteral( "MultiPolygon (((0 0, 10 0, 10 10, 0 10, 0 0 )),((2 2, 4 2, 4 4, 2 4, 2 2)))" ); geom = QgsGeometry::fromWkt( wkt ); - obtained = geom.exportToGeoJSON(); + obtained = geom.asJson(); geojson = QStringLiteral( "{\"type\": \"MultiPolygon\", \"coordinates\": [[[ [0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]], [[ [2, 2], [4, 2], [4, 4], [2, 4], [2, 2]]]] }" ); QCOMPARE( obtained, geojson ); // no geometry QgsGeometry nullGeom( nullptr ); - obtained = nullGeom.exportToGeoJSON(); + obtained = nullGeom.asJson(); geojson = QStringLiteral( "null" ); QCOMPARE( obtained, geojson ); } @@ -15469,7 +15469,7 @@ void TestQgsGeometry::wkbInOut() //QList errors; //g14182.validateGeometry(errors); // Check with valgrind ! - QString wkt = g14182.exportToWkt(); + QString wkt = g14182.asWkt(); QCOMPARE( wkt, QString() ); //WKB with a truncated header @@ -15718,25 +15718,25 @@ void TestQgsGeometry::reshapeGeometryLineMerge() QgsGeometry g2D_1 = g2D; res = g2D_1.reshapeGeometry( line2D_1 ); QCOMPARE( res, 0 ); - QCOMPARE( g2D_1.exportToWkt(), QString( "LineString (10 10, 20 20, 30 30)" ) ); + QCOMPARE( g2D_1.asWkt(), QString( "LineString (10 10, 20 20, 30 30)" ) ); // prepend with 2D line QgsGeometry g2D_2 = g2D; res = g2D_2.reshapeGeometry( line2D_2 ); QCOMPARE( res, 0 ); - QCOMPARE( g2D_2.exportToWkt(), QString( "LineString (-10 -10, 10 10, 20 20)" ) ); + QCOMPARE( g2D_2.asWkt(), QString( "LineString (-10 -10, 10 10, 20 20)" ) ); // append with 3D line QgsGeometry g3D_1 = g3D; res = g3D_1.reshapeGeometry( line3D_1 ); QCOMPARE( res, 0 ); - QCOMPARE( g3D_1.exportToWkt(), QString( "LineStringZ (10 10 1, 20 20 2, 30 30 3)" ) ); + QCOMPARE( g3D_1.asWkt(), QString( "LineStringZ (10 10 1, 20 20 2, 30 30 3)" ) ); // prepend with 3D line QgsGeometry g3D_2 = g3D; res = g3D_2.reshapeGeometry( line3D_2 ); QCOMPARE( res, 0 ); - QCOMPARE( g3D_2.exportToWkt(), QString( "LineStringZ (-10 -10 -1, 10 10 1, 20 20 2)" ) ); + QCOMPARE( g3D_2.asWkt(), QString( "LineStringZ (-10 -10 -1, 10 10 1, 20 20 2)" ) ); } void TestQgsGeometry::createCollectionOfType() diff --git a/tests/src/core/testqgsgeometryimport.cpp b/tests/src/core/testqgsgeometryimport.cpp index 3aa8fbd12f0c..5c0867eb3c31 100644 --- a/tests/src/core/testqgsgeometryimport.cpp +++ b/tests/src/core/testqgsgeometryimport.cpp @@ -272,7 +272,7 @@ void TestQgsGeometryImport::delimiters() QFETCH( QString, expected ); QgsGeometry gInput = QgsGeometry::fromWkt( input ); - QCOMPARE( gInput.exportToWkt(), expected ); + QCOMPARE( gInput.asWkt(), expected ); } QGSTEST_MAIN( TestQgsGeometryImport ) diff --git a/tests/src/core/testqgsmaptopixelgeometrysimplifier.cpp b/tests/src/core/testqgsmaptopixelgeometrysimplifier.cpp index b143e91b49a8..60eb1f29caba 100644 --- a/tests/src/core/testqgsmaptopixelgeometrysimplifier.cpp +++ b/tests/src/core/testqgsmaptopixelgeometrysimplifier.cpp @@ -127,7 +127,7 @@ void TestQgsMapToPixelGeometrySimplifier::testLine1() fl = QgsMapToPixelSimplifier::SimplifyGeometry; QgsMapToPixelSimplifier simplifier( fl, 10.0 ); QgsGeometry ret = simplifier.simplify( g ); - wkt = ret.exportToWkt(); + wkt = ret.asWkt(); // NOTE: vertex 1,1 is in this result, because we keep the first two or last two vertices in a line // TO ensure that the angles at the line start and end are the same after simplification // compared to what we have before @@ -136,13 +136,13 @@ void TestQgsMapToPixelGeometrySimplifier::testLine1() simplifier.setSimplifyFlags( QgsMapToPixelSimplifier::SimplifyEnvelope ); simplifier.setTolerance( 20.0 ); ret = simplifier.simplify( g ); - wkt = ret.exportToWkt(); + wkt = ret.asWkt(); // Cannot be simplified to its envelope since it's just at the setTollerance QCOMPARE( wkt, QString( "LineString (0 0, 1 1, 2 0, 3 1, 4 0, 20 1, 20 0, 10 0, 5 0)" ) ); simplifier.setTolerance( 30.0 ); ret = simplifier.simplify( g ); - wkt = ret.exportToWkt(); + wkt = ret.asWkt(); // Got simplified into a line going from one corner of the envelope to the other QCOMPARE( wkt, QString( "LineString (0 0, 20 1)" ) ); } @@ -176,7 +176,7 @@ void TestQgsMapToPixelGeometrySimplifier::testWkbDimensionMismatch() QgsGeometry g12416; // NOTE: wkb onwership transferred to QgsGeometry g12416.fromWkb( wkb, size ); - QString wkt = g12416.exportToWkt(); + QString wkt = g12416.asWkt(); QCOMPARE( wkt, QString( "MultiLineStringZ ((0 0 0, 1 1 0, 2 0 0, 3 1 0, 10 0 -0.000001),(0 0 0, 0 0 0.000001))" ) ); int fl = QgsMapToPixelSimplifier::SimplifyGeometry; @@ -191,7 +191,7 @@ void TestQgsMapToPixelGeometrySimplifier::testCircularString() const QgsGeometry g( QgsGeometry::fromWkt( WKT ) ); const QgsMapToPixelSimplifier simplifier( QgsMapToPixelSimplifier::SimplifyGeometry, 0.1 ); - QCOMPARE( simplifier.simplify( g ).exportToWkt(), WKT ); + QCOMPARE( simplifier.simplify( g ).asWkt(), WKT ); } void TestQgsMapToPixelGeometrySimplifier::testVisvalingam() @@ -202,7 +202,7 @@ void TestQgsMapToPixelGeometrySimplifier::testVisvalingam() const QgsMapToPixelSimplifier simplifier( QgsMapToPixelSimplifier::SimplifyGeometry, 7, QgsMapToPixelSimplifier::Visvalingam ); QString expectedWkt( QStringLiteral( "LineString (0 0, 40 0, 41 100, 42 0, 50 0)" ) ); - QCOMPARE( simplifier.simplify( g ).exportToWkt(), expectedWkt ); + QCOMPARE( simplifier.simplify( g ).asWkt(), expectedWkt ); } QGSTEST_MAIN( TestQgsMapToPixelGeometrySimplifier ) diff --git a/tests/src/core/testqgspoint.cpp b/tests/src/core/testqgspoint.cpp index 726cfea7922e..6413cb6b27de 100644 --- a/tests/src/core/testqgspoint.cpp +++ b/tests/src/core/testqgspoint.cpp @@ -41,12 +41,6 @@ class TestQgsPointXY: public QObject void toQPointF(); void operators(); void toString(); - void toDegreesMinutesSeconds(); - void toDegreesMinutesSecondsNoSuffix(); - void toDegreesMinutesSecondsPadded(); - void toDegreesMinutes(); - void toDegreesMinutesNoSuffix(); - void toDegreesMinutesPadded(); void sqrDist(); void distance(); void compare(); @@ -194,441 +188,6 @@ void TestQgsPointXY::toString() QCOMPARE( mPoint1.toString( 2 ), QString( "20.00,-20.00" ) ); } -void TestQgsPointXY::toDegreesMinutesSeconds() -{ - mReport += QLatin1String( "

Testing toDegreesMinutesSeconds()

" ); - mReport += "

" + mPoint1.toDegreesMinutesSeconds( 2 ) + "

"; - mReport += "

" + mPoint2.toDegreesMinutesSeconds( 2 ) + "

"; - mReport += "

" + mPoint3.toDegreesMinutesSeconds( 2 ) + "

"; - mReport += "

" + mPoint4.toDegreesMinutesSeconds( 2 ) + "

"; - - qDebug() << mPoint4.toDegreesMinutesSeconds( 2 ); - QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + - QChar( 0x2033 ) + - QStringLiteral( "E,20" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + - QStringLiteral( "N" ); - qDebug() << myControlString; - QCOMPARE( mPoint4.toDegreesMinutesSeconds( 2 ), myControlString ); - - //check if longitudes > 180 or <-180 wrap around - myControlString = QStringLiteral( "10" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 370, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "10" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( -370, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "179" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 181, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "179" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( -181, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "1" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 359, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "1" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( -359, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - - //check if latitudes > 90 or <-90 wrap around - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + - QStringLiteral( ",10" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "N" ); - QCOMPARE( QgsPointXY( 0, 190 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + - QStringLiteral( ",10" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "S" ); - QCOMPARE( QgsPointXY( 0, -190 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + - QStringLiteral( ",89" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "S" ); - QCOMPARE( QgsPointXY( 0, 91 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + - QStringLiteral( ",89" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "N" ); - QCOMPARE( QgsPointXY( 0, -91 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + - QStringLiteral( ",1" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "S" ); - QCOMPARE( QgsPointXY( 0, 179 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + - QStringLiteral( ",1" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "N" ); - QCOMPARE( QgsPointXY( 0, -179 ).toDegreesMinutesSeconds( 2 ), myControlString ); - - //should be no directional suffixes for 0 degree coordinates - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 0, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - //should also be no directional suffix for 0 degree coordinates within specified precision - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 2 ), myControlString ); - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 2 ), myControlString ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 ) + QStringLiteral( "N" ); - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 5 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 ) + QStringLiteral( "S" ); - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 5 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 5 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 5 ), myControlString ); - - //test rounding does not create seconds >= 60 - myControlString = QStringLiteral( "100" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) + - QStringLiteral( ",90" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "N" ); - QCOMPARE( QgsPointXY( 99.999999, 89.999999 ).toDegreesMinutesSeconds( 2 ), myControlString ); - - //should be no directional suffixes for 180 degree longitudes - myControlString = QStringLiteral( "180" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 180, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - //should also be no directional suffix for 180 degree longitudes within specified precision - QCOMPARE( QgsPointXY( 180.000001, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - QCOMPARE( QgsPointXY( 179.999999, 0 ).toDegreesMinutesSeconds( 2 ), myControlString ); - myControlString = QStringLiteral( "179" ) + QChar( 176 ) + - QStringLiteral( "59" ) + QChar( 0x2032 ) + QStringLiteral( "59.99640" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 180.000001, 0 ).toDegreesMinutesSeconds( 5 ), myControlString ); - myControlString = QStringLiteral( "179" ) + QChar( 176 ) + - QStringLiteral( "59" ) + QChar( 0x2032 ) + QStringLiteral( "59.99640" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 179.999999, 0 ).toDegreesMinutesSeconds( 5 ), myControlString ); -} - -void TestQgsPointXY::toDegreesMinutesSecondsNoSuffix() -{ - QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + - QChar( 0x2033 ) + - QStringLiteral( ",20" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ); - QCOMPARE( mPoint4.toDegreesMinutesSeconds( 2, false ), myControlString ); - - //test 0 lat/long - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ); - QVERIFY( QgsPointXY( 0, 0 ).toDegreesMinutesSeconds( 2, false ) == myControlString ); - //test near zero lat/long - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 2, false ), myControlString ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 2, false ), myControlString ); - //should be no "-" prefix for near-zero lat/long when rounding to 2 decimal places - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 2, false ), myControlString ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 2, false ), myControlString ); - - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 5, false ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + - QChar( 0x2033 ) + - QStringLiteral( ",-0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 5, false ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 5, false ), myControlString ); - myControlString = QStringLiteral( "-0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 5, false ), myControlString ); -} - -void TestQgsPointXY::toDegreesMinutesSecondsPadded() -{ - QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00" ) + - QChar( 0x2033 ) + - QStringLiteral( "E,20" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00" ) + QChar( 0x2033 ) + - QStringLiteral( "N" ); - qDebug() << myControlString; - QCOMPARE( mPoint4.toDegreesMinutesSeconds( 2, true, true ), myControlString ); - - //should be no directional suffixes for 0 degree coordinates - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00" ) + QChar( 0x2033 ); - QVERIFY( QgsPointXY( 0, 0 ).toDegreesMinutesSeconds( 2, true, true ) == myControlString ); - //should also be no directional suffix for 0 degree coordinates within specified precision - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 2, true, true ), myControlString ); - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 2, true, true ), myControlString ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 2, true, true ), myControlString ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 2, true, true ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00000" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00360" ) + QChar( 0x2033 ) + QStringLiteral( "N" ); - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 5, true, true ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00000" ) + - QChar( 0x2033 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00360" ) + QChar( 0x2033 ) + QStringLiteral( "S" ); - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 5, true, true ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00360" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00000" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 5, true, true ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00360" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00000" ) + QChar( 0x2033 ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 5, true, true ), myControlString ); -} - -void TestQgsPointXY::toDegreesMinutes() -{ - mReport += QLatin1String( "

Testing toDegreesMinutes()

" ); - mReport += "

" + mPoint1.toDegreesMinutes( 2 ) + "

"; - mReport += "

" + mPoint2.toDegreesMinutes( 2 ) + "

"; - mReport += "

" + mPoint3.toDegreesMinutes( 2 ) + "

"; - mReport += "

" + mPoint4.toDegreesMinutes( 2 ) + "

"; - - qDebug() << mPoint4.toDegreesMinutes( 2 ); - QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + - QStringLiteral( "E,20" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "N" ); - qDebug() << myControlString; - QCOMPARE( mPoint4.toDegreesMinutes( 2 ), myControlString ); - - //check if longitudes > 180 or <-180 wrap around - myControlString = QStringLiteral( "10" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 370, 0 ).toDegreesMinutes( 2 ), myControlString ); - myControlString = QStringLiteral( "10" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( -370, 0 ).toDegreesMinutes( 2 ), myControlString ); - myControlString = QStringLiteral( "179" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 181, 0 ).toDegreesMinutes( 2 ), myControlString ); - myControlString = QStringLiteral( "179" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( -181, 0 ).toDegreesMinutes( 2 ), myControlString ); - myControlString = QStringLiteral( "1" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 359, 0 ).toDegreesMinutes( 2 ), myControlString ); - myControlString = QStringLiteral( "1" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( -359, 0 ).toDegreesMinutes( 2 ), myControlString ); - - //should be no directional suffixes for 0 degree coordinates - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ); - QVERIFY( QgsPointXY( 0, 0 ).toDegreesMinutes( 2 ) == myControlString ); - //should also be no directional suffix for 0 degree coordinates within specified precision - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 2 ), myControlString ); - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 2 ), myControlString ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 2 ), myControlString ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 2 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0.00000" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00006" ) + QChar( 0x2032 ) + QStringLiteral( "N" ); - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 5 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0.00000" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00006" ) + QChar( 0x2032 ) + QStringLiteral( "S" ); - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 5 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0.00006" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00000" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 5 ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0.00006" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00000" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 5 ), myControlString ); - - //test rounding does not create minutes >= 60 - myControlString = QStringLiteral( "100" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) + - QStringLiteral( ",100" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "N" ); - QCOMPARE( QgsPointXY( 99.999999, 99.999999 ).toDegreesMinutes( 2 ), myControlString ); - - //should be no directional suffixes for 180 degree longitudes - myControlString = QStringLiteral( "180" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 180, 0 ).toDegreesMinutes( 2 ), myControlString ); - //should also be no directional suffix for 180 degree longitudes within specified precision - QCOMPARE( QgsPointXY( 180.000001, 0 ).toDegreesMinutes( 2 ), myControlString ); - QCOMPARE( QgsPointXY( 179.999999, 0 ).toDegreesMinutes( 2 ), myControlString ); - myControlString = QStringLiteral( "179" ) + QChar( 176 ) + - QStringLiteral( "59.99994" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00000" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 180.000001, 0 ).toDegreesMinutes( 5 ), myControlString ); - myControlString = QStringLiteral( "179" ) + QChar( 176 ) + - QStringLiteral( "59.99994" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00000" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 179.999999, 0 ).toDegreesMinutes( 5 ), myControlString ); -} - -void TestQgsPointXY::toDegreesMinutesNoSuffix() -{ - QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + - QStringLiteral( ",20" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ); - QCOMPARE( mPoint4.toDegreesMinutes( 2, false ), myControlString ); - - //test 0 lat/long - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00" ) + QChar( 0x2032 ); - QVERIFY( QgsPointXY( 0, 0 ).toDegreesMinutes( 2, false ) == myControlString ); - //test near zero lat/long - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 2, false ), myControlString ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 2, false ), myControlString ); - //should be no "-" prefix for near-zero lat/long when rounding to 2 decimal places - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 2, false ), myControlString ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 2, false ), myControlString ); - - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0.00000" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00006" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 5, false ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0.00000" ) + QChar( 0x2032 ) + - QStringLiteral( ",-0" ) + QChar( 176 ) + - QStringLiteral( "0.00006" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 5, false ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "0.00006" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00000" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 5, false ), myControlString ); - myControlString = QStringLiteral( "-0" ) + QChar( 176 ) + - QStringLiteral( "0.00006" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "0.00000" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 5, false ), myControlString ); -} - -void TestQgsPointXY::toDegreesMinutesPadded() -{ - QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) + - QStringLiteral( "00.00" ) + QChar( 0x2032 ) + - QStringLiteral( "E,20" ) + QChar( 176 ) + - QStringLiteral( "00.00" ) + QChar( 0x2032 ) + QStringLiteral( "N" ); - qDebug() << myControlString; - QCOMPARE( mPoint4.toDegreesMinutes( 2, true, true ), myControlString ); - - //should be no directional suffixes for 0 degree coordinates - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "00.00" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "00.00" ) + QChar( 0x2032 ); - QVERIFY( QgsPointXY( 0, 0 ).toDegreesMinutes( 2, true, true ) == myControlString ); - //should also be no directional suffix for 0 degree coordinates within specified precision - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 2, true, true ), myControlString ); - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 2, true, true ), myControlString ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 2, true, true ), myControlString ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 2, true, true ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "00.00000" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "00.00006" ) + QChar( 0x2032 ) + QStringLiteral( "N" ); - QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 5, true, true ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "00.00000" ) + QChar( 0x2032 ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "00.00006" ) + QChar( 0x2032 ) + QStringLiteral( "S" ); - QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 5, true, true ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "00.00006" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "00.00000" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 5, true, true ), myControlString ); - myControlString = QStringLiteral( "0" ) + QChar( 176 ) + - QStringLiteral( "00.00006" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) + - QStringLiteral( ",0" ) + QChar( 176 ) + - QStringLiteral( "00.00000" ) + QChar( 0x2032 ); - QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 5, true, true ), myControlString ); -} - void TestQgsPointXY::sqrDist() { QCOMPARE( QgsPointXY( 1, 2 ).sqrDist( QgsPointXY( 2, 2 ) ), 1.0 ); diff --git a/tests/src/providers/grass/testqgsgrassprovider.cpp b/tests/src/providers/grass/testqgsgrassprovider.cpp index 40592e5334d7..9bd5cfcbfea6 100644 --- a/tests/src/providers/grass/testqgsgrassprovider.cpp +++ b/tests/src/providers/grass/testqgsgrassprovider.cpp @@ -126,13 +126,13 @@ QString TestQgsGrassCommand::toString() const { if ( grassFeature.hasGeometry() ) { - string += "
grass: " + grassFeature.geometry().exportToWkt( 1 ); + string += "
grass: " + grassFeature.geometry().asWkt( 1 ); } } if ( expectedFeature.hasGeometry() ) { - string += "
expected: " + expectedFeature.geometry().exportToWkt( 1 ); + string += "
expected: " + expectedFeature.geometry().asWkt( 1 ); } } else if ( command == DeleteFeature ) @@ -143,7 +143,7 @@ QString TestQgsGrassCommand::toString() const else if ( command == ChangeGeometry ) { string += QLatin1String( "ChangeGeometry " ); - string += QStringLiteral( "fid: %1 geometry: %2" ).arg( fid ).arg( geometry->exportToWkt( 1 ) ); + string += QStringLiteral( "fid: %1 geometry: %2" ).arg( fid ).arg( geometry->asWkt( 1 ) ); } else if ( command == AddAttribute ) { diff --git a/tests/src/python/CMakeLists.txt b/tests/src/python/CMakeLists.txt index 29da79641ee4..43c245ef9902 100644 --- a/tests/src/python/CMakeLists.txt +++ b/tests/src/python/CMakeLists.txt @@ -25,6 +25,7 @@ ADD_PYTHON_TEST(PyQgsCheckableComboBox test_qgscheckablecombobox.py) ADD_PYTHON_TEST(PyQgsColorButton test_qgscolorbutton.py) ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py) ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py) +ADD_PYTHON_TEST(PyQgsCoordinateFormatter test_qgscoordinateformatter.py) ADD_PYTHON_TEST(PyQgsComposerEffects test_qgscomposereffects.py) ADD_PYTHON_TEST(PyQgsComposerHtml test_qgscomposerhtml.py) ADD_PYTHON_TEST(PyQgsComposerItem test_qgscomposeritem.py) diff --git a/tests/src/python/featuresourcetestbase.py b/tests/src/python/featuresourcetestbase.py index 6ef4b7a7443e..a801f4013a7d 100644 --- a/tests/src/python/featuresourcetestbase.py +++ b/tests/src/python/featuresourcetestbase.py @@ -82,7 +82,7 @@ def testGetFeatures(self, source=None, extra_features=[], skip_features=[], chan # field attrs[4] = str(attrs[4]) attributes[f['pk']] = attrs - geometries[f['pk']] = f.hasGeometry() and f.geometry().exportToWkt() + geometries[f['pk']] = f.hasGeometry() and f.geometry().asWkt() expected_attributes = {5: [5, -200, NULL, 'NuLl', '5'], 3: [3, 300, 'Pear', 'PEaR', '3'], @@ -98,7 +98,7 @@ def testGetFeatures(self, source=None, extra_features=[], skip_features=[], chan for f in extra_features: expected_attributes[f[0]] = f.attributes() if f.hasGeometry(): - expected_geometries[f[0]] = f.geometry().exportToWkt() + expected_geometries[f[0]] = f.geometry().asWkt() else: expected_geometries[f[0]] = None @@ -110,7 +110,7 @@ def testGetFeatures(self, source=None, extra_features=[], skip_features=[], chan expected_attributes[i][attr_idx] = v for i, g, in changed_geometries.items(): if g: - expected_geometries[i] = g.exportToWkt() + expected_geometries[i] = g.asWkt() else: expected_geometries[i] = None diff --git a/tests/src/python/test_provider_memory.py b/tests/src/python/test_provider_memory.py index 620b296be546..996c8743e882 100644 --- a/tests/src/python/test_provider_memory.py +++ b/tests/src/python/test_provider_memory.py @@ -222,9 +222,9 @@ def testAddFeatures(self): geom = f.geometry() myMessage = ('Expected: %s\nGot: %s\n' % - ("Point (10 10)", str(geom.exportToWkt()))) + ("Point (10 10)", str(geom.asWkt()))) - assert compareWkt(str(geom.exportToWkt()), "Point (10 10)"), myMessage + assert compareWkt(str(geom.asWkt()), "Point (10 10)"), myMessage def testGetFields(self): layer = QgsVectorLayer("Point", "test", "memory") diff --git a/tests/src/python/test_provider_ogr_gpkg.py b/tests/src/python/test_provider_ogr_gpkg.py index 8196c88dac29..da884fdb9599 100644 --- a/tests/src/python/test_provider_ogr_gpkg.py +++ b/tests/src/python/test_provider_ogr_gpkg.py @@ -91,7 +91,7 @@ def testSingleToMultiPolygonPromotion(self): got_geom = got.geometry() reference = QgsGeometry.fromWkt('MultiPolygon (((0 0, 0 1, 1 1, 0 0)))') # The geometries must be binarily identical - self.assertEqual(got_geom.exportToWkb(), reference.exportToWkb(), 'Expected {}, got {}'.format(reference.exportToWkt(), got_geom.exportToWkt())) + self.assertEqual(got_geom.asWkb(), reference.asWkb(), 'Expected {}, got {}'.format(reference.asWkt(), got_geom.asWkt())) def testCurveGeometryType(self): @@ -109,7 +109,7 @@ def testCurveGeometryType(self): got_geom = got.geometry() reference = QgsGeometry.fromWkt('CurvePolygon (((0 0, 0 1, 1 1, 0 0)))') # The geometries must be binarily identical - self.assertEqual(got_geom.exportToWkb(), reference.exportToWkb(), 'Expected {}, got {}'.format(reference.exportToWkt(), got_geom.exportToWkt())) + self.assertEqual(got_geom.asWkb(), reference.asWkb(), 'Expected {}, got {}'.format(reference.asWkt(), got_geom.asWkt())) def internalTestBug15351(self, orderClosing): @@ -522,13 +522,13 @@ def testGeopackageTwoLayerEdition(self): got_geom = got.geometry() self.assertEqual(got['attr'], 100) reference = QgsGeometry.fromWkt('Point (4 4)') - self.assertEqual(got_geom.exportToWkb(), reference.exportToWkb(), 'Expected {}, got {}'.format(reference.exportToWkt(), got_geom.exportToWkt())) + self.assertEqual(got_geom.asWkb(), reference.asWkb(), 'Expected {}, got {}'.format(reference.asWkt(), got_geom.asWkt())) got = [feat for feat in vl2.getFeatures()][0] got_geom = got.geometry() self.assertEqual(got['attr'], 101) reference = QgsGeometry.fromWkt('Point (5 5)') - self.assertEqual(got_geom.exportToWkb(), reference.exportToWkb(), 'Expected {}, got {}'.format(reference.exportToWkt(), got_geom.exportToWkt())) + self.assertEqual(got_geom.asWkb(), reference.asWkb(), 'Expected {}, got {}'.format(reference.asWkt(), got_geom.asWkt())) def testGeopackageManyLayers(self): ''' test opening more than 64 layers without running out of Spatialite connections ''' diff --git a/tests/src/python/test_provider_postgres.py b/tests/src/python/test_provider_postgres.py index 2ad975dc4ab4..670478647773 100644 --- a/tests/src/python/test_provider_postgres.py +++ b/tests/src/python/test_provider_postgres.py @@ -169,7 +169,7 @@ def test_table(dbconn, table_name, wkt): vl = QgsVectorLayer('%s srid=4326 table="qgis_test".%s (geom) sql=' % (dbconn, table_name), "testgeom", "postgres") self.assertTrue(vl.isValid()) for f in vl.getFeatures(): - self.assertEqual(f.geometry().exportToWkt(), wkt) + self.assertEqual(f.geometry().asWkt(), wkt) test_table(self.dbconn, 'p2d', 'Polygon ((0 0, 1 0, 1 1, 0 1, 0 0))') test_table(self.dbconn, 'p3d', 'PolygonZ ((0 0 0, 1 0 0, 1 1 0, 0 1 0, 0 0 0))') diff --git a/tests/src/python/test_provider_virtual.py b/tests/src/python/test_provider_virtual.py index 75130defcae4..0b9e3c9bf6bc 100644 --- a/tests/src/python/test_provider_virtual.py +++ b/tests/src/python/test_provider_virtual.py @@ -624,22 +624,22 @@ def test_geometry_conversion(self): l = QgsVectorLayer("?query=%s&geometry=geom:multipoint:0" % query, "tt", "virtual", QgsVectorLayer.LayerOptions(False)) self.assertEqual(l.isValid(), True) for f in l.getFeatures(): - self.assertEqual(f.geometry().exportToWkt().lower().startswith("multipoint"), True) - self.assertEqual("),(" in f.geometry().exportToWkt(), True) # has two points + self.assertEqual(f.geometry().asWkt().lower().startswith("multipoint"), True) + self.assertEqual("),(" in f.geometry().asWkt(), True) # has two points query = toPercent("select geomfromtext('multipolygon(((0 0,1 0,1 1,0 1,0 0)),((0 1,1 1,1 2,0 2,0 1)))') as geom") l = QgsVectorLayer("?query=%s&geometry=geom:multipolygon:0" % query, "tt", "virtual", QgsVectorLayer.LayerOptions(False)) self.assertEqual(l.isValid(), True) for f in l.getFeatures(): - self.assertEqual(f.geometry().exportToWkt().lower().startswith("multipolygon"), True) - self.assertEqual(")),((" in f.geometry().exportToWkt(), True) # has two polygons + self.assertEqual(f.geometry().asWkt().lower().startswith("multipolygon"), True) + self.assertEqual(")),((" in f.geometry().asWkt(), True) # has two polygons query = toPercent("select geomfromtext('multilinestring((0 0,1 0,1 1,0 1,0 0),(0 1,1 1,1 2,0 2,0 1))') as geom") l = QgsVectorLayer("?query=%s&geometry=geom:multilinestring:0" % query, "tt", "virtual", QgsVectorLayer.LayerOptions(False)) self.assertEqual(l.isValid(), True) for f in l.getFeatures(): - self.assertEqual(f.geometry().exportToWkt().lower().startswith("multilinestring"), True) - self.assertEqual("),(" in f.geometry().exportToWkt(), True) # has two linestrings + self.assertEqual(f.geometry().asWkt().lower().startswith("multilinestring"), True) + self.assertEqual("),(" in f.geometry().asWkt(), True) # has two linestrings def test_queryOnMemoryLayer(self): ml = QgsVectorLayer("Point?srid=EPSG:4326&field=a:int", "mem", "memory") diff --git a/tests/src/python/test_provider_wfs.py b/tests/src/python/test_provider_wfs.py index 0f3dce732db6..9dd83bb68e30 100644 --- a/tests/src/python/test_provider_wfs.py +++ b/tests/src/python/test_provider_wfs.py @@ -415,7 +415,7 @@ def testWFS10(self): self.assertEqual(vl.featureCount(), 0) reference = QgsGeometry.fromRect(QgsRectangle(400000.0, 5400000.0, 450000.0, 5500000.0)) vl_extent = QgsGeometry.fromRect(vl.extent()) - assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt()) + assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.asWkt(), vl_extent.asWkt()) with open(sanitize(endpoint, '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&TYPENAME=my:typename&SRSNAME=EPSG:32631'), 'wb') as f: f.write(""" @@ -658,7 +658,7 @@ def testWFS10_latlongboundingbox_in_WGS84(self): reference = QgsGeometry.fromRect(QgsRectangle(399999.9999999680439942, 5399338.9090830031782389, 449999.9999999987776391, 5500658.0448500607162714)) vl_extent = QgsGeometry.fromRect(vl.extent()) - assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt()) + assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.asWkt(), vl_extent.asWkt()) def testWFST10(self): """Test WFS-T 1.0 (read-write)""" @@ -2038,7 +2038,7 @@ def testWrongCapabilityExtent(self): reference = QgsGeometry.fromRect(QgsRectangle(2, 49, 2, 49)) vl_extent = QgsGeometry.fromRect(vl.extent()) - assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt()) + assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.asWkt(), vl_extent.asWkt()) # Same with restrictToRequestBBOX=1 vl = QgsVectorLayer("url='http://" + endpoint + "' typename='my:typename' version='2.0.0' restrictToRequestBBOX=1", 'test', 'WFS') @@ -2179,7 +2179,7 @@ def testGeomedia(self): # Extent before downloading features reference = QgsGeometry.fromRect(QgsRectangle(243900.3520259926444851, 4427769.1559739429503679, 1525592.3040170343592763, 5607994.6020106188952923)) vl_extent = QgsGeometry.fromRect(vl.extent()) - assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt()) + assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.asWkt(), vl_extent.asWkt()) # Download all features features = [f for f in vl.getFeatures()] @@ -2187,7 +2187,7 @@ def testGeomedia(self): reference = QgsGeometry.fromRect(QgsRectangle(500000, 4500000, 510000, 4510000)) vl_extent = QgsGeometry.fromRect(vl.extent()) - assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt()) + assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.asWkt(), vl_extent.asWkt()) self.assertEqual(features[0]['intfield'], 1) self.assertEqual(features[1]['intfield'], 2) diff --git a/tests/src/python/test_qgsaggregatecalculator.py b/tests/src/python/test_qgsaggregatecalculator.py index db0dc0e99318..51e40588d59b 100644 --- a/tests/src/python/test_qgsaggregatecalculator.py +++ b/tests/src/python/test_qgsaggregatecalculator.py @@ -79,7 +79,7 @@ def testGeometry(self): val, ok = agg.calculate(QgsAggregateCalculator.GeometryCollect, '$geometry') self.assertTrue(ok) expwkt = "MultiPoint ((0 0), (1 1), (2 2))" - wkt = val.exportToWkt() + wkt = val.asWkt() self.assertTrue(compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)) def testNumeric(self): @@ -359,7 +359,7 @@ def testExpression(self): # geometry val, ok = agg.calculate(QgsAggregateCalculator.GeometryCollect, "make_point( coalesce(fldint,0), 2 )") self.assertTrue(ok) - self.assertTrue(val.exportToWkt(), 'MultiPoint((4 2, 2 2, 3 2, 2 2,5 2, 0 2,8 2))') + self.assertTrue(val.asWkt(), 'MultiPoint((4 2, 2 2, 3 2, 2 2,5 2, 0 2,8 2))') # try a bad expression val, ok = agg.calculate(QgsAggregateCalculator.Max, "not_a_field || ' oranges'") diff --git a/tests/src/python/test_qgscomposition.py b/tests/src/python/test_qgscomposition.py index 3418be2263c8..e40b4b4b33e2 100644 --- a/tests/src/python/test_qgscomposition.py +++ b/tests/src/python/test_qgscomposition.py @@ -23,7 +23,8 @@ QgsPointXY, QgsRasterLayer, QgsMultiBandColorRenderer, - QgsProject) + QgsProject, + QgsCoordinateFormatter) from qgis.testing import start_app, unittest from qgis.testing.mocked import get_iface @@ -49,7 +50,7 @@ def testSubstitutionMap(self): """ # Create a point and convert it to text containing a degree symbol. myPoint = QgsPointXY(12.3, -33.33) - myCoordinates = myPoint.toDegreesMinutesSeconds(2) + myCoordinates = QgsCoordinateFormatter.format(myPoint, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2) myTokens = myCoordinates.split(',') myLongitude = myTokens[0] myLatitude = myTokens[1] diff --git a/tests/src/python/test_qgscoordinateformatter.py b/tests/src/python/test_qgscoordinateformatter.py new file mode 100644 index 000000000000..5696e457c64c --- /dev/null +++ b/tests/src/python/test_qgscoordinateformatter.py @@ -0,0 +1,353 @@ +# -*- coding: utf-8 -*- +"""QGIS Unit tests for QgsCoordinateFormatter. + +.. note:: This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. +""" +__author__ = 'Nyall Dawson' +__date__ = '25/07/2014' +__copyright__ = 'Copyright 2015, The QGIS Project' +# This will get replaced with a git SHA1 when you do a git archive +__revision__ = '$Format:%H$' + +import qgis +from qgis.testing import unittest +from qgis.core import QgsCoordinateFormatter + + +class TestQgsCoordinateFormatter(unittest.TestCase): + + def testFormatXPair(self): + """Test formatting x as pair""" + + self.assertEqual(QgsCoordinateFormatter.formatX(20, QgsCoordinateFormatter.FormatPair, 0), '20') + self.assertEqual(QgsCoordinateFormatter.formatX(-20, QgsCoordinateFormatter.FormatPair, 0), '-20') + self.assertEqual(QgsCoordinateFormatter.formatX(20.11111111111111111, QgsCoordinateFormatter.FormatPair, 3), '20.111') + self.assertEqual(QgsCoordinateFormatter.formatX(20.11161111111111111, QgsCoordinateFormatter.FormatPair, 3), '20.112') + self.assertEqual(QgsCoordinateFormatter.formatX(20, QgsCoordinateFormatter.FormatPair, 3), '20.000') + self.assertEqual(QgsCoordinateFormatter.formatX(float('inf'), QgsCoordinateFormatter.FormatPair, 3), 'infinite') + + def testFormatYPair(self): + """Test formatting y as pair""" + + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatPair, 0), '20') + self.assertEqual(QgsCoordinateFormatter.formatY(-20, QgsCoordinateFormatter.FormatPair, 0), '-20') + self.assertEqual(QgsCoordinateFormatter.formatY(20.11111111111111111, QgsCoordinateFormatter.FormatPair, 3), '20.111') + self.assertEqual(QgsCoordinateFormatter.formatY(20.11161111111111111, QgsCoordinateFormatter.FormatPair, 3), '20.112') + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatPair, 3), '20.000') + self.assertEqual(QgsCoordinateFormatter.formatY(float('inf'), QgsCoordinateFormatter.FormatPair, 3), 'infinite') + + def testAsPair(self): + """Test formatting x/y as pair""" + self.assertEqual(QgsCoordinateFormatter.asPair(20, 30, 0), '20,30') + self.assertEqual(QgsCoordinateFormatter.asPair(20, -30, 0), '20,-30') + self.assertEqual(QgsCoordinateFormatter.asPair(20.111, 10.999, 0), '20,11') + self.assertEqual(QgsCoordinateFormatter.asPair(20.111, 10.999, 2), '20.11,11.00') + self.assertEqual(QgsCoordinateFormatter.asPair(20, 10, 2), '20.00,10.00') + self.assertEqual(QgsCoordinateFormatter.asPair(20, -10, 2), '20.00,-10.00') + + def testFormatXFormatDegreesMinutesSeconds(self): + """Test formatting x as DMS""" + + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"80°0′0.00″E") + + # check precision + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 4), u"80°0′0.0000″E") + self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 4), u"80°7′24.4444″E") + self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 0), u"80°7′24″E") + + # check if longitudes > 180 or <-180 wrap around + self.assertEqual(QgsCoordinateFormatter.formatX(370, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"10°0′0.00″E") + self.assertEqual(QgsCoordinateFormatter.formatX(-370, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"10°0′0.00″W") + self.assertEqual(QgsCoordinateFormatter.formatX(181, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"179°0′0.00″W") + self.assertEqual(QgsCoordinateFormatter.formatX(-181, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"179°0′0.00″E") + self.assertEqual(QgsCoordinateFormatter.formatX(359, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"1°0′0.00″W") + self.assertEqual(QgsCoordinateFormatter.formatX(-359, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"1°0′0.00″E") + + # should be no directional suffixes for 0 degree coordinates + self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″") + # should also be no directional suffix for 0 degree coordinates within specified precision + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″") + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"0°0′0.00360″W") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"0°0′0.00360″E") + + # should be no directional suffixes for 180 degree longitudes + self.assertEqual(QgsCoordinateFormatter.formatX(180, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"180°0′0.00″") + self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"180°0′0.00″") + self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"179°59′59.99640″E") + self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"180°0′0.00″") + self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"179°59′59.99640″W") + + # test rounding does not create seconds >= 60 + self.assertEqual(QgsCoordinateFormatter.formatX(99.999999, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"100°0′0.00″E") + self.assertEqual(QgsCoordinateFormatter.formatX(89.999999, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"90°0′0.00″E") + + # test without direction suffix + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"80°0′0.00″") + + # test 0 longitude + self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″") + # test near zero longitude + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″") + # should be no "-" prefix for near-zero longitude when rounding to 2 decimal places + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00360″") + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0′0.00360″") + + # test with padding + padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter.FlagDegreesUseStringSuffix) + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"80°00′00.00″E") + self.assertEqual(QgsCoordinateFormatter.formatX(85.44, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"85°26′24.00″E") + self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″") + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″") + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″W") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″E") + + def testFormatYFormatDegreesMinutesSeconds(self): + """Test formatting y as DMS""" + + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"20°0′0.00″N") + + # check precision + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 4), u"20°0′0.0000″N") + self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 4), u"20°7′24.4444″N") + self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 0), u"20°7′24″N") + + # check if latitudes > 90 or <-90 wrap around + self.assertEqual(QgsCoordinateFormatter.formatY(190, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"10°0′0.00″N") + self.assertEqual(QgsCoordinateFormatter.formatY(-190, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"10°0′0.00″S") + self.assertEqual(QgsCoordinateFormatter.formatY(91, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"89°0′0.00″S") + self.assertEqual(QgsCoordinateFormatter.formatY(-91, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"89°0′0.00″N") + self.assertEqual(QgsCoordinateFormatter.formatY(179, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"1°0′0.00″S") + self.assertEqual(QgsCoordinateFormatter.formatY(-179, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"1°0′0.00″N") + + # should be no directional suffixes for 0 degree coordinates + self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″") + # should also be no directional suffix for 0 degree coordinates within specified precision + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″") + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"0°0′0.00360″N") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"0°0′0.00360″S") + + # test rounding does not create seconds >= 60 + self.assertEqual(QgsCoordinateFormatter.formatY(89.999999, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"90°0′0.00″N") + + # test without direction suffix + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"20°0′0.00″") + + # test 0 latitude + self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″") + # test near zero lat/long + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″") + # should be no "-" prefix for near-zero latitude when rounding to 2 decimal places + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″") + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00360″") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0′0.00360″") + + # test with padding + padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter.FlagDegreesUseStringSuffix) + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"20°00′00.00″N") + self.assertEqual(QgsCoordinateFormatter.formatY(85.44, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"85°26′24.00″N") + self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″") + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″S") + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″N") + + def testFormatXDegreesMinutes(self): + """Test formatting x as DM""" + + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"80°0.00′E") + + # check precision + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutes, 4), u"80°0.0000′E") + self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDegreesMinutes, 4), u"80°7.4074′E") + self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDegreesMinutes, 0), u"80°7′E") + + # check if longitudes > 180 or <-180 wrap around + self.assertEqual(QgsCoordinateFormatter.formatX(370, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"10°0.00′E") + self.assertEqual(QgsCoordinateFormatter.formatX(-370, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"10°0.00′W") + self.assertEqual(QgsCoordinateFormatter.formatX(181, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"179°0.00′W") + self.assertEqual(QgsCoordinateFormatter.formatX(-181, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"179°0.00′E") + self.assertEqual(QgsCoordinateFormatter.formatX(359, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"1°0.00′W") + self.assertEqual(QgsCoordinateFormatter.formatX(-359, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"1°0.00′E") + + # should be no directional suffixes for 0 degree coordinates + self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′") + # should also be no directional suffix for 0 degree coordinates within specified precision + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′") + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"0°0.00006′W") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"0°0.00006′E") + + # test rounding does not create minutes >= 60 + self.assertEqual(QgsCoordinateFormatter.formatX(99.999999, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"100°0.00′E") + + # should be no directional suffixes for 180 degree longitudes + self.assertEqual(QgsCoordinateFormatter.formatX(180, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"180°0.00′") + + # should also be no directional suffix for 180 degree longitudes within specified precision + self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"180°0.00′") + self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"180°0.00′") + self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"179°59.99994′W") + self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"179°59.99994′E") + + # test without direction suffix + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"80°0.00′") + # test 0 longitude + self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′") + # test near zero longitude + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′") + # should be no "-" prefix for near-zero longitude when rounding to 2 decimal places + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0.00006′") + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0.00006′") + + # test with padding + padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter.FlagDegreesUseStringSuffix) + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"80°00.00′E") + self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′") + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′") + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, padding_and_suffix), u"0°00.00006′W") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, padding_and_suffix), u"0°00.00006′E") + + def testFormatYDegreesMinutes(self): + """Test formatting y as DM""" + + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"20°0.00′N") + + # check precision + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutes, 4), u"20°0.0000′N") + self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDegreesMinutes, 4), u"20°7.4074′N") + self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDegreesMinutes, 0), u"20°7′N") + + # check if latitudes > 90 or <-90 wrap around + self.assertEqual(QgsCoordinateFormatter.formatY(190, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"10°0.00′N") + self.assertEqual(QgsCoordinateFormatter.formatY(-190, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"10°0.00′S") + self.assertEqual(QgsCoordinateFormatter.formatY(91, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"89°0.00′S") + self.assertEqual(QgsCoordinateFormatter.formatY(-91, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"89°0.00′N") + self.assertEqual(QgsCoordinateFormatter.formatY(179, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"1°0.00′S") + self.assertEqual(QgsCoordinateFormatter.formatY(-179, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"1°0.00′N") + + # should be no directional suffixes for 0 degree coordinates + self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′") + # should also be no directional suffix for 0 degree coordinates within specified precision + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′") + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"0°0.00006′S") + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"0°0.00006′N") + + # test rounding does not create minutes >= 60 + self.assertEqual(QgsCoordinateFormatter.formatY(79.999999, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"80°0.00′N") + + # test without direction suffix + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"20°0.00′") + # test 0 latitude + self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′") + # test near zero latitude + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′") + # should be no "-" prefix for near-zero latitude when rounding to 2 decimal places + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′") + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0.00006′") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0.00006′") + + # test with padding + padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter.FlagDegreesUseStringSuffix) + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"20°00.00′N") + self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′") + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, padding_and_suffix), u"0°00.00006′S") + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, padding_and_suffix), u"0°00.00006′N") + + def testFormatXDegrees(self): + """Test formatting x as decimal degrees""" + + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"80.00°E") + + # check precision + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDecimalDegrees, 4), u"80.0000°E") + self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDecimalDegrees, 4), u"80.1235°E") + self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDecimalDegrees, 0), u"80°E") + + # check if longitudes > 180 or <-180 wrap around + self.assertEqual(QgsCoordinateFormatter.formatX(370, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"10.00°E") + self.assertEqual(QgsCoordinateFormatter.formatX(-370, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"10.00°W") + self.assertEqual(QgsCoordinateFormatter.formatX(181, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"179.00°W") + self.assertEqual(QgsCoordinateFormatter.formatX(-181, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"179.00°E") + self.assertEqual(QgsCoordinateFormatter.formatX(359, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"1.00°W") + self.assertEqual(QgsCoordinateFormatter.formatX(-359, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"1.00°E") + + # should be no directional suffixes for 0 degree coordinates + self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°") + # should also be no directional suffix for 0 degree coordinates within specified precision + self.assertEqual(QgsCoordinateFormatter.formatX(-0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°") + self.assertEqual(QgsCoordinateFormatter.formatX(0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°") + self.assertEqual(QgsCoordinateFormatter.formatX(-0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 5), u"0.00001°W") + self.assertEqual(QgsCoordinateFormatter.formatX(0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 5), u"0.00001°E") + + # should be no directional suffixes for 180 degree longitudes + self.assertEqual(QgsCoordinateFormatter.formatX(180, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"180.00°") + + # should also be no directional suffix for 180 degree longitudes within specified precision + self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"180.00°") + self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"180.00°") + self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 6), u"179.999999°W") + self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDecimalDegrees, 6), u"179.999999°E") + + # test without direction suffix + self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"80.00°") + # test 0 longitude + self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°") + # test near zero longitude + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°") + # should be no "-" prefix for near-zero longitude when rounding to 2 decimal places + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°") + self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"0.000001°") + self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"-0.000001°") + + def testFormatYDegrees(self): + """Test formatting y as decimal degrees""" + + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"20.00°N") + + # check precision + self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDecimalDegrees, 4), u"20.0000°N") + self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDecimalDegrees, 4), u"20.1235°N") + self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDecimalDegrees, 0), u"20°N") + + # check if latitudes > 90 or <-90 wrap around + self.assertEqual(QgsCoordinateFormatter.formatY(190, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"10.00°N") + self.assertEqual(QgsCoordinateFormatter.formatY(-190, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"10.00°S") + self.assertEqual(QgsCoordinateFormatter.formatY(91, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"89.00°S") + self.assertEqual(QgsCoordinateFormatter.formatY(-91, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"89.00°N") + self.assertEqual(QgsCoordinateFormatter.formatY(179, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"1.00°S") + self.assertEqual(QgsCoordinateFormatter.formatY(-179, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"1.00°N") + + # should be no directional suffixes for 0 degree coordinates + self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°") + # should also be no directional suffix for 0 degree coordinates within specified precision + self.assertEqual(QgsCoordinateFormatter.formatY(-0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°") + self.assertEqual(QgsCoordinateFormatter.formatY(0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 5), u"0.00001°S") + self.assertEqual(QgsCoordinateFormatter.formatY(0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 5), u"0.00001°N") + + # test without direction suffix + self.assertEqual(QgsCoordinateFormatter.formatY(80, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"80.00°") + # test 0 longitude + self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°") + # test near zero latitude + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°") + # should be no "-" prefix for near-zero latitude when rounding to 2 decimal places + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°") + self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"0.000001°") + self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"-0.000001°") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/src/python/test_qgsdelimitedtextprovider.py b/tests/src/python/test_qgsdelimitedtextprovider.py index 5aebb65cfb24..6f93151e6ebd 100644 --- a/tests/src/python/test_qgsdelimitedtextprovider.py +++ b/tests/src/python/test_qgsdelimitedtextprovider.py @@ -237,7 +237,7 @@ def layerData(self, layer, request={}, offset=0): fielddata = dict((name, str(f[name])) for name in fields) g = f.geometry() if not g.isNull(): - fielddata[geomkey] = str(g.exportToWkt()) + fielddata[geomkey] = str(g.asWkt()) else: fielddata[geomkey] = "None" diff --git a/tests/src/python/test_qgsdistancearea.py b/tests/src/python/test_qgsdistancearea.py index 29040ea91b45..eac1e54c14ea 100644 --- a/tests/src/python/test_qgsdistancearea.py +++ b/tests/src/python/test_qgsdistancearea.py @@ -175,13 +175,13 @@ def testMeasureLineProjectedWorldPoints(self): point_meter_result = QgsPointXY(0, 0) length_meter_mapunits, point_meter_result = da_3068.measureLineProjected(point_berlin_3068, 1.0, (math.pi / 2)) pprint(point_meter_result) - print('-I-> Berlin 3068 length_meter_mapunits[{}] point_meter_result[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_3068.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Berlin 3068 length_meter_mapunits[{}] point_meter_result[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_3068.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 1, da_3068.lengthUnits(), True), '1.0 m') self.assertEqual(point_meter_result.toString(7), point_berlin_3068_project.toString(7)) point_berlin_wsg84 = QgsPointXY(13.37770458660236, 52.51627178856762) point_berlin_wsg84_project = QgsPointXY(13.37771931736259, 52.51627178856669) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_berlin_wsg84, 1.0, (math.pi / 2)) - print('-I-> Berlin Wsg84 length_meter_mapunits[{}] point_meter_result[{}] ellipsoid[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 20, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText(), da_wsg84.ellipsoid())) + print('-I-> Berlin Wsg84 length_meter_mapunits[{}] point_meter_result[{}] ellipsoid[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 20, da_wsg84.lengthUnits(), True), point_meter_result.asWkt(), da_wsg84.ellipsoid())) # for unknown reasons, this is returning '0.00001473026 m' instead of '0.00001473026 deg' when using da_wsg84.lengthUnits() # self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits,11,da_wsg84.lengthUnits(),True), '0.00001473026 deg') self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 11, QgsUnitTypes.DistanceDegrees, True), '0.00001473026 deg') @@ -189,191 +189,191 @@ def testMeasureLineProjectedWorldPoints(self): point_berlin_4314 = QgsPointXY(13.37944343021465, 52.51767872437083) point_berlin_4314_project = QgsPointXY(13.37945816324759, 52.5176787243699) length_meter_mapunits, point_meter_result = da_4314.measureLineProjected(point_berlin_4314, 1.0, (math.pi / 2)) - print('-I-> Berlin 4314 length_meter_mapunits[{}] point_meter_result[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_4314.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Berlin 4314 length_meter_mapunits[{}] point_meter_result[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_4314.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 9, QgsUnitTypes.DistanceDegrees, True), '0.000014733 deg') self.assertEqual(point_meter_result.toString(7), point_berlin_4314_project.toString(7)) point_berlin_4805 = QgsPointXY(31.04960570069176, 52.5174657497405) point_berlin_4805_project = QgsPointXY(31.04962043365347, 52.51746574973957) length_meter_mapunits, point_meter_result = da_4805.measureLineProjected(point_berlin_4805, 1.0, (math.pi / 2)) - print('-I-> Berlin 4805 length_meter_mapunits[{}] point_meter_result[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_4805.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Berlin 4805 length_meter_mapunits[{}] point_meter_result[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_4805.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 9, QgsUnitTypes.DistanceDegrees, True), '0.000014733 deg') self.assertEqual(point_meter_result.toString(7), point_berlin_4805_project.toString(7)) point_berlin_25833 = QgsPointXY(389918.0748318382, 5819698.772194743) point_berlin_25833_project = point_berlin_25833.project(1, (math.pi / 2)) length_meter_mapunits, point_meter_result = da_25833.measureLineProjected(point_berlin_25833, 1.0, (math.pi / 2)) - print('-I-> Berlin 25833 length_meter_mapunits[{}] point_meter_result[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_25833.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Berlin 25833 length_meter_mapunits[{}] point_meter_result[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_25833.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_25833.lengthUnits(), True), '1.0000000 m') self.assertEqual(point_meter_result.toString(7), point_berlin_25833_project.toString(7)) if da_5665.sourceCrs().authid() != "": point_berlin_5665 = QgsPointXY(3389996.871728864, 5822169.719727578) point_berlin_5665_project = point_berlin_5665.project(1, (math.pi / 2)) length_meter_mapunits, point_meter_result = da_5665.measureLineProjected(point_berlin_5665, 1.0, (math.pi / 2)) - print('-I-> Berlin 5665 length_meter_mapunits[{}] point_meter_result[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_5665.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Berlin 5665 length_meter_mapunits[{}] point_meter_result[{}]'.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_5665.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 1.0, da_5665.lengthUnits(), True), '1.0 m') self.assertEqual(point_meter_result.toString(7), point_berlin_5665_project.toString(7)) print('\n12 points ''above over'' and on the Equator') point_wsg84 = QgsPointXY(25.7844, 71.1725) point_wsg84_project = QgsPointXY(25.78442775215388, 71.17249999999795) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Nordkap, Norway - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Nordkap, Norway - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, QgsUnitTypes.DistanceDegrees, True), '0.0000278 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(24.95995, 60.16841) point_wsg84_project = QgsPointXY(24.95996801277454, 60.16840999999877) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Helsinki, Finnland - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Helsinki, Finnland - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001801 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(12.599278, 55.692861) point_wsg84_project = QgsPointXY(12.59929390161872, 55.69286099999897) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Copenhagen, Denmark - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Copenhagen, Denmark - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001590 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-0.001389, 51.477778) point_wsg84_project = QgsPointXY(-0.001374606184398, 51.4777779999991) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Royal Greenwich Observatory, United Kingdom - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Royal Greenwich Observatory, United Kingdom - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001439 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(7.58769, 47.55814) point_wsg84_project = QgsPointXY(7.587703287209086, 47.55813999999922) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Basel, Switzerland - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Basel, Switzerland - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001329 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(11.255278, 43.775278) point_wsg84_project = QgsPointXY(11.25529042107924, 43.77527799999933) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Florenz, Italy - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Florenz, Italy - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001242 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(14.514722, 35.899722) point_wsg84_project = QgsPointXY(14.51473307693308, 35.89972199999949) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Valletta, Malta - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Valletta, Malta - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001108 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-79.933333, 32.783333) point_wsg84_project = QgsPointXY(-79.93332232547254, 32.78333299999955) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Charlston, South Carolina - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Charlston, South Carolina - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001067 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-17.6666666, 27.733333) point_wsg84_project = QgsPointXY(-17.66665645831515, 27.73333299999962) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Ferro, Spain - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Ferro, Spain - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001014 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-99.133333, 19.433333) point_wsg84_project = QgsPointXY(-99.1333234776827, 19.43333299999975) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Mexico City, Mexico - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Mexico City, Mexico - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00000952 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-79.894444, 9.341667) point_wsg84_project = QgsPointXY(-79.89443489691369, 9.341666999999882) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Colón, Panama - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Colón, Panama - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00000910 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-74.075833, 4.598056) point_wsg84_project = QgsPointXY(-74.07582398803629, 4.598055999999943) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Bogotá, Colombia - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Bogotá, Colombia - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00000901 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(0, 0) point_wsg84_project = QgsPointXY(0.000008983152841, 0) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Equator, Atlantic Ocean - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Equator, Atlantic Ocean - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00000898 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) print('\n12 points ''down under'' and 1 point that should be considered invalid') point_wsg84 = QgsPointXY(-78.509722, -0.218611) point_wsg84_project = QgsPointXY(-78.50971301678221, -0.218610999999997) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Quito, Ecuador - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Quito, Ecuador - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00000898 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(106.816667, -6.2) point_wsg84_project = QgsPointXY(106.8166760356519, -6.199999999999922) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Jakarta, Indonesia - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Jakarta, Indonesia - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00000904 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-77.018611, -12.035) point_wsg84_project = QgsPointXY(-77.01860181630058, -12.03499999999985) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Lima, Peru - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Lima, Peru - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00000918 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(25.466667, -10.716667) point_wsg84_project = QgsPointXY(25.46667614155322, -10.71666699999986) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Kolwezi, Congo - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Kolwezi, Congo - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00000914 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-70.333333, -18.483333) point_wsg84_project = QgsPointXY(-70.3333235314429, -18.48333299999976) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Arica, Chile - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Arica, Chile - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00000947 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-70.666667, -33.45) point_wsg84_project = QgsPointXY(-70.66665624452817, -33.44999999999953) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Santiago, Chile - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Santiago, Chile - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001076 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(144.9604, -37.8191) point_wsg84_project = QgsPointXY(144.96041135746983741, -37.81909999999945171) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Melbourne, Australia - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Melbourne, Australia - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001136 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(147.29, -42.88) point_wsg84_project = QgsPointXY(147.2900122399815, -42.87999999999934) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Hobart City,Tasmania, Australia - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Hobart City,Tasmania, Australia - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001224 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(168.101667, -46.899722) point_wsg84_project = QgsPointXY(168.101680123673, -46.89972199999923) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Ryan''s Creek Aerodrome, New Zealand - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Ryan''s Creek Aerodrome, New Zealand - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001312 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-69.216667, -51.633333) point_wsg84_project = QgsPointXY(-69.21665255700216, -51.6333329999991) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Río Gallegos, Argentina - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Río Gallegos, Argentina - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001444 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-68.3, -54.8) point_wsg84_project = QgsPointXY(-68.29998445081456, -54.79999999999899) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Ushuaia, Tierra del Fuego, Argentina - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Ushuaia, Tierra del Fuego, Argentina - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00001555 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-63.494444, -64.825278) point_wsg84_project = QgsPointXY(-63.49442294002932, -64.82527799999851) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Port Lockroy, Antarctica - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Port Lockroy, Antarctica - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00002106 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-180, -84.863272250) point_wsg84_project = QgsPointXY(-179.9999000000025, -84.8632722499922) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-I-> Someware, Antarctica - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-I-> Someware, Antarctica - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00010000 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) point_wsg84 = QgsPointXY(-180, -85.0511300) point_wsg84_project = QgsPointXY(-179.9998962142197, -85.05112999999191) length_meter_mapunits, point_meter_result = da_wsg84.measureLineProjected(point_wsg84, 1.0, (math.pi / 2)) - print('-W-> Mercator''s Last Stop, Antarctica - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.wellKnownText())) + print('-W-> Mercator''s Last Stop, Antarctica - Wsg84 - length_meter_mapunits[{}] point_meter_result[{}] '.format(QgsDistanceArea.formatDistance(length_meter_mapunits, 7, da_wsg84.lengthUnits(), True), point_meter_result.asWkt())) self.assertEqual(QgsDistanceArea.formatDistance(length_meter_mapunits, 8, QgsUnitTypes.DistanceDegrees, True), '0.00010379 deg') self.assertEqual(point_meter_result.toString(7), point_wsg84_project.toString(7)) diff --git a/tests/src/python/test_qgsfeaturesource.py b/tests/src/python/test_qgsfeaturesource.py index 102c81fb6c63..4a3ef3a58949 100644 --- a/tests/src/python/test_qgsfeaturesource.py +++ b/tests/src/python/test_qgsfeaturesource.py @@ -107,7 +107,7 @@ def testMaterialize(self): new_features = {f[0]: f for f in new_layer.getFeatures()} for id, f in original_features.items(): self.assertEqual(new_features[id].attributes(), f.attributes()) - self.assertEqual(new_features[id].geometry().exportToWkt(), f.geometry().exportToWkt()) + self.assertEqual(new_features[id].geometry().asWkt(), f.geometry().asWkt()) # materialize with no geometry request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry) @@ -136,7 +136,7 @@ def testMaterialize(self): 5: 'Point (0 -0)'} for id, f in original_features.items(): self.assertEqual(new_features[id].attributes(), f.attributes()) - self.assertEqual(new_features[id].geometry().exportToWkt(0), expected_geometry[id]) + self.assertEqual(new_features[id].geometry().asWkt(0), expected_geometry[id]) # materialize with attribute subset request = QgsFeatureRequest().setSubsetOfAttributes([0, 2]) diff --git a/tests/src/python/test_qgsgeometry.py b/tests/src/python/test_qgsgeometry.py index 5de5df059505..e623d2be15e4 100644 --- a/tests/src/python/test_qgsgeometry.py +++ b/tests/src/python/test_qgsgeometry.py @@ -173,7 +173,7 @@ def testReferenceGeometry(self): continue # test exporting to WKT results in expected string - result = geom.exportToWkt() + result = geom.asWkt() exp = row['valid_wkt'] assert compareWkt(result, exp, 0.000001), "WKT conversion {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp, result) @@ -207,7 +207,7 @@ def testReferenceGeometry(self): # test geometry centroid exp = row['centroid'] - result = geom.centroid().exportToWkt() + result = geom.centroid().asWkt() assert compareWkt(result, exp, 0.00001), "Centroid {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp, result) # test bounding box limits @@ -377,7 +377,7 @@ def testSimplifyIssue4189(self): myStartLength = len(myWKT) myTolerance = 0.00001 mySimpleGeometry = myGeometry.simplify(myTolerance) - myEndLength = len(mySimpleGeometry.exportToWkt()) + myEndLength = len(mySimpleGeometry.asWkt()) myMessage = 'Before simplify: %i\nAfter simplify: %i\n : Tolerance %e' % ( myStartLength, myEndLength, myTolerance) myMinimumLength = len('Polygon(())') @@ -434,7 +434,7 @@ def testClipping(self): QgsPointXY(30, 20), QgsPointXY(20, 20), ]]) - print(('Clip: %s' % myClipPolygon.exportToWkt())) + print(('Clip: %s' % myClipPolygon.asWkt())) writeShape(myMemoryLayer, 'clipGeometryBefore.shp') fit = myProvider.getFeatures() myFeatures = [] @@ -450,17 +450,17 @@ def testClipping(self): # Gives you areas outside the clip area # myDifferenceGeometry = myCombinedGeometry.difference( # myClipPolygon) - # print 'Original: %s' % myGeometry.exportToWkt() - # print 'Combined: %s' % myCombinedGeometry.exportToWkt() - # print 'Difference: %s' % myDifferenceGeometry.exportToWkt() - print(('Symmetrical: %s' % mySymmetricalGeometry.exportToWkt())) + # print 'Original: %s' % myGeometry.asWkt() + # print 'Combined: %s' % myCombinedGeometry.asWkt() + # print 'Difference: %s' % myDifferenceGeometry.asWkt() + print(('Symmetrical: %s' % mySymmetricalGeometry.asWkt())) myExpectedWkt = 'Polygon ((20 20, 20 30, 30 30, 30 20, 20 20))' # There should only be one feature that intersects this clip # poly so this assertion should work. assert compareWkt(myExpectedWkt, - mySymmetricalGeometry.exportToWkt()) + mySymmetricalGeometry.asWkt()) myNewFeature = QgsFeature() myNewFeature.setAttributes(myFeature.attributes()) @@ -888,17 +888,17 @@ def testMultipoint(self): assert multipoint.insertVertex(4, 4, 0), "MULTIPOINT insert 4,4 at 0 failed" expwkt = "MultiPoint ((4 4),(5 5))" - wkt = multipoint.exportToWkt() + wkt = multipoint.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert multipoint.insertVertex(7, 7, 2), "MULTIPOINT append 7,7 at 2 failed" expwkt = "MultiPoint ((4 4),(5 5),(7 7))" - wkt = multipoint.exportToWkt() + wkt = multipoint.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert multipoint.insertVertex(6, 6, 2), "MULTIPOINT append 6,6 at 2 failed" expwkt = "MultiPoint ((4 4),(5 5),(6 6),(7 7))" - wkt = multipoint.exportToWkt() + wkt = multipoint.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert not multipoint.deleteVertex(4), "MULTIPOINT delete at 4 unexpectedly succeeded" @@ -906,17 +906,17 @@ def testMultipoint(self): assert multipoint.deleteVertex(1), "MULTIPOINT delete at 1 failed" expwkt = "MultiPoint ((4 4),(6 6),(7 7))" - wkt = multipoint.exportToWkt() + wkt = multipoint.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert multipoint.deleteVertex(2), "MULTIPOINT delete at 2 failed" expwkt = "MultiPoint ((4 4),(6 6))" - wkt = multipoint.exportToWkt() + wkt = multipoint.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert multipoint.deleteVertex(0), "MULTIPOINT delete at 2 failed" expwkt = "MultiPoint ((6 6))" - wkt = multipoint.exportToWkt() + wkt = multipoint.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) multipoint = QgsGeometry.fromWkt("MultiPoint ((5 5))") @@ -933,7 +933,7 @@ def testMoveVertex(self): for i in range(0, 10): assert multipoint.moveVertex(i + 1, -1 - i, i), "move vertex %d failed" % i expwkt = "MultiPoint ((1 -1),(2 -2),(3 -3),(4 -4),(5 -5),(6 -6),(7 -7),(8 -8),(9 -9),(10 -10))" - wkt = multipoint.exportToWkt() + wkt = multipoint.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # 2-+-+-+-+-3 @@ -954,7 +954,7 @@ def testMoveVertex(self): assert polyline.moveVertex(5.5, 4.5, 3), "move vertex failed" expwkt = "LineString (5 0, 0 0, 0 4, 5.5 4.5, 5 1, 1 1, 1 3, 4 3, 4 2, 2 2)" - wkt = polyline.exportToWkt() + wkt = polyline.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # 5-+-4 @@ -970,17 +970,17 @@ def testMoveVertex(self): assert polygon.moveVertex(1, 2, 0), "move vertex failed" expwkt = "Polygon ((1 2, 1 0, 1 1, 2 1, 2 2, 0 2, 1 2))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert polygon.moveVertex(3, 4, 3), "move vertex failed" expwkt = "Polygon ((1 2, 1 0, 1 1, 3 4, 2 2, 0 2, 1 2))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert polygon.moveVertex(2, 3, 6), "move vertex failed" expwkt = "Polygon ((2 3, 1 0, 1 1, 3 4, 2 2, 0 2, 2 3))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # 5-+-4 0-+-9 @@ -996,17 +996,17 @@ def testMoveVertex(self): assert polygon.moveVertex(6, 2, 9), "move vertex failed" expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 6 2, 3 2, 3 1, 4 1, 4 0)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert polygon.moveVertex(1, 2, 0), "move vertex failed" expwkt = "MultiPolygon (((1 2, 1 0, 1 1, 2 1, 2 2, 0 2, 1 2)),((4 0, 5 0, 6 2, 3 2, 3 1, 4 1, 4 0)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert polygon.moveVertex(2, 1, 7), "move vertex failed" expwkt = "MultiPolygon (((1 2, 1 0, 1 1, 2 1, 2 2, 0 2, 1 2)),((2 1, 5 0, 6 2, 3 2, 3 1, 4 1, 2 1)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) def testDeleteVertex(self): @@ -1022,7 +1022,7 @@ def testDeleteVertex(self): polyline = QgsGeometry.fromWkt("LineString (5 0, 0 0, 0 4, 5 4, 5 1, 1 1, 1 3, 4 3, 4 2, 2 2)") assert polyline.deleteVertex(3), "Delete vertex 5 4 failed" expwkt = "LineString (5 0, 0 0, 0 4, 5 1, 1 1, 1 3, 4 3, 4 2, 2 2)" - wkt = polyline.exportToWkt() + wkt = polyline.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert not polyline.deleteVertex(-5), "Delete vertex -5 unexpectedly succeeded" @@ -1034,7 +1034,7 @@ def testDeleteVertex(self): polyline = QgsGeometry.fromWkt("MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0),(3 0, 3 1, 5 1, 5 0, 6 0))") assert polyline.deleteVertex(5), "Delete vertex 5 failed" expwkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0), (3 1, 5 1, 5 0, 6 0))" - wkt = polyline.exportToWkt() + wkt = polyline.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert not polyline.deleteVertex(-100), "Delete vertex -100 unexpectedly succeeded" @@ -1042,14 +1042,14 @@ def testDeleteVertex(self): assert polyline.deleteVertex(0), "Delete vertex 0 failed" expwkt = "MultiLineString ((1 0, 1 1, 2 1, 2 0), (3 1, 5 1, 5 0, 6 0))" - wkt = polyline.exportToWkt() + wkt = polyline.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) polyline = QgsGeometry.fromWkt("MultiLineString ((0 0, 1 0, 1 1, 2 1,2 0),(3 0, 3 1, 5 1, 5 0, 6 0))") for i in range(4): assert polyline.deleteVertex(5), "Delete vertex 5 failed" expwkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0))" - wkt = polyline.exportToWkt() + wkt = polyline.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # 5---4 @@ -1061,18 +1061,18 @@ def testDeleteVertex(self): assert polygon.deleteVertex(2), "Delete vertex 2 failed" expwkt = "Polygon ((0 0, 1 0, 2 1, 2 2, 0 2, 0 0))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert polygon.deleteVertex(0), "Delete vertex 0 failed" expwkt = "Polygon ((1 0, 2 1, 2 2, 0 2, 1 0))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert polygon.deleteVertex(4), "Delete vertex 4 failed" # "Polygon ((2 1, 2 2, 0 2, 2 1))" #several possibilities are correct here expwkt = "Polygon ((0 2, 2 1, 2 2, 0 2))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert not polygon.deleteVertex(-100), "Delete vertex -100 unexpectedly succeeded" @@ -1086,17 +1086,17 @@ def testDeleteVertex(self): polygon = QgsGeometry.fromWkt("MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))") assert polygon.deleteVertex(9), "Delete vertex 5 2 failed" expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 3 2, 3 1, 4 1, 4 0)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert polygon.deleteVertex(0), "Delete vertex 0 failed" expwkt = "MultiPolygon (((1 0, 1 1, 2 1, 2 2, 0 2, 1 0)),((4 0, 5 0, 3 2, 3 1, 4 1, 4 0)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert polygon.deleteVertex(6), "Delete vertex 6 failed" expwkt = "MultiPolygon (((1 0, 1 1, 2 1, 2 2, 0 2, 1 0)),((5 0, 3 2, 3 1, 4 1, 5 0)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) polygon = QgsGeometry.fromWkt("MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))") @@ -1104,7 +1104,7 @@ def testDeleteVertex(self): assert polygon.deleteVertex(0), "Delete vertex 0 failed" expwkt = "MultiPolygon (((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # 3-+-+-+-+-+-+-+-+-2 @@ -1121,7 +1121,7 @@ def testDeleteVertex(self): assert polygon.deleteVertex(16), "Delete vertex 16 failed" % i expwkt = "Polygon ((0 0, 9 0, 9 3, 0 3, 0 0),(1 1, 2 1, 2 2, 1 2, 1 1),(3 1, 4 1, 4 2, 3 2, 3 1),(7 1, 8 1, 8 2, 7 2, 7 1))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) for i in range(3): @@ -1129,7 +1129,7 @@ def testDeleteVertex(self): assert polygon.deleteVertex(5), "Delete vertex 5 failed" % i expwkt = "Polygon ((0 0, 9 0, 9 3, 0 3, 0 0))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # Remove whole outer ring, inner ring should become outer @@ -1138,7 +1138,7 @@ def testDeleteVertex(self): assert polygon.deleteVertex(0), "Delete vertex 16 failed" % i expwkt = "Polygon ((1 1, 2 1, 2 2, 1 2, 1 1))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) def testInsertVertex(self): @@ -1146,12 +1146,12 @@ def testInsertVertex(self): assert linestring.insertVertex(0, 0, 0), "Insert vertex 0 0 at 0 failed" expwkt = "LineString (0 0, 1 0, 2 0)" - wkt = linestring.exportToWkt() + wkt = linestring.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert linestring.insertVertex(1.5, 0, 2), "Insert vertex 1.5 0 at 2 failed" expwkt = "LineString (0 0, 1 0, 1.5 0, 2 0)" - wkt = linestring.exportToWkt() + wkt = linestring.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) assert not linestring.insertVertex(3, 0, 5), "Insert vertex 3 0 at 5 should have failed" @@ -1159,63 +1159,63 @@ def testInsertVertex(self): polygon = QgsGeometry.fromWkt("MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))") assert polygon.insertVertex(0, 0, 8), "Insert vertex 0 0 at 8 failed" expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 0 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) polygon = QgsGeometry.fromWkt("MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))") assert polygon.insertVertex(0, 0, 7), "Insert vertex 0 0 at 7 failed" expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((0 0, 4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 0 0)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) def testTranslate(self): point = QgsGeometry.fromWkt("Point (1 1)") self.assertEqual(point.translate(1, 2), 0, "Translate failed") expwkt = "Point (2 3)" - wkt = point.exportToWkt() + wkt = point.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) point = QgsGeometry.fromWkt("MultiPoint ((1 1),(2 2),(3 3))") self.assertEqual(point.translate(1, 2), 0, "Translate failed") expwkt = "MultiPoint ((2 3),(3 4),(4 5))" - wkt = point.exportToWkt() + wkt = point.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) linestring = QgsGeometry.fromWkt("LineString (1 0, 2 0)") self.assertEqual(linestring.translate(1, 2), 0, "Translate failed") expwkt = "LineString (2 2, 3 2)" - wkt = linestring.exportToWkt() + wkt = linestring.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) polygon = QgsGeometry.fromWkt("MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))") self.assertEqual(polygon.translate(1, 2), 0, "Translate failed") expwkt = "MultiPolygon (((1 2, 2 2, 2 3, 3 3, 3 4, 1 4, 1 2)),((5 2, 6 2, 6 2, 4 4, 4 3, 5 3, 5 2)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() ct = QgsCoordinateTransform() point = QgsGeometry.fromWkt("Point (1 1)") self.assertEqual(point.transform(ct), 0, "Translate failed") expwkt = "Point (1 1)" - wkt = point.exportToWkt() + wkt = point.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) point = QgsGeometry.fromWkt("MultiPoint ((1 1),(2 2),(3 3))") self.assertEqual(point.transform(ct), 0, "Translate failed") expwkt = "MultiPoint ((1 1),(2 2),(3 3))" - wkt = point.exportToWkt() + wkt = point.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) linestring = QgsGeometry.fromWkt("LineString (1 0, 2 0)") self.assertEqual(linestring.transform(ct), 0, "Translate failed") expwkt = "LineString (1 0, 2 0)" - wkt = linestring.exportToWkt() + wkt = linestring.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) polygon = QgsGeometry.fromWkt("MultiPolygon(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,5 2,3 2,3 1,4 1,4 0)))") self.assertEqual(polygon.transform(ct), 0, "Translate failed") expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() def testExtrude(self): # test with empty geometry @@ -1225,12 +1225,12 @@ def testExtrude(self): points = [QgsPointXY(1, 2), QgsPointXY(3, 2), QgsPointXY(4, 3)] line = QgsGeometry.fromPolylineXY(points) expected = QgsGeometry.fromWkt('Polygon ((1 2, 3 2, 4 3, 5 5, 4 4, 2 4, 1 2))') - self.assertEqual(line.extrude(1, 2).exportToWkt(), expected.exportToWkt()) + self.assertEqual(line.extrude(1, 2).asWkt(), expected.asWkt()) points2 = [[QgsPointXY(1, 2), QgsPointXY(3, 2)], [QgsPointXY(4, 3), QgsPointXY(8, 3)]] multiline = QgsGeometry.fromMultiPolylineXY(points2) expected = QgsGeometry.fromWkt('MultiPolygon (((1 2, 3 2, 4 4, 2 4, 1 2)),((4 3, 8 3, 9 5, 5 5, 4 3)))') - self.assertEqual(multiline.extrude(1, 2).exportToWkt(), expected.exportToWkt()) + self.assertEqual(multiline.extrude(1, 2).asWkt(), expected.asWkt()) def testNearestPoint(self): # test with empty geometries @@ -1243,24 +1243,24 @@ def testNearestPoint(self): g2 = QgsGeometry.fromWkt('Point( 6 3 )') expWkt = 'Point( 5 3 )' - wkt = g1.nearestPoint(g2).exportToWkt() + wkt = g1.nearestPoint(g2).asWkt() self.assertTrue(compareWkt(expWkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) expWkt = 'Point( 6 3 )' - wkt = g2.nearestPoint(g1).exportToWkt() + wkt = g2.nearestPoint(g1).asWkt() self.assertTrue(compareWkt(expWkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) g1 = QgsGeometry.fromWkt('Polygon ((1 1, 5 1, 5 5, 1 5, 1 1))') g2 = QgsGeometry.fromWkt('Point( 6 3 )') expWkt = 'Point( 5 3 )' - wkt = g1.nearestPoint(g2).exportToWkt() + wkt = g1.nearestPoint(g2).asWkt() self.assertTrue(compareWkt(expWkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) expWkt = 'Point( 6 3 )' - wkt = g2.nearestPoint(g1).exportToWkt() + wkt = g2.nearestPoint(g1).asWkt() self.assertTrue(compareWkt(expWkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) g2 = QgsGeometry.fromWkt('Point( 2 3 )') expWkt = 'Point( 2 3 )' - wkt = g1.nearestPoint(g2).exportToWkt() + wkt = g1.nearestPoint(g2).asWkt() self.assertTrue(compareWkt(expWkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) def testShortestLine(self): @@ -1274,24 +1274,24 @@ def testShortestLine(self): g2 = QgsGeometry.fromWkt('Point( 6 3 )') expWkt = 'LineString( 5 3, 6 3 )' - wkt = g1.shortestLine(g2).exportToWkt() + wkt = g1.shortestLine(g2).asWkt() self.assertTrue(compareWkt(expWkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) expWkt = 'LineString( 6 3, 5 3 )' - wkt = g2.shortestLine(g1).exportToWkt() + wkt = g2.shortestLine(g1).asWkt() self.assertTrue(compareWkt(expWkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) g1 = QgsGeometry.fromWkt('Polygon ((1 1, 5 1, 5 5, 1 5, 1 1))') g2 = QgsGeometry.fromWkt('Point( 6 3 )') expWkt = 'LineString( 5 3, 6 3 )' - wkt = g1.shortestLine(g2).exportToWkt() + wkt = g1.shortestLine(g2).asWkt() self.assertTrue(compareWkt(expWkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) expWkt = 'LineString( 6 3, 5 3 )' - wkt = g2.shortestLine(g1).exportToWkt() + wkt = g2.shortestLine(g1).asWkt() self.assertTrue(compareWkt(expWkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) g2 = QgsGeometry.fromWkt('Point( 2 3 )') expWkt = 'LineString( 2 3, 2 3 )' - wkt = g1.shortestLine(g2).exportToWkt() + wkt = g1.shortestLine(g2).asWkt() self.assertTrue(compareWkt(expWkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) def testBoundingBox(self): @@ -1376,7 +1376,7 @@ def testCollectGeometry(self): geometries = [QgsGeometry.fromPointXY(QgsPointXY(0, 0)), QgsGeometry.fromPointXY(QgsPointXY(1, 1))] geometry = QgsGeometry.collectGeometry(geometries) expwkt = "MultiPoint ((0 0), (1 1))" - wkt = geometry.exportToWkt() + wkt = geometry.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # collect lines @@ -1387,7 +1387,7 @@ def testCollectGeometry(self): geometries = [QgsGeometry.fromPolylineXY(points[0]), QgsGeometry.fromPolylineXY(points[1])] geometry = QgsGeometry.collectGeometry(geometries) expwkt = "MultiLineString ((0 0, 1 0), (2 0, 3 0))" - wkt = geometry.exportToWkt() + wkt = geometry.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # collect polygons @@ -1398,7 +1398,7 @@ def testCollectGeometry(self): geometries = [QgsGeometry.fromPolygonXY(points[0]), QgsGeometry.fromPolygonXY(points[1])] geometry = QgsGeometry.collectGeometry(geometries) expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 0 1, 0 0)),((2 0, 3 0, 3 1, 2 1, 2 0)))" - wkt = geometry.exportToWkt() + wkt = geometry.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # test empty list @@ -1417,7 +1417,7 @@ def testAddPart(self): point = QgsGeometry.fromPointXY(points[0]) self.assertEqual(point.addPointsXY([points[1]]), 0) expwkt = "MultiPoint ((0 0), (1 0))" - wkt = point.exportToWkt() + wkt = point.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # test adding a part with Z values @@ -1425,7 +1425,7 @@ def testAddPart(self): point.get().addZValue(4.0) self.assertEqual(point.addPoints([QgsPoint(points[1][0], points[1][1], 3.0, wkbType=QgsWkbTypes.PointZ)]), 0) expwkt = "MultiPointZ ((0 0 4), (1 0 3))" - wkt = point.exportToWkt() + wkt = point.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # 2-3 6-+-7 @@ -1440,13 +1440,13 @@ def testAddPart(self): self.assertEqual(polyline.addPointsXY(points[1][0:1]), QgsGeometry.InvalidInput, "addPoints with one point line unexpectedly succeeded.") self.assertEqual(polyline.addPointsXY(points[1][0:2]), QgsGeometry.Success, "addPoints with two point line failed.") expwkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1))" - wkt = polyline.exportToWkt() + wkt = polyline.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) polyline = QgsGeometry.fromPolylineXY(points[0]) self.assertEqual(polyline.addPointsXY(points[1]), QgsGeometry.Success, "addPoints with %d point line failed." % len(points[1])) expwkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1, 5 1, 5 0, 6 0))" - wkt = polyline.exportToWkt() + wkt = polyline.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # test adding a part with Z values @@ -1455,7 +1455,7 @@ def testAddPart(self): points2 = [QgsPoint(p[0], p[1], 3.0, wkbType=QgsWkbTypes.PointZ) for p in points[1]] self.assertEqual(polyline.addPoints(points2), QgsGeometry.Success) expwkt = "MultiLineStringZ ((0 0 4, 1 0 4, 1 1 4, 2 1 4, 2 0 4),(3 0 3, 3 1 3, 5 1 3, 5 0 3, 6 0 3))" - wkt = polyline.exportToWkt() + wkt = polyline.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # 5-+-4 0-+-9 @@ -1477,20 +1477,20 @@ def testAddPart(self): self.assertEqual(polygon.addPointsXY(points[1][0]), QgsGeometry.Success, "addPoints failed") expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) mp = QgsGeometry.fromMultiPolygonXY(points[:1]) p = QgsGeometry.fromPolygonXY(points[1]) self.assertEqual(mp.addPartGeometry(p), QgsGeometry.Success) - wkt = mp.exportToWkt() + wkt = mp.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) mp = QgsGeometry.fromMultiPolygonXY(points[:1]) mp2 = QgsGeometry.fromMultiPolygonXY(points[1:]) self.assertEqual(mp.addPartGeometry(mp2), QgsGeometry.Success) - wkt = mp.exportToWkt() + wkt = mp.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # test adding a part with Z values @@ -1499,7 +1499,7 @@ def testAddPart(self): points2 = [QgsPoint(pi[0], pi[1], 3.0, wkbType=QgsWkbTypes.PointZ) for pi in points[1][0]] self.assertEqual(polygon.addPoints(points2), QgsGeometry.Success) expwkt = "MultiPolygonZ (((0 0 4, 1 0 4, 1 1 4, 2 1 4, 2 2 4, 0 2 4, 0 0 4)),((4 0 3, 5 0 3, 5 2 3, 3 2 3, 3 1 3, 4 1 3, 4 0 3)))" - wkt = polygon.exportToWkt() + wkt = polygon.asWkt() assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # Test adding parts to empty geometry, should become first part @@ -1509,36 +1509,36 @@ def testAddPart(self): assert result != QgsGeometry.Success, 'Got return code {}'.format(result) result = empty.addPointsXY([QgsPointXY(4, 0)], QgsWkbTypes.PointGeometry) self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result)) - wkt = empty.exportToWkt() + wkt = empty.asWkt() expwkt = 'MultiPoint ((4 0))' assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) result = empty.addPointsXY([QgsPointXY(5, 1)]) self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result)) - wkt = empty.exportToWkt() + wkt = empty.asWkt() expwkt = 'MultiPoint ((4 0),(5 1))' assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # next try with lines empty = QgsGeometry() result = empty.addPointsXY(points[0][0], QgsWkbTypes.LineGeometry) self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result)) - wkt = empty.exportToWkt() + wkt = empty.asWkt() expwkt = 'MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))' assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) result = empty.addPointsXY(points[1][0]) self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result)) - wkt = empty.exportToWkt() + wkt = empty.asWkt() expwkt = 'MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0),(4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0))' assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) # finally try with polygons empty = QgsGeometry() result = empty.addPointsXY(points[0][0], QgsWkbTypes.PolygonGeometry) self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result)) - wkt = empty.exportToWkt() + wkt = empty.asWkt() expwkt = 'MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)))' assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) result = empty.addPointsXY(points[1][0]) self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result)) - wkt = empty.exportToWkt() + wkt = empty.asWkt() expwkt = 'MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))' assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt) @@ -1558,31 +1558,31 @@ def testConvertToType(self): # ####### TO POINT ######## # POINT TO POINT point = QgsGeometry.fromPointXY(QgsPointXY(1, 1)) - wkt = point.convertToType(QgsWkbTypes.PointGeometry, False).exportToWkt() + wkt = point.convertToType(QgsWkbTypes.PointGeometry, False).asWkt() expWkt = "Point (1 1)" assert compareWkt(expWkt, wkt), "convertToType failed: from point to point. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # POINT TO MultiPoint - wkt = point.convertToType(QgsWkbTypes.PointGeometry, True).exportToWkt() + wkt = point.convertToType(QgsWkbTypes.PointGeometry, True).asWkt() expWkt = "MultiPoint ((1 1))" assert compareWkt(expWkt, wkt), "convertToType failed: from point to multipoint. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # LINE TO MultiPoint line = QgsGeometry.fromPolylineXY(points[0][0]) - wkt = line.convertToType(QgsWkbTypes.PointGeometry, True).exportToWkt() + wkt = line.convertToType(QgsWkbTypes.PointGeometry, True).asWkt() expWkt = "MultiPoint ((0 0),(1 0),(1 1),(2 1),(2 2),(0 2),(0 0))" assert compareWkt(expWkt, wkt), "convertToType failed: from line to multipoint. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # MULTILINE TO MultiPoint multiLine = QgsGeometry.fromMultiPolylineXY(points[2]) - wkt = multiLine.convertToType(QgsWkbTypes.PointGeometry, True).exportToWkt() + wkt = multiLine.convertToType(QgsWkbTypes.PointGeometry, True).asWkt() expWkt = "MultiPoint ((10 0),(13 0),(13 3),(10 3),(10 0),(11 1),(12 1),(12 2),(11 2),(11 1))" assert compareWkt(expWkt, wkt), "convertToType failed: from multiline to multipoint. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # Polygon TO MultiPoint polygon = QgsGeometry.fromPolygonXY(points[0]) - wkt = polygon.convertToType(QgsWkbTypes.PointGeometry, True).exportToWkt() + wkt = polygon.convertToType(QgsWkbTypes.PointGeometry, True).asWkt() expWkt = "MultiPoint ((0 0),(1 0),(1 1),(2 1),(2 2),(0 2),(0 0))" assert compareWkt(expWkt, wkt), "convertToType failed: from poylgon to multipoint. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # MultiPolygon TO MultiPoint multiPolygon = QgsGeometry.fromMultiPolygonXY(points) - wkt = multiPolygon.convertToType(QgsWkbTypes.PointGeometry, True).exportToWkt() + wkt = multiPolygon.convertToType(QgsWkbTypes.PointGeometry, True).asWkt() expWkt = "MultiPoint ((0 0),(1 0),(1 1),(2 1),(2 2),(0 2),(0 0),(4 0),(5 0),(5 2),(3 2),(3 1),(4 1),(4 0),(10 0),(13 0),(13 3),(10 3),(10 0),(11 1),(12 1),(12 2),(11 2),(11 1))" assert compareWkt(expWkt, wkt), "convertToType failed: from multipoylgon to multipoint. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) @@ -1592,64 +1592,64 @@ def testConvertToType(self): self.assertFalse(point.convertToType(QgsWkbTypes.LineGeometry, False)), "convertToType with a point should return a null geometry" # MultiPoint TO LINE multipoint = QgsGeometry.fromMultiPointXY(points[0][0]) - wkt = multipoint.convertToType(QgsWkbTypes.LineGeometry, False).exportToWkt() + wkt = multipoint.convertToType(QgsWkbTypes.LineGeometry, False).asWkt() expWkt = "LineString (0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)" assert compareWkt(expWkt, wkt), "convertToType failed: from multipoint to line. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # MultiPoint TO MULTILINE multipoint = QgsGeometry.fromMultiPointXY(points[0][0]) - wkt = multipoint.convertToType(QgsWkbTypes.LineGeometry, True).exportToWkt() + wkt = multipoint.convertToType(QgsWkbTypes.LineGeometry, True).asWkt() expWkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))" assert compareWkt(expWkt, wkt), "convertToType failed: from multipoint to multiline. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # MULTILINE (which has a single part) TO LINE multiLine = QgsGeometry.fromMultiPolylineXY(points[0]) - wkt = multiLine.convertToType(QgsWkbTypes.LineGeometry, False).exportToWkt() + wkt = multiLine.convertToType(QgsWkbTypes.LineGeometry, False).asWkt() expWkt = "LineString (0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)" assert compareWkt(expWkt, wkt), "convertToType failed: from multiline to line. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # LINE TO MULTILINE line = QgsGeometry.fromPolylineXY(points[0][0]) - wkt = line.convertToType(QgsWkbTypes.LineGeometry, True).exportToWkt() + wkt = line.convertToType(QgsWkbTypes.LineGeometry, True).asWkt() expWkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))" assert compareWkt(expWkt, wkt), "convertToType failed: from line to multiline. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # Polygon TO LINE polygon = QgsGeometry.fromPolygonXY(points[0]) - wkt = polygon.convertToType(QgsWkbTypes.LineGeometry, False).exportToWkt() + wkt = polygon.convertToType(QgsWkbTypes.LineGeometry, False).asWkt() expWkt = "LineString (0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)" assert compareWkt(expWkt, wkt), "convertToType failed: from polygon to line. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # Polygon TO MULTILINE polygon = QgsGeometry.fromPolygonXY(points[0]) - wkt = polygon.convertToType(QgsWkbTypes.LineGeometry, True).exportToWkt() + wkt = polygon.convertToType(QgsWkbTypes.LineGeometry, True).asWkt() expWkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))" assert compareWkt(expWkt, wkt), "convertToType failed: from polygon to multiline. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # Polygon with ring TO MULTILINE polygon = QgsGeometry.fromPolygonXY(points[2]) - wkt = polygon.convertToType(QgsWkbTypes.LineGeometry, True).exportToWkt() + wkt = polygon.convertToType(QgsWkbTypes.LineGeometry, True).asWkt() expWkt = "MultiLineString ((10 0, 13 0, 13 3, 10 3, 10 0), (11 1, 12 1, 12 2, 11 2, 11 1))" assert compareWkt(expWkt, wkt), "convertToType failed: from polygon with ring to multiline. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # MultiPolygon (which has a single part) TO LINE multiPolygon = QgsGeometry.fromMultiPolygonXY([points[0]]) - wkt = multiPolygon.convertToType(QgsWkbTypes.LineGeometry, False).exportToWkt() + wkt = multiPolygon.convertToType(QgsWkbTypes.LineGeometry, False).asWkt() expWkt = "LineString (0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)" assert compareWkt(expWkt, wkt), "convertToType failed: from multipolygon to multiline. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # MultiPolygon TO MULTILINE multiPolygon = QgsGeometry.fromMultiPolygonXY(points) - wkt = multiPolygon.convertToType(QgsWkbTypes.LineGeometry, True).exportToWkt() + wkt = multiPolygon.convertToType(QgsWkbTypes.LineGeometry, True).asWkt() expWkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0), (4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0), (10 0, 13 0, 13 3, 10 3, 10 0), (11 1, 12 1, 12 2, 11 2, 11 1))" assert compareWkt(expWkt, wkt), "convertToType failed: from multipolygon to multiline. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # ####### TO Polygon ######## # MultiPoint TO Polygon multipoint = QgsGeometry.fromMultiPointXY(points[0][0]) - wkt = multipoint.convertToType(QgsWkbTypes.PolygonGeometry, False).exportToWkt() + wkt = multipoint.convertToType(QgsWkbTypes.PolygonGeometry, False).asWkt() expWkt = "Polygon ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))" assert compareWkt(expWkt, wkt), "convertToType failed: from multipoint to polygon. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # MultiPoint TO MultiPolygon multipoint = QgsGeometry.fromMultiPointXY(points[0][0]) - wkt = multipoint.convertToType(QgsWkbTypes.PolygonGeometry, True).exportToWkt() + wkt = multipoint.convertToType(QgsWkbTypes.PolygonGeometry, True).asWkt() expWkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)))" assert compareWkt(expWkt, wkt), "convertToType failed: from multipoint to multipolygon. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # LINE TO Polygon line = QgsGeometry.fromPolylineXY(points[0][0]) - wkt = line.convertToType(QgsWkbTypes.PolygonGeometry, False).exportToWkt() + wkt = line.convertToType(QgsWkbTypes.PolygonGeometry, False).asWkt() expWkt = "Polygon ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))" assert compareWkt(expWkt, wkt), "convertToType failed: from line to polygon. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # LINE ( 3 vertices, with first = last ) TO Polygon @@ -1660,27 +1660,27 @@ def testConvertToType(self): self.assertFalse(multiline.convertToType(QgsWkbTypes.PolygonGeometry, True), "convertToType to polygon of a 3 vertices lines with first and last vertex identical should return a null geometry") # LINE TO MultiPolygon line = QgsGeometry.fromPolylineXY(points[0][0]) - wkt = line.convertToType(QgsWkbTypes.PolygonGeometry, True).exportToWkt() + wkt = line.convertToType(QgsWkbTypes.PolygonGeometry, True).asWkt() expWkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)))" assert compareWkt(expWkt, wkt), "convertToType failed: from line to multipolygon. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # MULTILINE (which has a single part) TO Polygon multiLine = QgsGeometry.fromMultiPolylineXY(points[0]) - wkt = multiLine.convertToType(QgsWkbTypes.PolygonGeometry, False).exportToWkt() + wkt = multiLine.convertToType(QgsWkbTypes.PolygonGeometry, False).asWkt() expWkt = "Polygon ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))" assert compareWkt(expWkt, wkt), "convertToType failed: from multiline to polygon. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # MULTILINE TO MultiPolygon multiLine = QgsGeometry.fromMultiPolylineXY([points[0][0], points[1][0]]) - wkt = multiLine.convertToType(QgsWkbTypes.PolygonGeometry, True).exportToWkt() + wkt = multiLine.convertToType(QgsWkbTypes.PolygonGeometry, True).asWkt() expWkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))" assert compareWkt(expWkt, wkt), "convertToType failed: from multiline to multipolygon. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # Polygon TO MultiPolygon polygon = QgsGeometry.fromPolygonXY(points[0]) - wkt = polygon.convertToType(QgsWkbTypes.PolygonGeometry, True).exportToWkt() + wkt = polygon.convertToType(QgsWkbTypes.PolygonGeometry, True).asWkt() expWkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)))" assert compareWkt(expWkt, wkt), "convertToType failed: from polygon to multipolygon. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # MultiPolygon (which has a single part) TO Polygon multiPolygon = QgsGeometry.fromMultiPolygonXY([points[0]]) - wkt = multiPolygon.convertToType(QgsWkbTypes.PolygonGeometry, False).exportToWkt() + wkt = multiPolygon.convertToType(QgsWkbTypes.PolygonGeometry, False).asWkt() expWkt = "Polygon ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))" assert compareWkt(expWkt, wkt), "convertToType failed: from multiline to polygon. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) @@ -1690,7 +1690,7 @@ def testRegression13053(self): assert p is not None expWkt = 'MultiPolygon (((62 18, 62 19, 63 19, 63 18, 62 18)),((63 19, 63 20, 64 20, 64 19, 63 19)))' - wkt = p.exportToWkt() + wkt = p.asWkt() assert compareWkt(expWkt, wkt), "testRegression13053 failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) def testRegression13055(self): @@ -1702,7 +1702,7 @@ def testRegression13055(self): assert p is not None expWkt = 'PolygonZ ((0 0 0, 0 1 0, 1 1 0, 0 0 0 ))' - wkt = p.exportToWkt() + wkt = p.asWkt() assert compareWkt(expWkt, wkt), "testRegression13055 failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) def testRegression13274(self): @@ -1714,7 +1714,7 @@ def testRegression13274(self): c = a.combine(b) expWkt = 'LineString (0 0, 1 0, 2 0)' - wkt = c.exportToWkt() + wkt = c.asWkt() assert compareWkt(expWkt, wkt), "testRegression13274 failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) def testReshape(self): @@ -1722,14 +1722,14 @@ def testReshape(self): g = QgsGeometry.fromWkt('Polygon ((0 0, 1 0, 1 1, 0 1, 0 0))') g.reshapeGeometry(QgsLineString([QgsPoint(0, 1.5), QgsPoint(1.5, 0)])) expWkt = 'Polygon ((0.5 1, 0 1, 0 0, 1 0, 1 0.5, 0.5 1))' - wkt = g.exportToWkt() + wkt = g.asWkt() assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # Test reshape a geometry involving the first/last vertex (https://issues.qgis.org/issues/14443) g.reshapeGeometry(QgsLineString([QgsPoint(0.5, 1), QgsPoint(0, 0.5)])) expWkt = 'Polygon ((0 0.5, 0 0, 1 0, 1 0.5, 0.5 1, 0 0.5))' - wkt = g.exportToWkt() + wkt = g.asWkt() assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # Test reshape a line from first/last vertex @@ -1737,24 +1737,24 @@ def testReshape(self): # extend start self.assertEqual(g.reshapeGeometry(QgsLineString([QgsPoint(0, 0), QgsPoint(-1, 0)])), 0) expWkt = 'LineString (-1 0, 0 0, 5 0, 5 1)' - wkt = g.exportToWkt() + wkt = g.asWkt() assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # extend end self.assertEqual(g.reshapeGeometry(QgsLineString([QgsPoint(5, 1), QgsPoint(10, 1), QgsPoint(10, 2)])), 0) expWkt = 'LineString (-1 0, 0 0, 5 0, 5 1, 10 1, 10 2)' - wkt = g.exportToWkt() + wkt = g.asWkt() assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # test with reversed lines g = QgsGeometry.fromWkt('LineString (0 0, 5 0, 5 1)') # extend start self.assertEqual(g.reshapeGeometry(QgsLineString([QgsPoint(-1, 0), QgsPoint(0, 0)])), 0) expWkt = 'LineString (-1 0, 0 0, 5 0, 5 1)' - wkt = g.exportToWkt() + wkt = g.asWkt() assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # extend end self.assertEqual(g.reshapeGeometry(QgsLineString([QgsPoint(10, 2), QgsPoint(10, 1), QgsPoint(5, 1)])), 0) expWkt = 'LineString (-1 0, 0 0, 5 0, 5 1, 10 1, 10 2)' - wkt = g.exportToWkt() + wkt = g.asWkt() assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) def testConvertToMultiType(self): @@ -1762,7 +1762,7 @@ def testConvertToMultiType(self): point = QgsGeometry.fromWkt('Point (1 2)') assert point.convertToMultiType() expWkt = 'MultiPoint ((1 2))' - wkt = point.exportToWkt() + wkt = point.asWkt() assert compareWkt(expWkt, wkt), "testConvertToMultiType failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # test conversion of MultiPoint assert point.convertToMultiType() @@ -1771,7 +1771,7 @@ def testConvertToMultiType(self): line = QgsGeometry.fromWkt('LineString (1 0, 2 0)') assert line.convertToMultiType() expWkt = 'MultiLineString ((1 0, 2 0))' - wkt = line.exportToWkt() + wkt = line.asWkt() assert compareWkt(expWkt, wkt), "testConvertToMultiType failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # test conversion of MultiLineString assert line.convertToMultiType() @@ -1780,7 +1780,7 @@ def testConvertToMultiType(self): poly = QgsGeometry.fromWkt('Polygon ((1 0, 2 0, 2 1, 1 1, 1 0))') assert poly.convertToMultiType() expWkt = 'MultiPolygon (((1 0, 2 0, 2 1, 1 1, 1 0)))' - wkt = poly.exportToWkt() + wkt = poly.asWkt() assert compareWkt(expWkt, wkt), "testConvertToMultiType failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # test conversion of MultiPolygon assert poly.convertToMultiType() @@ -1791,7 +1791,7 @@ def testConvertToSingleType(self): point = QgsGeometry.fromWkt('MultiPoint ((1 2),(2 3))') assert point.convertToSingleType() expWkt = 'Point (1 2)' - wkt = point.exportToWkt() + wkt = point.asWkt() assert compareWkt(expWkt, wkt), "testConvertToSingleType failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # test conversion of Point assert point.convertToSingleType() @@ -1800,7 +1800,7 @@ def testConvertToSingleType(self): line = QgsGeometry.fromWkt('MultiLineString ((1 0, 2 0),(2 3, 4 5))') assert line.convertToSingleType() expWkt = 'LineString (1 0, 2 0)' - wkt = line.exportToWkt() + wkt = line.asWkt() assert compareWkt(expWkt, wkt), "testConvertToSingleType failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # test conversion of LineString assert line.convertToSingleType() @@ -1809,7 +1809,7 @@ def testConvertToSingleType(self): poly = QgsGeometry.fromWkt('MultiPolygon (((1 0, 2 0, 2 1, 1 1, 1 0)),((2 3,2 4, 3 4, 3 3, 2 3)))') assert poly.convertToSingleType() expWkt = 'Polygon ((1 0, 2 0, 2 1, 1 1, 1 0))' - wkt = poly.exportToWkt() + wkt = poly.asWkt() assert compareWkt(expWkt, wkt), "testConvertToSingleType failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # test conversion of Polygon assert poly.convertToSingleType() @@ -1823,7 +1823,7 @@ def testAddZValue(self): assert geom.constGet().addZValue(2) self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.CircularStringZ) expWkt = 'CircularStringZ (1 5 2, 6 2 2, 7 3 2)' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addZValue to CircularString failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # compound curve @@ -1831,7 +1831,7 @@ def testAddZValue(self): assert geom.constGet().addZValue(2) self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.CompoundCurveZ) expWkt = 'CompoundCurveZ ((5 3 2, 5 13 2),CircularStringZ (5 13 2, 7 15 2, 9 13 2),(9 13 2, 9 3 2),CircularStringZ (9 3 2, 7 1 2, 5 3 2))' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addZValue to CompoundCurve failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # curve polygon @@ -1840,7 +1840,7 @@ def testAddZValue(self): self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.PolygonZ) self.assertEqual(geom.wkbType(), QgsWkbTypes.PolygonZ) expWkt = 'PolygonZ ((0 0 3, 1 0 3, 1 1 3, 2 1 3, 2 2 3, 0 2 3, 0 0 3))' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addZValue to CurvePolygon failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # geometry collection @@ -1849,7 +1849,7 @@ def testAddZValue(self): self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.MultiPointZ) self.assertEqual(geom.wkbType(), QgsWkbTypes.MultiPointZ) expWkt = 'MultiPointZ ((1 2 4),(2 3 4))' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addZValue to GeometryCollection failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # LineString @@ -1858,7 +1858,7 @@ def testAddZValue(self): self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.LineStringZ) self.assertEqual(geom.wkbType(), QgsWkbTypes.LineStringZ) expWkt = 'LineStringZ (1 2 4, 2 3 4)' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addZValue to LineString failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # Point @@ -1867,7 +1867,7 @@ def testAddZValue(self): self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.PointZ) self.assertEqual(geom.wkbType(), QgsWkbTypes.PointZ) expWkt = 'PointZ (1 2 4)' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addZValue to Point failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) def testAddMValue(self): @@ -1878,7 +1878,7 @@ def testAddMValue(self): assert geom.constGet().addMValue(2) self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.CircularStringM) expWkt = 'CircularStringM (1 5 2, 6 2 2, 7 3 2)' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addMValue to CircularString failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # compound curve @@ -1886,7 +1886,7 @@ def testAddMValue(self): assert geom.constGet().addMValue(2) self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.CompoundCurveM) expWkt = 'CompoundCurveM ((5 3 2, 5 13 2),CircularStringM (5 13 2, 7 15 2, 9 13 2),(9 13 2, 9 3 2),CircularStringM (9 3 2, 7 1 2, 5 3 2))' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addMValue to CompoundCurve failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # curve polygon @@ -1894,7 +1894,7 @@ def testAddMValue(self): assert geom.constGet().addMValue(3) self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.PolygonM) expWkt = 'PolygonM ((0 0 3, 1 0 3, 1 1 3, 2 1 3, 2 2 3, 0 2 3, 0 0 3))' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addMValue to CurvePolygon failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # geometry collection @@ -1902,7 +1902,7 @@ def testAddMValue(self): assert geom.constGet().addMValue(4) self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.MultiPointM) expWkt = 'MultiPointM ((1 2 4),(2 3 4))' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addMValue to GeometryCollection failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # LineString @@ -1910,7 +1910,7 @@ def testAddMValue(self): assert geom.constGet().addMValue(4) self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.LineStringM) expWkt = 'LineStringM (1 2 4, 2 3 4)' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addMValue to LineString failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # Point @@ -1918,7 +1918,7 @@ def testAddMValue(self): assert geom.constGet().addMValue(4) self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.PointM) expWkt = 'PointM (1 2 4)' - wkt = geom.exportToWkt() + wkt = geom.asWkt() assert compareWkt(expWkt, wkt), "addMValue to Point failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) def testDistanceToVertex(self): @@ -3233,37 +3233,37 @@ def testDeleteVertexCircularString(self): wkt = "CircularString ((0 0,1 1,2 0))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(0) - self.assertEqual(geom.exportToWkt(), QgsCircularString().asWkt()) + self.assertEqual(geom.asWkt(), QgsCircularString().asWkt()) wkt = "CircularString ((0 0,1 1,2 0,3 -1,4 0))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(0) expected_wkt = "CircularString (2 0, 3 -1, 4 0)" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CircularString ((0 0,1 1,2 0,3 -1,4 0))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(1) expected_wkt = "CircularString (0 0, 3 -1, 4 0)" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CircularString ((0 0,1 1,2 0,3 -1,4 0))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(2) expected_wkt = "CircularString (0 0, 1 1, 4 0)" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CircularString ((0 0,1 1,2 0,3 -1,4 0))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(3) expected_wkt = "CircularString (0 0, 1 1, 4 0)" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CircularString ((0 0,1 1,2 0,3 -1,4 0))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(4) expected_wkt = "CircularString (0 0,1 1,2 0)" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CircularString ((0 0,1 1,2 0,3 -1,4 0))" geom = QgsGeometry.fromWkt(wkt) @@ -3277,60 +3277,60 @@ def testDeleteVertexCompoundCurve(self): assert not geom.deleteVertex(-1) assert not geom.deleteVertex(2) assert geom.deleteVertex(0) - self.assertEqual(geom.exportToWkt(), QgsCompoundCurve().asWkt()) + self.assertEqual(geom.asWkt(), QgsCompoundCurve().asWkt()) wkt = "CompoundCurve ((0 0,1 1))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(1) - self.assertEqual(geom.exportToWkt(), QgsCompoundCurve().asWkt()) + self.assertEqual(geom.asWkt(), QgsCompoundCurve().asWkt()) wkt = "CompoundCurve ((0 0,1 1),(1 1,2 2))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(0) expected_wkt = "CompoundCurve ((1 1,2 2))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CompoundCurve ((0 0,1 1),(1 1,2 2))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(1) expected_wkt = "CompoundCurve ((0 0,2 2))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CompoundCurve ((0 0,1 1),(1 1,2 2))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(2) expected_wkt = "CompoundCurve ((0 0,1 1))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CompoundCurve ((0 0,1 1),CircularString(1 1,2 0,1 -1))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(1) expected_wkt = "CompoundCurve ((0 0,1 -1))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CompoundCurve (CircularString(0 0,1 1,2 0),CircularString(2 0,3 -1,4 0))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(2) expected_wkt = "CompoundCurve ((0 0, 4 0))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CompoundCurve (CircularString(0 0,1 1,2 0,1.5 -0.5,1 -1),(1 -1,0 0))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(4) expected_wkt = "CompoundCurve (CircularString (0 0, 1 1, 2 0),(2 0, 0 0))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CompoundCurve ((-1 0,0 0),CircularString(0 0,1 1,2 0,1.5 -0.5,1 -1))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(1) expected_wkt = "CompoundCurve ((-1 0, 2 0),CircularString (2 0, 1.5 -0.5, 1 -1))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CompoundCurve (CircularString(-1 -1,-1.5 -0.5,-2 0,-1 1,0 0),CircularString(0 0,1 1,2 0,1.5 -0.5,1 -1))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(4) expected_wkt = "CompoundCurve (CircularString (-1 -1, -1.5 -0.5, -2 0),(-2 0, 2 0),CircularString (2 0, 1.5 -0.5, 1 -1))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) def testDeleteVertexCurvePolygon(self): @@ -3339,80 +3339,80 @@ def testDeleteVertexCurvePolygon(self): assert not geom.deleteVertex(-1) assert not geom.deleteVertex(4) assert geom.deleteVertex(0) - self.assertEqual(geom.exportToWkt(), QgsCurvePolygon().asWkt()) + self.assertEqual(geom.asWkt(), QgsCurvePolygon().asWkt()) wkt = "CurvePolygon (CompoundCurve (CircularString(0 0,1 1,2 0),(2 0,0 0)))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(1) - self.assertEqual(geom.exportToWkt(), QgsCurvePolygon().asWkt()) + self.assertEqual(geom.asWkt(), QgsCurvePolygon().asWkt()) wkt = "CurvePolygon (CompoundCurve (CircularString(0 0,1 1,2 0),(2 0,0 0)))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(2) - self.assertEqual(geom.exportToWkt(), QgsCurvePolygon().asWkt()) + self.assertEqual(geom.asWkt(), QgsCurvePolygon().asWkt()) wkt = "CurvePolygon (CompoundCurve (CircularString(0 0,1 1,2 0),(2 0,0 0)))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(3) - self.assertEqual(geom.exportToWkt(), QgsCurvePolygon().asWkt()) + self.assertEqual(geom.asWkt(), QgsCurvePolygon().asWkt()) wkt = "CurvePolygon (CompoundCurve (CircularString(0 0,1 1,2 0,1.5 -0.5,1 -1),(1 -1,0 0)))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(0) expected_wkt = "CurvePolygon (CompoundCurve (CircularString (2 0, 1.5 -0.5, 1 -1),(1 -1, 2 0)))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CurvePolygon (CompoundCurve (CircularString(0 0,1 1,2 0,1.5 -0.5,1 -1),(1 -1,0 0)))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(1) expected_wkt = "CurvePolygon (CompoundCurve (CircularString (0 0, 1.5 -0.5, 1 -1),(1 -1, 0 0)))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CurvePolygon (CompoundCurve (CircularString(0 0,1 1,2 0,1.5 -0.5,1 -1),(1 -1,0 0)))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(2) expected_wkt = "CurvePolygon (CompoundCurve (CircularString (0 0, 1 1, 1 -1),(1 -1, 0 0)))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CurvePolygon (CompoundCurve (CircularString(0 0,1 1,2 0,1.5 -0.5,1 -1),(1 -1,0 0)))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(3) expected_wkt = "CurvePolygon (CompoundCurve (CircularString (0 0, 1 1, 1 -1),(1 -1, 0 0)))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) wkt = "CurvePolygon (CompoundCurve (CircularString(0 0,1 1,2 0,1.5 -0.5,1 -1),(1 -1,0 0)))" geom = QgsGeometry.fromWkt(wkt) assert geom.deleteVertex(4) expected_wkt = "CurvePolygon (CompoundCurve (CircularString (0 0, 1 1, 2 0),(2 0, 0 0)))" - self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) + self.assertEqual(geom.asWkt(), QgsGeometry.fromWkt(expected_wkt).asWkt()) def testSingleSidedBuffer(self): wkt = "LineString( 0 0, 10 0)" geom = QgsGeometry.fromWkt(wkt) out = geom.singleSidedBuffer(1, 8, QgsGeometry.SideLeft) - result = out.exportToWkt() + result = out.asWkt() expected_wkt = "Polygon ((10 0, 0 0, 0 1, 10 1, 10 0))" self.assertTrue(compareWkt(result, expected_wkt, 0.00001), "Merge lines: mismatch Expected:\n{}\nGot:\n{}\n".format(expected_wkt, result)) wkt = "LineString( 0 0, 10 0)" geom = QgsGeometry.fromWkt(wkt) out = geom.singleSidedBuffer(1, 8, QgsGeometry.SideRight) - result = out.exportToWkt() + result = out.asWkt() expected_wkt = "Polygon ((0 0, 10 0, 10 -1, 0 -1, 0 0))" self.assertTrue(compareWkt(result, expected_wkt, 0.00001), "Merge lines: mismatch Expected:\n{}\nGot:\n{}\n".format(expected_wkt, result)) wkt = "LineString( 0 0, 10 0, 10 10)" geom = QgsGeometry.fromWkt(wkt) out = geom.singleSidedBuffer(1, 8, QgsGeometry.SideRight, QgsGeometry.JoinStyleMiter) - result = out.exportToWkt() + result = out.asWkt() expected_wkt = "Polygon ((0 0, 10 0, 10 10, 11 10, 11 -1, 0 -1, 0 0))" self.assertTrue(compareWkt(result, expected_wkt, 0.00001), "Merge lines: mismatch Expected:\n{}\nGot:\n{}\n".format(expected_wkt, result)) wkt = "LineString( 0 0, 10 0, 10 10)" geom = QgsGeometry.fromWkt(wkt) out = geom.singleSidedBuffer(1, 8, QgsGeometry.SideRight, QgsGeometry.JoinStyleBevel) - result = out.exportToWkt() + result = out.asWkt() expected_wkt = "Polygon ((0 0, 10 0, 10 10, 11 10, 11 0, 10 -1, 0 -1, 0 0))" self.assertTrue(compareWkt(result, expected_wkt, 0.00001), "Merge lines: mismatch Expected:\n{}\nGot:\n{}\n".format(expected_wkt, result)) @@ -3426,7 +3426,7 @@ def testMisc(self): # Test that importing an invalid WKB (a MultiPolygon with a CurvePolygon) fails geom = QgsGeometry.fromWkt('MultiSurface(((0 0,0 1,1 1,0 0)), CurvePolygon ((0 0,0 1,1 1,0 0)))') - wkb = geom.exportToWkb() + wkb = geom.asWkb() wkb = bytearray(wkb) if wkb[1] == QgsWkbTypes.MultiSurface: wkb[1] = QgsWkbTypes.MultiPolygon @@ -3436,7 +3436,7 @@ def testMisc(self): self.assertTrue(False) geom = QgsGeometry() geom.fromWkb(wkb) - self.assertEqual(geom.exportToWkt(), QgsMultiPolygon().asWkt()) + self.assertEqual(geom.asWkt(), QgsMultiPolygon().asWkt()) # Test that fromWkt() on a GeometryCollection works with all possible geometries wkt = "GeometryCollection( " @@ -3466,10 +3466,10 @@ def testMisc(self): wkt += ")" geom = QgsGeometry.fromWkt(wkt) assert geom is not None - wkb1 = geom.exportToWkb() + wkb1 = geom.asWkb() geom = QgsGeometry() geom.fromWkb(wkb1) - wkb2 = geom.exportToWkb() + wkb2 = geom.asWkb() self.assertEqual(wkb1, wkb2) def testMergeLines(self): @@ -3482,23 +3482,23 @@ def testMergeLines(self): # linestring should be returned intact geom = QgsGeometry.fromWkt('LineString(0 0, 10 10)') - result = geom.mergeLines().exportToWkt() + result = geom.mergeLines().asWkt() exp = 'LineString(0 0, 10 10)' self.assertTrue(compareWkt(result, exp, 0.00001), "Merge lines: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) # multilinestring geom = QgsGeometry.fromWkt('MultiLineString((0 0, 10 10),(10 10, 20 20))') - result = geom.mergeLines().exportToWkt() + result = geom.mergeLines().asWkt() exp = 'LineString(0 0, 10 10, 20 20)' self.assertTrue(compareWkt(result, exp, 0.00001), "Merge lines: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) geom = QgsGeometry.fromWkt('MultiLineString((0 0, 10 10),(12 2, 14 4),(10 10, 20 20))') - result = geom.mergeLines().exportToWkt() + result = geom.mergeLines().asWkt() exp = 'MultiLineString((0 0, 10 10, 20 20),(12 2, 14 4))' self.assertTrue(compareWkt(result, exp, 0.00001), "Merge lines: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) geom = QgsGeometry.fromWkt('MultiLineString((0 0, 10 10),(12 2, 14 4))') - result = geom.mergeLines().exportToWkt() + result = geom.mergeLines().asWkt() exp = 'MultiLineString((0 0, 10 10),(12 2, 14 4))' self.assertTrue(compareWkt(result, exp, 0.00001), "Merge lines: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3582,13 +3582,13 @@ def testInterpolate(self): # linestring linestring = QgsGeometry.fromWkt('LineString(0 0, 10 0, 10 10)') exp = 'Point(5 0)' - result = linestring.interpolate(5).exportToWkt() + result = linestring.interpolate(5).asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "Interpolate: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) # polygon polygon = QgsGeometry.fromWkt('Polygon((0 0, 10 0, 10 10, 20 20, 10 20, 0 0))') # NOQA exp = 'Point(10 5)' - result = linestring.interpolate(15).exportToWkt() + result = linestring.interpolate(15).asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "Interpolate: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3645,7 +3645,7 @@ def testExtendLine(self): linestring = QgsGeometry.fromWkt('LineString(0 0, 1 0, 1 1)') extended = linestring.extendLine(1, 2) exp = 'LineString(-1 0, 1 0, 1 3)' - result = extended.exportToWkt() + result = extended.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "Extend line: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3653,7 +3653,7 @@ def testExtendLine(self): multilinestring = QgsGeometry.fromWkt('MultiLineString((0 0, 1 0, 1 1),(11 11, 11 10, 10 10))') extended = multilinestring.extendLine(1, 2) exp = 'MultiLineString((-1 0, 1 0, 1 3),(11 12, 11 10, 8 10))' - result = extended.exportToWkt() + result = extended.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "Extend line: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3669,7 +3669,7 @@ def testRemoveRings(self): polygon = QgsGeometry.fromWkt('Polygon((0 0, 1 0, 1 1, 0 0),(0.1 0.1, 0.2 0.1, 0.2 0.2, 0.1 0.1))') removed = polygon.removeInteriorRings() exp = 'Polygon((0 0, 1 0, 1 1, 0 0))' - result = removed.exportToWkt() + result = removed.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "Extend line: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3678,7 +3678,7 @@ def testRemoveRings(self): '((10 0, 11 0, 11 1, 10 0),(10.1 10.1, 10.2 0.1, 10.2 0.2, 10.1 0.1)))') removed = multipolygon.removeInteriorRings() exp = 'MultiPolygon(((0 0, 1 0, 1 1, 0 0)),((10 0, 11 0, 11 1, 10 0)))' - result = removed.exportToWkt() + result = removed.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "Extend line: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3697,7 +3697,7 @@ def testMinimumOrientedBoundingBox(self): bbox, area, angle, width, height = polygon.orientedMinimumBoundingBox() exp = 'Polygon ((-0.94905660 -1.571698, 2.3817055 -4.580453, 6.7000000 0.1999999, 3.36923 3.208754, -0.949056 -1.57169))' - result = bbox.exportToWkt() + result = bbox.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "Oriented MBBR: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) self.assertAlmostEqual(area, 28.9152, places=3) @@ -3719,7 +3719,7 @@ def testOrthogonalize(self): polygon = QgsGeometry.fromWkt('Polygon((-0.699 0.892, -0.703 0.405, -0.022 0.361, 0.014 0.851, -0.699 0.892))') o = polygon.orthogonalize() exp = 'Polygon ((-0.69899999999999995 0.89200000000000002, -0.72568713635737736 0.38414056283699533, -0.00900222326098143 0.34648000752227009, 0.01768491457044956 0.85433944198378253, -0.69899999999999995 0.89200000000000002))' - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "orthogonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3727,7 +3727,7 @@ def testOrthogonalize(self): polygon = QgsGeometry.fromWkt('Polygon ((-0.698 0.892, -0.702 0.405, -0.022 0.360, 0.014 0.850, -0.698 0.892),(-0.619 0.777, -0.619 0.574, -0.515 0.567, -0.517 0.516, -0.411 0.499, -0.379 0.767, -0.619 0.777),(-0.322 0.506, -0.185 0.735, -0.046 0.428, -0.322 0.506))') o = polygon.orthogonalize() exp = 'Polygon ((-0.69799999999999995 0.89200000000000002, -0.72515703079591087 0.38373993222914216, -0.00901577368860811 0.34547552423418099, 0.01814125858957143 0.85373558928902782, -0.69799999999999995 0.89200000000000002),(-0.61899999999999999 0.77700000000000002, -0.63403125159063511 0.56020458713735533, -0.53071476068518508 0.55304126003523246, -0.5343108192220235 0.5011754225601015, -0.40493624158682306 0.49220537936424585, -0.3863089084840608 0.76086661681561074, -0.61899999999999999 0.77700000000000002),(-0.32200000000000001 0.50600000000000001, -0.185 0.73499999999999999, -0.046 0.42799999999999999, -0.32200000000000001 0.50600000000000001))' - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "orthogonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3737,7 +3737,7 @@ def testOrthogonalize(self): '((0.506 -1.376, 0.433 -1.081, 0.765 -0.900, 0.923 -1.132, 0.923 -1.391, 0.506 -1.376)))') o = polygon.orthogonalize() exp = 'MultiPolygon (((-0.55000000000000004 -1.55299999999999994, -0.182 -0.95399999999999996, -0.182 -0.95399999999999996, 0.186 -1.53800000000000003, -0.55000000000000004 -1.55299999999999994)),((0.50600000000000001 -1.37599999999999989, 0.34888970623957499 -1.04704644438350125, 0.78332709454235683 -0.83955640656085295, 0.92300000000000004 -1.1319999999999999, 0.91737248858460974 -1.38514497083566535, 0.50600000000000001 -1.37599999999999989)))' - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "orthogonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3745,7 +3745,7 @@ def testOrthogonalize(self): line = QgsGeometry.fromWkt('LineString (-1.07445631048298162 -0.91619958829825165, 0.04022568180912156 -0.95572731852137571, 0.04741254184968957 -0.61794489661467789, 0.68704308546024517 -0.66106605685808595)') o = line.orthogonalize() exp = 'LineString (-1.07445631048298162 -0.91619958829825165, 0.04812855116470245 -0.96433184892270418, 0.06228000950284909 -0.63427853851139493, 0.68704308546024517 -0.66106605685808595)' - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "orthogonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3763,7 +3763,7 @@ def testPolygonize(self): l2 = QgsGeometry.fromWkt("LINESTRING (100 180, 80 60, 120 60, 100 180)") o = QgsGeometry.polygonize([l1, l2]) exp = "GeometryCollection(POLYGON ((100 180, 160 20, 20 20, 100 180), (100 180, 80 60, 120 60, 100 180)),POLYGON ((100 180, 120 60, 80 60, 100 180)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "polygonize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3776,7 +3776,7 @@ def testPolygonize(self): QgsGeometry.fromWkt('Point(0, 0)')] o = QgsGeometry.polygonize(lines) exp = "GeometryCollection (Polygon ((0 0, 1 1, 1 0, 0 0)),Polygon ((1 1, 0 0, 0 1, 1 1)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "polygonize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3791,49 +3791,49 @@ def testDelaunayTriangulation(self): input = QgsGeometry.fromWkt("MULTIPOINT ((10 10), (10 20), (20 20))") o = input.delaunayTriangulation() exp = "GEOMETRYCOLLECTION (POLYGON ((10 20, 10 10, 20 20, 10 20)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) o = input.delaunayTriangulation(0, True) exp = "MultiLineString ((10 20, 20 20),(10 10, 10 20),(10 10, 20 20))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("MULTIPOINT ((50 40), (140 70), (80 100), (130 140), (30 150), (70 180), (190 110), (120 20))") o = input.delaunayTriangulation() exp = "GEOMETRYCOLLECTION (POLYGON ((30 150, 50 40, 80 100, 30 150)), POLYGON ((30 150, 80 100, 70 180, 30 150)), POLYGON ((70 180, 80 100, 130 140, 70 180)), POLYGON ((70 180, 130 140, 190 110, 70 180)), POLYGON ((190 110, 130 140, 140 70, 190 110)), POLYGON ((190 110, 140 70, 120 20, 190 110)), POLYGON ((120 20, 140 70, 80 100, 120 20)), POLYGON ((120 20, 80 100, 50 40, 120 20)), POLYGON ((80 100, 140 70, 130 140, 80 100)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) o = input.delaunayTriangulation(0, True) exp = "MultiLineString ((70 180, 190 110),(30 150, 70 180),(30 150, 50 40),(50 40, 120 20),(120 20, 190 110),(120 20, 140 70),(140 70, 190 110),(130 140, 140 70),(130 140, 190 110),(70 180, 130 140),(80 100, 130 140),(70 180, 80 100),(30 150, 80 100),(50 40, 80 100),(80 100, 120 20),(80 100, 140 70))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt( "MULTIPOINT ((10 10), (10 20), (20 20), (20 10), (20 0), (10 0), (0 0), (0 10), (0 20))") o = input.delaunayTriangulation() exp = "GEOMETRYCOLLECTION (POLYGON ((0 20, 0 10, 10 10, 0 20)), POLYGON ((0 20, 10 10, 10 20, 0 20)), POLYGON ((10 20, 10 10, 20 10, 10 20)), POLYGON ((10 20, 20 10, 20 20, 10 20)), POLYGON ((10 0, 20 0, 10 10, 10 0)), POLYGON ((10 0, 10 10, 0 10, 10 0)), POLYGON ((10 0, 0 10, 0 0, 10 0)), POLYGON ((10 10, 20 0, 20 10, 10 10)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) o = input.delaunayTriangulation(0, True) exp = "MultiLineString ((10 20, 20 20),(0 20, 10 20),(0 10, 0 20),(0 0, 0 10),(0 0, 10 0),(10 0, 20 0),(20 0, 20 10),(20 10, 20 20),(10 20, 20 10),(10 10, 20 10),(10 10, 10 20),(0 20, 10 10),(0 10, 10 10),(10 0, 10 10),(0 10, 10 0),(10 10, 20 0))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt( "POLYGON ((42 30, 41.96 29.61, 41.85 29.23, 41.66 28.89, 41.41 28.59, 41.11 28.34, 40.77 28.15, 40.39 28.04, 40 28, 39.61 28.04, 39.23 28.15, 38.89 28.34, 38.59 28.59, 38.34 28.89, 38.15 29.23, 38.04 29.61, 38 30, 38.04 30.39, 38.15 30.77, 38.34 31.11, 38.59 31.41, 38.89 31.66, 39.23 31.85, 39.61 31.96, 40 32, 40.39 31.96, 40.77 31.85, 41.11 31.66, 41.41 31.41, 41.66 31.11, 41.85 30.77, 41.96 30.39, 42 30))") o = input.delaunayTriangulation(0, True) exp = "MULTILINESTRING ((41.66 31.11, 41.85 30.77), (41.41 31.41, 41.66 31.11), (41.11 31.66, 41.41 31.41), (40.77 31.85, 41.11 31.66), (40.39 31.96, 40.77 31.85), (40 32, 40.39 31.96), (39.61 31.96, 40 32), (39.23 31.85, 39.61 31.96), (38.89 31.66, 39.23 31.85), (38.59 31.41, 38.89 31.66), (38.34 31.11, 38.59 31.41), (38.15 30.77, 38.34 31.11), (38.04 30.39, 38.15 30.77), (38 30, 38.04 30.39), (38 30, 38.04 29.61), (38.04 29.61, 38.15 29.23), (38.15 29.23, 38.34 28.89), (38.34 28.89, 38.59 28.59), (38.59 28.59, 38.89 28.34), (38.89 28.34, 39.23 28.15), (39.23 28.15, 39.61 28.04), (39.61 28.04, 40 28), (40 28, 40.39 28.04), (40.39 28.04, 40.77 28.15), (40.77 28.15, 41.11 28.34), (41.11 28.34, 41.41 28.59), (41.41 28.59, 41.66 28.89), (41.66 28.89, 41.85 29.23), (41.85 29.23, 41.96 29.61), (41.96 29.61, 42 30), (41.96 30.39, 42 30), (41.85 30.77, 41.96 30.39), (41.66 31.11, 41.96 30.39), (41.41 31.41, 41.96 30.39), (41.41 28.59, 41.96 30.39), (41.41 28.59, 41.41 31.41), (38.59 28.59, 41.41 28.59), (38.59 28.59, 41.41 31.41), (38.59 28.59, 38.59 31.41), (38.59 31.41, 41.41 31.41), (38.59 31.41, 39.61 31.96), (39.61 31.96, 41.41 31.41), (39.61 31.96, 40.39 31.96), (40.39 31.96, 41.41 31.41), (40.39 31.96, 41.11 31.66), (38.04 30.39, 38.59 28.59), (38.04 30.39, 38.59 31.41), (38.04 30.39, 38.34 31.11), (38.04 29.61, 38.59 28.59), (38.04 29.61, 38.04 30.39), (39.61 28.04, 41.41 28.59), (38.59 28.59, 39.61 28.04), (38.89 28.34, 39.61 28.04), (40.39 28.04, 41.41 28.59), (39.61 28.04, 40.39 28.04), (41.96 29.61, 41.96 30.39), (41.41 28.59, 41.96 29.61), (41.66 28.89, 41.96 29.61), (40.39 28.04, 41.11 28.34), (38.04 29.61, 38.34 28.89), (38.89 31.66, 39.61 31.96))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt( "POLYGON ((0 0, 0 200, 180 200, 180 0, 0 0), (20 180, 160 180, 160 20, 152.625 146.75, 20 180), (30 160, 150 30, 70 90, 30 160))") o = input.delaunayTriangulation(0, True) exp = "MultiLineString ((0 200, 180 200),(0 0, 0 200),(0 0, 180 0),(180 0, 180 200),(152.625 146.75, 180 0),(152.625 146.75, 180 200),(152.625 146.75, 160 180),(160 180, 180 200),(0 200, 160 180),(20 180, 160 180),(0 200, 20 180),(20 180, 30 160),(0 200, 30 160),(0 0, 30 160),(30 160, 70 90),(0 0, 70 90),(70 90, 150 30),(0 0, 150 30),(150 30, 160 20),(0 0, 160 20),(160 20, 180 0),(152.625 146.75, 160 20),(150 30, 152.625 146.75),(70 90, 152.625 146.75),(30 160, 152.625 146.75),(30 160, 160 180))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3841,12 +3841,12 @@ def testDelaunayTriangulation(self): "MULTIPOINT ((10 10 1), (10 20 2), (20 20 3), (20 10 1.5), (20 0 2.5), (10 0 3.5), (0 0 0), (0 10 .5), (0 20 .25))") o = input.delaunayTriangulation() exp = "GeometryCollection (PolygonZ ((0 20 0.25, 0 10 0.5, 10 10 1, 0 20 0.25)),PolygonZ ((0 20 0.25, 10 10 1, 10 20 2, 0 20 0.25)),PolygonZ ((10 20 2, 10 10 1, 20 10 1.5, 10 20 2)),PolygonZ ((10 20 2, 20 10 1.5, 20 20 3, 10 20 2)),PolygonZ ((10 0 3.5, 20 0 2.5, 10 10 1, 10 0 3.5)),PolygonZ ((10 0 3.5, 10 10 1, 0 10 0.5, 10 0 3.5)),PolygonZ ((10 0 3.5, 0 10 0.5, 0 0 0, 10 0 3.5)),PolygonZ ((10 10 1, 20 0 2.5, 20 10 1.5, 10 10 1)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) o = input.delaunayTriangulation(0, True) exp = "MultiLineStringZ ((10 20 2, 20 20 3),(0 20 0.25, 10 20 2),(0 10 0.5, 0 20 0.25),(0 0 0, 0 10 0.5),(0 0 0, 10 0 3.5),(10 0 3.5, 20 0 2.5),(20 0 2.5, 20 10 1.5),(20 10 1.5, 20 20 3),(10 20 2, 20 10 1.5),(10 10 1, 20 10 1.5),(10 10 1, 10 20 2),(0 20 0.25, 10 10 1),(0 10 0.5, 10 10 1),(10 0 3.5, 10 10 1),(0 10 0.5, 10 0 3.5),(10 10 1, 20 0 2.5))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3854,7 +3854,7 @@ def testDelaunayTriangulation(self): "MULTIPOINT((-118.3964065 56.0557),(-118.396406 56.0475),(-118.396407 56.04),(-118.3968 56))") o = input.delaunayTriangulation(0.001, True) exp = "MULTILINESTRING ((-118.3964065 56.0557, -118.396406 56.0475), (-118.396407 56.04, -118.396406 56.0475), (-118.3968 56, -118.396407 56.04))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3873,28 +3873,28 @@ def testVoronoi(self): input = QgsGeometry.fromWkt("MULTIPOINT ((150 200), (180 270), (275 163))") o = input.voronoiDiagram() exp = "GeometryCollection (Polygon ((170.02400000000000091 38, 25 38, 25 295, 221.20588235294115975 210.91176470588234793, 170.02400000000000091 38)),Polygon ((400 369.65420560747662648, 400 38, 170.02400000000000091 38, 221.20588235294115975 210.91176470588234793, 400 369.65420560747662648)),Polygon ((25 295, 25 395, 400 395, 400 369.65420560747662648, 221.20588235294115975 210.91176470588234793, 25 295)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("MULTIPOINT ((280 300), (420 330), (380 230), (320 160))") o = input.voronoiDiagram() exp = "GeometryCollection (Polygon ((110 175.71428571428572241, 110 500, 310.35714285714283278 500, 353.515625 298.59375, 306.875 231.96428571428572241, 110 175.71428571428572241)),Polygon ((590 204, 590 -10, 589.16666666666662877 -10, 306.875 231.96428571428572241, 353.515625 298.59375, 590 204)),Polygon ((589.16666666666662877 -10, 110 -10, 110 175.71428571428572241, 306.875 231.96428571428572241, 589.16666666666662877 -10)),Polygon ((310.35714285714283278 500, 590 500, 590 204, 353.515625 298.59375, 310.35714285714283278 500)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("MULTIPOINT ((320 170), (366 246), (530 230), (530 300), (455 277), (490 160))") o = input.voronoiDiagram() exp = "GeometryCollection (Polygon ((392.35294117647055145 -50, 110 -50, 110 349.02631578947364233, 405.31091180866962986 170.28550074738416242, 392.35294117647055145 -50)),Polygon ((740 63.57142857142859071, 740 -50, 392.35294117647055145 -50, 405.31091180866962986 170.28550074738416242, 429.91476778570188344 205.76082797008174907, 470.12061711079945781 217.78821879382888937, 740 63.57142857142859071)),Polygon ((110 349.02631578947364233, 110 510, 323.94382022471910432 510, 429.91476778570188344 205.76082797008174907, 405.31091180866962986 170.28550074738416242, 110 349.02631578947364233)),Polygon ((323.94382022471910432 510, 424.57333333333326664 510, 499.70666666666664923 265, 470.12061711079945781 217.78821879382888937, 429.91476778570188344 205.76082797008174907, 323.94382022471910432 510)),Polygon ((740 265, 740 63.57142857142859071, 470.12061711079945781 217.78821879382888937, 499.70666666666664923 265, 740 265)),Polygon ((424.57333333333326664 510, 740 510, 740 265, 499.70666666666664923 265, 424.57333333333326664 510)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("MULTIPOINT ((280 200), (406 285), (580 280), (550 190), (370 190), (360 90), (480 110), (440 160), (450 180), (480 180), (460 160), (360 210), (360 220), (370 210), (375 227))") o = input.voronoiDiagram() exp = "GeometryCollection (Polygon ((-20 -102.27272727272726627, -20 585, 111.94841269841269593 585, 293.54906542056073704 315.803738317756995, 318.75 215, 323.2352941176470722 179.1176470588235361, 319.39560439560437999 144.560439560439562, -20 -102.27272727272726627)),Polygon ((365 200, 365 215, 369.40909090909093493 219.40909090909090651, 414.21192052980131848 206.23178807947019209, 411.875 200, 365 200)),Polygon ((365 215, 365 200, 323.2352941176470722 179.1176470588235361, 318.75 215, 365 215)),Polygon ((471.66666666666674246 -210, -20 -210, -20 -102.27272727272726627, 319.39560439560437999 144.560439560439562, 388.97260273972602818 137.60273972602738013, 419.55882352941176805 102.64705882352942012, 471.66666666666674246 -210)),Polygon ((411.875 200, 410.29411764705884025 187.35294117647057988, 388.97260273972602818 137.60273972602738013, 319.39560439560437999 144.560439560439562, 323.2352941176470722 179.1176470588235361, 365 200, 411.875 200)),Polygon ((410.29411764705884025 187.35294117647057988, 411.875 200, 414.21192052980131848 206.23178807947019209, 431.62536593766145643 234.0192009643533595, 465 248.00476190476189231, 465 175, 450 167.5, 410.29411764705884025 187.35294117647057988)),Polygon ((293.54906542056073704 315.803738317756995, 339.65007656967839011 283.17840735068909908, 369.40909090909093493 219.40909090909090651, 365 215, 318.75 215, 293.54906542056073704 315.803738317756995)),Polygon ((111.94841269841269593 585, 501.69252873563215189 585, 492.56703910614521646 267.43296089385472669, 465 248.00476190476189231, 431.62536593766145643 234.0192009643533595, 339.65007656967839011 283.17840735068909908, 293.54906542056073704 315.803738317756995, 111.94841269841269593 585)),Polygon ((369.40909090909093493 219.40909090909090651, 339.65007656967839011 283.17840735068909908, 431.62536593766145643 234.0192009643533595, 414.21192052980131848 206.23178807947019209, 369.40909090909093493 219.40909090909090651)),Polygon ((388.97260273972602818 137.60273972602738013, 410.29411764705884025 187.35294117647057988, 450 167.5, 450 127, 419.55882352941176805 102.64705882352942012, 388.97260273972602818 137.60273972602738013)),Polygon ((465 175, 465 248.00476190476189231, 492.56703910614521646 267.43296089385472669, 505 255, 520.71428571428566556 145, 495 145, 465 175)),Polygon ((880 -169.375, 880 -210, 471.66666666666674246 -210, 419.55882352941176805 102.64705882352942012, 450 127, 495 145, 520.71428571428566556 145, 880 -169.375)),Polygon ((465 175, 495 145, 450 127, 450 167.5, 465 175)),Polygon ((501.69252873563215189 585, 880 585, 880 130.00000000000005684, 505 255, 492.56703910614521646 267.43296089385472669, 501.69252873563215189 585)),Polygon ((880 130.00000000000005684, 880 -169.375, 520.71428571428566556 145, 505 255, 880 130.00000000000005684)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3902,7 +3902,7 @@ def testVoronoi(self): "MULTIPOINT ((100 200), (105 202), (110 200), (140 230), (210 240), (220 190), (170 170), (170 260), (213 245), (220 190))") o = input.voronoiDiagram(QgsGeometry(), 6) exp = "GeometryCollection (Polygon ((77.1428571428571388 50, -20 50, -20 380, -3.75 380, 105 235, 105 115, 77.1428571428571388 50)),Polygon ((247 50, 77.1428571428571388 50, 105 115, 145 195, 178.33333333333334281 211.66666666666665719, 183.51851851851853326 208.70370370370369528, 247 50)),Polygon ((-3.75 380, 20.00000000000000711 380, 176.66666666666665719 223.33333333333334281, 178.33333333333334281 211.66666666666665719, 145 195, 105 235, -3.75 380)),Polygon ((105 115, 105 235, 145 195, 105 115)),Polygon ((20.00000000000000711 380, 255 380, 176.66666666666665719 223.33333333333334281, 20.00000000000000711 380)),Polygon ((255 380, 340 380, 340 240, 183.51851851851853326 208.70370370370369528, 178.33333333333334281 211.66666666666665719, 176.66666666666665719 223.33333333333334281, 255 380)),Polygon ((340 240, 340 50, 247 50, 183.51851851851853326 208.70370370370369528, 340 240)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3910,7 +3910,7 @@ def testVoronoi(self): "MULTIPOINT ((170 270), (177 275), (190 230), (230 250), (210 290), (240 280), (240 250))") o = input.voronoiDiagram(QgsGeometry(), 10) exp = "GeometryCollection (Polygon ((100 210, 100 360, 150 360, 200 260, 100 210)),Polygon ((150 360, 250 360, 220 270, 200 260, 150 360)),Polygon ((247 160, 100 160, 100 210, 200 260, 235 190, 247 160)),Polygon ((220 270, 235 265, 235 190, 200 260, 220 270)),Polygon ((250 360, 310 360, 310 265, 235 265, 220 270, 250 360)),Polygon ((310 265, 310 160, 247 160, 235 190, 235 265, 310 265)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3918,7 +3918,7 @@ def testVoronoi(self): "MULTIPOINT ((155 271), (150 360), (260 360), (271 265), (280 260), (270 370), (154 354), (150 260))") o = input.voronoiDiagram(QgsGeometry(), 100) exp = "GeometryCollection (Polygon ((215 130, 20 130, 20 310, 205 310, 215 299, 215 130)),Polygon ((205 500, 410 500, 410 338, 215 299, 205 310, 205 500)),Polygon ((20 310, 20 500, 205 500, 205 310, 20 310)),Polygon ((410 338, 410 130, 215 130, 215 299, 410 338)))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "delaunay: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3932,14 +3932,14 @@ def testDensifyByCount(self): input = QgsGeometry.fromWkt("PointZ( 1 2 3 )") o = input.densifyByCount(100) exp = "PointZ( 1 2 3 )" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt( "MULTIPOINT ((155 271), (150 360), (260 360), (271 265), (280 260), (270 370), (154 354), (150 260))") o = input.densifyByCount(100) exp = "MULTIPOINT ((155 271), (150 360), (260 360), (271 265), (280 260), (270 370), (154 354), (150 260))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3947,35 +3947,35 @@ def testDensifyByCount(self): input = QgsGeometry.fromWkt("LineString( 0 0, 10 0, 10 10 )") o = input.densifyByCount(0) exp = "LineString( 0 0, 10 0, 10 10 )" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) o = input.densifyByCount(1) exp = "LineString( 0 0, 5 0, 10 0, 10 5, 10 10 )" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) o = input.densifyByCount(3) exp = "LineString( 0 0, 2.5 0, 5 0, 7.5 0, 10 0, 10 2.5, 10 5, 10 7.5, 10 10 )" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("LineStringZ( 0 0 1, 10 0 2, 10 10 0)") o = input.densifyByCount(1) exp = "LineStringZ( 0 0 1, 5 0 1.5, 10 0 2, 10 5 1, 10 10 0 )" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("LineStringM( 0 0 0, 10 0 2, 10 10 0)") o = input.densifyByCount(1) exp = "LineStringM( 0 0 0, 5 0 1, 10 0 2, 10 5 1, 10 10 0 )" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("LineStringZM( 0 0 1 10, 10 0 2 8, 10 10 0 4)") o = input.densifyByCount(1) exp = "LineStringZM( 0 0 1 10, 5 0 1.5 9, 10 0 2 8, 10 5 1 6, 10 10 0 4 )" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -3983,28 +3983,28 @@ def testDensifyByCount(self): input = QgsGeometry.fromWkt("Polygon(( 0 0, 10 0, 10 10, 0 0 ))") o = input.densifyByCount(0) exp = "Polygon(( 0 0, 10 0, 10 10, 0 0 ))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("PolygonZ(( 0 0 1, 10 0 2, 10 10 0, 0 0 1 ))") o = input.densifyByCount(1) exp = "PolygonZ(( 0 0 1, 5 0 1.5, 10 0 2, 10 5 1, 10 10 0, 5 5 0.5, 0 0 1 ))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("PolygonZM(( 0 0 1 4, 10 0 2 6, 10 10 0 8, 0 0 1 4 ))") o = input.densifyByCount(1) exp = "PolygonZM(( 0 0 1 4, 5 0 1.5 5, 10 0 2 6, 10 5 1 7, 10 10 0 8, 5 5 0.5 6, 0 0 1 4 ))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) # (not strictly valid, but shouldn't matter! input = QgsGeometry.fromWkt("PolygonZM(( 0 0 1 4, 10 0 2 6, 10 10 0 8, 0 0 1 4 ), ( 0 0 1 4, 10 0 2 6, 10 10 0 8, 0 0 1 4 ) )") o = input.densifyByCount(1) exp = "PolygonZM(( 0 0 1 4, 5 0 1.5 5, 10 0 2 6, 10 5 1 7, 10 10 0 8, 5 5 0.5 6, 0 0 1 4 ),( 0 0 1 4, 5 0 1.5 5, 10 0 2 6, 10 5 1 7, 10 10 0 8, 5 5 0.5 6, 0 0 1 4 ))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -4012,7 +4012,7 @@ def testDensifyByCount(self): input = QgsGeometry.fromWkt("MultiLineString(( 0 0, 5 0, 10 0, 10 5, 10 10), (20 0, 25 0, 30 0, 30 5, 30 10 ) )") o = input.densifyByCount(1) exp = "MultiLineString(( 0 0, 2.5 0, 5 0, 7.5 0, 10 0, 10 2.5, 10 5, 10 7.5, 10 10 ),( 20 0, 22.5 0, 25 0, 27.5 0, 30 0, 30 2.5, 30 5, 30 7.5, 30 10 ))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -4020,7 +4020,7 @@ def testDensifyByCount(self): input = QgsGeometry.fromWkt("MultiPolygonZ((( 0 0 1, 10 0 2, 10 10 0, 0 0 1)),(( 0 0 1, 10 0 2, 10 10 0, 0 0 1 )))") o = input.densifyByCount(1) exp = "MultiPolygonZ((( 0 0 1, 5 0 1.5, 10 0 2, 10 5 1, 10 10 0, 5 5 0.5, 0 0 1 )),(( 0 0 1, 5 0 1.5, 10 0 2, 10 5 1, 10 10 0, 5 5 0.5, 0 0 1 )))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -4033,14 +4033,14 @@ def testDensifyByDistance(self): input = QgsGeometry.fromWkt("PointZ( 1 2 3 )") o = input.densifyByDistance(0.1) exp = "PointZ( 1 2 3 )" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt( "MULTIPOINT ((155 271), (150 360), (260 360), (271 265), (280 260), (270 370), (154 354), (150 260))") o = input.densifyByDistance(0.1) exp = "MULTIPOINT ((155 271), (150 360), (260 360), (271 265), (280 260), (270 370), (154 354), (150 260))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -4048,31 +4048,31 @@ def testDensifyByDistance(self): input = QgsGeometry.fromWkt("LineString( 0 0, 10 0, 10 10 )") o = input.densifyByDistance(100) exp = "LineString( 0 0, 10 0, 10 10 )" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) o = input.densifyByDistance(3) exp = "LineString (0 0, 2.5 0, 5 0, 7.5 0, 10 0, 10 2.5, 10 5, 10 7.5, 10 10)" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("LineStringZ( 0 0 1, 10 0 2, 10 10 0)") o = input.densifyByDistance(6) exp = "LineStringZ (0 0 1, 5 0 1.5, 10 0 2, 10 5 1, 10 10 0)" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("LineStringM( 0 0 0, 10 0 2, 10 10 0)") o = input.densifyByDistance(3) exp = "LineStringM (0 0 0, 2.5 0 0.5, 5 0 1, 7.5 0 1.5, 10 0 2, 10 2.5 1.5, 10 5 1, 10 7.5 0.5, 10 10 0)" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("LineStringZM( 0 0 1 10, 10 0 2 8, 10 10 0 4)") o = input.densifyByDistance(6) exp = "LineStringZM (0 0 1 10, 5 0 1.5 9, 10 0 2 8, 10 5 1 6, 10 10 0 4)" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -4080,14 +4080,14 @@ def testDensifyByDistance(self): input = QgsGeometry.fromWkt("Polygon(( 0 0, 20 0, 20 20, 0 0 ))") o = input.densifyByDistance(110) exp = "Polygon(( 0 0, 20 0, 20 20, 0 0 ))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) input = QgsGeometry.fromWkt("PolygonZ(( 0 0 1, 20 0 2, 20 20 0, 0 0 1 ))") o = input.densifyByDistance(6) exp = "PolygonZ ((0 0 1, 5 0 1.25, 10 0 1.5, 15 0 1.75, 20 0 2, 20 5 1.5, 20 10 1, 20 15 0.5, 20 20 0, 16 16 0.2, 12 12 0.4, 8 8 0.6, 4 4 0.8, 0 0 1))" - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "densify by count: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -4132,13 +4132,13 @@ def testCentroid(self): input = QgsGeometry.fromWkt(t[0]) o = input.centroid() exp = t[1] - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "centroid: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) # QGIS native algorithms are bad! if False: - result = QgsGeometry(input.get().centroid()).exportToWkt() + result = QgsGeometry(input.get().centroid()).asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "centroid: mismatch using QgsAbstractGeometry methods Input {} \n Expected:\n{}\nGot:\n{}\n".format(t[0], exp, result)) @@ -4220,7 +4220,7 @@ def testSubdivide(self): if t[2]: exp = t[2] - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "clipped: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) @@ -4247,7 +4247,7 @@ def testClipped(self): input = QgsGeometry.fromWkt(t[0]) o = input.clipped(t[1]) exp = t[2] - result = o.exportToWkt() + result = o.asWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "clipped: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result)) diff --git a/tests/src/python/test_qgsserver_wfst.py b/tests/src/python/test_qgsserver_wfst.py index 6e1ab351f6f3..839c89de2695 100644 --- a/tests/src/python/test_qgsserver_wfst.py +++ b/tests/src/python/test_qgsserver_wfst.py @@ -201,8 +201,8 @@ def _checkMatchFeatures(self, wfs_layer, features): """ for f in features: wf = self._getFeatureByAttribute(wfs_layer, 'id', f['id']) - self.assertEqual(wf.geometry().exportToWkt(), - f.geometry().exportToWkt()) + self.assertEqual(wf.geometry().asWkt(), + f.geometry().asWkt()) self.assertEqual(f['name'], wf['name']) def _checkDeleteFeatures(self, layer, features): diff --git a/tests/src/python/test_qgsvectorfilewriter.py b/tests/src/python/test_qgsvectorfilewriter.py index 36a53fc0bf12..9a1478b96922 100644 --- a/tests/src/python/test_qgsvectorfilewriter.py +++ b/tests/src/python/test_qgsvectorfilewriter.py @@ -287,7 +287,7 @@ def testWriteShapefileWithZ(self): created_layer = QgsVectorLayer('{}|layerid=0'.format(dest_file_name), 'test', 'ogr') f = next(created_layer.getFeatures(QgsFeatureRequest())) g = f.geometry() - wkt = g.exportToWkt() + wkt = g.asWkt() expWkt = 'PointZ (1 2 3)' self.assertTrue(compareWkt(expWkt, wkt), "saving geometry with Z failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) @@ -311,7 +311,7 @@ def testWriteShapefileWithZ(self): created_layer_from_shp = QgsVectorLayer('{}|layerid=0'.format(dest_file_name), 'test', 'ogr') f = next(created_layer_from_shp.getFeatures(QgsFeatureRequest())) g = f.geometry() - wkt = g.exportToWkt() + wkt = g.asWkt() self.assertTrue(compareWkt(expWkt, wkt), "saving geometry with Z failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)) @@ -350,7 +350,7 @@ def testWriteShapefileWithMultiConversion(self): created_layer = QgsVectorLayer('{}|layerid=0'.format(dest_file_name), 'test', 'ogr') f = next(created_layer.getFeatures(QgsFeatureRequest())) g = f.geometry() - wkt = g.exportToWkt() + wkt = g.asWkt() expWkt = 'MultiPoint ((1 2))' self.assertTrue(compareWkt(expWkt, wkt), "saving geometry with multi conversion failed: mismatch Expected:\n%s\nGot:\n%s\n" % ( @@ -435,7 +435,7 @@ def testWriteShapefileWithAttributeSubsets(self): # even without attributes f = next(created_layer.getFeatures(QgsFeatureRequest())) g = f.geometry() - wkt = g.exportToWkt() + wkt = g.asWkt() expWkt = 'Point (1 2)' self.assertTrue(compareWkt(expWkt, wkt), "geometry not saved correctly when saving without attributes : mismatch Expected:\n%s\nGot:\n%s\n" % ( diff --git a/tests/src/python/test_qgsvectorlayer.py b/tests/src/python/test_qgsvectorlayer.py index b04b3f8a565c..c6d76242df55 100644 --- a/tests/src/python/test_qgsvectorlayer.py +++ b/tests/src/python/test_qgsvectorlayer.py @@ -175,10 +175,10 @@ def dumpEditBuffer(layer): for fid, f in editBuffer.addedFeatures().items(): print(("%d: %s | %s" % ( f.id(), formatAttributes(f.attributes()), - f.geometry().exportToWkt()))) + f.geometry().asWkt()))) print("CHANGED GEOM:") for fid, geom in editBuffer.changedGeometries().items(): - print(("%d | %s" % (f.id(), f.geometry().exportToWkt()))) + print(("%d | %s" % (f.id(), f.geometry().asWkt()))) class TestQgsVectorLayer(unittest.TestCase, FeatureSourceTestCase): diff --git a/tests/src/python/test_qgsvectorlayerutils.py b/tests/src/python/test_qgsvectorlayerutils.py index 09cad2eb69dd..20b2c7d67999 100644 --- a/tests/src/python/test_qgsvectorlayerutils.py +++ b/tests/src/python/test_qgsvectorlayerutils.py @@ -243,7 +243,7 @@ def testCreateFeature(self): g = QgsGeometry.fromPointXY(QgsPointXY(100, 200)) f = QgsVectorLayerUtils.createFeature(layer, g) self.assertTrue(f.hasGeometry()) - self.assertEqual(f.geometry().exportToWkt(), g.exportToWkt()) + self.assertEqual(f.geometry().asWkt(), g.asWkt()) # using attribute map f = QgsVectorLayerUtils.createFeature(layer, attributes={0: 'a', 2: 6.0})