Skip to content

Commit

Permalink
Rename QgsGeometry.addPoints with XY / V2-less versions
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 30, 2017
1 parent 750a54f commit ca74e39
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions doc/api_break.dox
Expand Up @@ -1311,8 +1311,8 @@ method if the geometry is not being modified.
empty geometry collection)
- wkbSize() and asWkb() has been replaced by exportToWkb(). 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<QgsPoint> &points, QgsWkbTypes::GeometryType geomType ) has been renamed to addPoints
- int addPart( const QList<QgsPointV2> &points, QgsWkbTypes::GeometryType geomType ) has been renamed to addPointsV2
- int addPart( const QList<QgsPoint> &points, QgsWkbTypes::GeometryType geomType ) has been renamed to addPointsXY
- int addPart( const QList<QgsPointV2> &points, QgsWkbTypes::GeometryType geomType ) has been renamed to addPoints
- static bool compare( const QgsPolyline& p1, const QgsPolyline& p2, double epsilon ) has been renamed to comparePolylines
- static bool compare( const QgsPolygon& p1, const QgsPolygon& p2, double epsilon ) has been renamed to comparePolygons
- static bool compare( const QgsMultiPolygon& p1, const QgsMultiPolygon& p2, double epsilon ) has been renamed to compareMultiPolygons
Expand Down
12 changes: 6 additions & 6 deletions python/core/geometry/qgsgeometry.sip
Expand Up @@ -519,7 +519,7 @@ Returns true if WKB of the geometry is of WKBMulti* type
:rtype: OperationResult
%End

OperationResult addPart( const QList<QgsPointXY> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) /PyName=addPoints/;
OperationResult addPart( const QList<QgsPointXY> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) /PyName=addPointsXY/;
%Docstring
Adds a new part to a the geometry.
\param points points describing part to add
Expand All @@ -528,7 +528,7 @@ Returns true if WKB of the geometry is of WKBMulti* type
:rtype: OperationResult
%End

OperationResult addPart( const QgsPointSequence &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) /PyName=addPointsV2/;
OperationResult addPart( const QgsPointSequence &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) /PyName=addPoints/;
%Docstring
Adds a new part to a the geometry.
\param points points describing part to add
Expand Down Expand Up @@ -1581,16 +1581,16 @@ Returns an extruded version of this geometry.

static void convertPointList( const QList<QgsPointXY> &input, QgsPointSequence &output );
%Docstring
Upgrades a point list from QgsPointXY to QgsPointV2
Upgrades a point list from QgsPointXY to QgsPoint
\param input list of QgsPointXY objects to be upgraded
\param output destination for list of points converted to QgsPointV2
\param output destination for list of points converted to QgsPoint
%End

static void convertPointList( const QgsPointSequence &input, QList<QgsPointXY> &output );
%Docstring
Downgrades a point list from QgsPoint to QgsPoint
Downgrades a point list from QgsPoint to QgsPointXY
\param input list of QgsPoint objects to be downgraded
\param output destination for list of points converted to QgsPoint
\param output destination for list of points converted to QgsPointXY
%End

operator QVariant() const;
Expand Down
12 changes: 6 additions & 6 deletions src/core/geometry/qgsgeometry.h
Expand Up @@ -582,15 +582,15 @@ class CORE_EXPORT QgsGeometry
* \param geomType default geometry type to create if no existing geometry
* \returns OperationResult a result code: success or reason of failure
*/
OperationResult addPart( const QList<QgsPointXY> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) SIP_PYNAME( addPoints );
OperationResult addPart( const QList<QgsPointXY> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) SIP_PYNAME( addPointsXY );

/**
* Adds a new part to a the geometry.
* \param points points describing part to add
* \param geomType default geometry type to create if no existing geometry
* \returns OperationResult a result code: success or reason of failure
*/
OperationResult addPart( const QgsPointSequence &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) SIP_PYNAME( addPointsV2 );
OperationResult addPart( const QgsPointSequence &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) SIP_PYNAME( addPoints );

/**
* Adds a new part to this geometry.
Expand Down Expand Up @@ -1605,16 +1605,16 @@ class CORE_EXPORT QgsGeometry
static QgsGeometryEngine *createGeometryEngine( const QgsAbstractGeometry *geometry ) SIP_FACTORY;

/**
* Upgrades a point list from QgsPointXY to QgsPointV2
* Upgrades a point list from QgsPointXY to QgsPoint
* \param input list of QgsPointXY objects to be upgraded
* \param output destination for list of points converted to QgsPointV2
* \param output destination for list of points converted to QgsPoint
*/
static void convertPointList( const QList<QgsPointXY> &input, QgsPointSequence &output );

/**
* Downgrades a point list from QgsPoint to QgsPoint
* Downgrades a point list from QgsPoint to QgsPointXY
* \param input list of QgsPoint objects to be downgraded
* \param output destination for list of points converted to QgsPoint
* \param output destination for list of points converted to QgsPointXY
*/
static void convertPointList( const QgsPointSequence &input, QList<QgsPointXY> &output );

Expand Down
32 changes: 16 additions & 16 deletions tests/src/python/test_qgsgeometry.py
Expand Up @@ -1415,7 +1415,7 @@ def testAddPart(self):
points = [QgsPointXY(0, 0), QgsPointXY(1, 0)]

point = QgsGeometry.fromPoint(points[0])
self.assertEqual(point.addPoints([points[1]]), 0)
self.assertEqual(point.addPointsXY([points[1]]), 0)
expwkt = "MultiPoint ((0 0), (1 0))"
wkt = point.exportToWkt()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
Expand All @@ -1437,14 +1437,14 @@ def testAddPart(self):
]

polyline = QgsGeometry.fromPolylineXY(points[0])
self.assertEqual(polyline.addPoints(points[1][0:1]), QgsGeometry.InvalidInput, "addPoints with one point line unexpectedly succeeded.")
self.assertEqual(polyline.addPoints(points[1][0:2]), QgsGeometry.Success, "addPoints with two point line failed.")
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()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

polyline = QgsGeometry.fromPolylineXY(points[0])
self.assertEqual(polyline.addPoints(points[1]), QgsGeometry.Success, "addPoints with %d point line failed." % len(points[1]))
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()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
Expand All @@ -1470,12 +1470,12 @@ def testAddPart(self):

polygon = QgsGeometry.fromPolygon(points[0])

self.assertEqual(polygon.addPoints(points[1][0][0:1]), QgsGeometry.InvalidInput, "addPoints with one point ring unexpectedly succeeded.")
self.assertEqual(polygon.addPoints(points[1][0][0:2]), QgsGeometry.InvalidInput, "addPoints with two point ring unexpectedly succeeded.")
self.assertEqual(polygon.addPoints(points[1][0][0:3]), QgsGeometry.InvalidInput, "addPoints with unclosed three point ring unexpectedly succeeded.")
self.assertEqual(polygon.addPoints([QgsPointXY(4, 0), QgsPointXY(5, 0), QgsPointXY(4, 0)]), QgsGeometry.InvalidInput, "addPoints with 'closed' three point ring unexpectedly succeeded.")
self.assertEqual(polygon.addPointsXY(points[1][0][0:1]), QgsGeometry.InvalidInput, "addPoints with one point ring unexpectedly succeeded.")
self.assertEqual(polygon.addPointsXY(points[1][0][0:2]), QgsGeometry.InvalidInput, "addPoints with two point ring unexpectedly succeeded.")
self.assertEqual(polygon.addPointsXY(points[1][0][0:3]), QgsGeometry.InvalidInput, "addPoints with unclosed three point ring unexpectedly succeeded.")
self.assertEqual(polygon.addPointsXY([QgsPointXY(4, 0), QgsPointXY(5, 0), QgsPointXY(4, 0)]), QgsGeometry.InvalidInput, "addPoints with 'closed' three point ring unexpectedly succeeded.")

self.assertEqual(polygon.addPoints(points[1][0]), QgsGeometry.Success, "addPoints failed")
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()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
Expand Down Expand Up @@ -1505,38 +1505,38 @@ def testAddPart(self):
# Test adding parts to empty geometry, should become first part
empty = QgsGeometry()
# if not default type specified, addPart should fail
result = empty.addPoints([QgsPointXY(4, 0)])
result = empty.addPointsXY([QgsPointXY(4, 0)])
assert result != QgsGeometry.Success, 'Got return code {}'.format(result)
result = empty.addPoints([QgsPointXY(4, 0)], QgsWkbTypes.PointGeometry)
result = empty.addPointsXY([QgsPointXY(4, 0)], QgsWkbTypes.PointGeometry)
self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result))
wkt = empty.exportToWkt()
expwkt = 'MultiPoint ((4 0))'
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
result = empty.addPoints([QgsPointXY(5, 1)])
result = empty.addPointsXY([QgsPointXY(5, 1)])
self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result))
wkt = empty.exportToWkt()
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.addPoints(points[0][0], QgsWkbTypes.LineGeometry)
result = empty.addPointsXY(points[0][0], QgsWkbTypes.LineGeometry)
self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result))
wkt = empty.exportToWkt()
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.addPoints(points[1][0])
result = empty.addPointsXY(points[1][0])
self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result))
wkt = empty.exportToWkt()
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.addPoints(points[0][0], QgsWkbTypes.PolygonGeometry)
result = empty.addPointsXY(points[0][0], QgsWkbTypes.PolygonGeometry)
self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result))
wkt = empty.exportToWkt()
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.addPoints(points[1][0])
result = empty.addPointsXY(points[1][0])
self.assertEqual(result, QgsGeometry.Success, 'Got return code {}'.format(result))
wkt = empty.exportToWkt()
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)))'
Expand Down

0 comments on commit ca74e39

Please sign in to comment.