Skip to content

Commit a86f5ea

Browse files
committedApr 30, 2017
remove PyNames for QgsGeometry::compare methods
single python method with some MethodCode to dispatch to proper cpp methods.
1 parent b0d4a4c commit a86f5ea

File tree

7 files changed

+263
-51
lines changed

7 files changed

+263
-51
lines changed
 

‎python/core/geometry/qgsgeometry.sip

Lines changed: 112 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,45 +1185,123 @@ Ring 0 is outer ring and can't be deleted.
11851185
:rtype: QgsPolygon
11861186
%End
11871187

1188-
static bool compare( const QgsPolyline &p1, const QgsPolyline &p2,
1189-
double epsilon = 4 * DBL_EPSILON ) /PyName=comparePolylines/;
1190-
%Docstring
1191-
Compares two polylines for equality within a specified tolerance.
1192-
\param p1 first polyline
1193-
\param p2 second polyline
1194-
\param epsilon maximum difference for coordinates between the polylines
1195-
:return: true if polylines have the same number of points and all
1196-
points are equal within the specified tolerance
1197-
.. versionadded:: 2.9
1198-
:rtype: bool
1199-
%End
12001188

1201-
static bool compare( const QgsPolygon &p1, const QgsPolygon &p2,
1202-
double epsilon = 4 * DBL_EPSILON ) /PyName=comparePolygons/;
1203-
%Docstring
1204-
Compares two polygons for equality within a specified tolerance.
1205-
\param p1 first polygon
1206-
\param p2 second polygon
1207-
\param epsilon maximum difference for coordinates between the polygons
1208-
:return: true if polygons have the same number of rings, and each ring has the same
1209-
number of points and all points are equal within the specified tolerance
1210-
.. versionadded:: 2.9
1211-
:rtype: bool
1212-
%End
1213-
1214-
static bool compare( const QgsMultiPolygon &p1, const QgsMultiPolygon &p2,
1215-
double epsilon = 4 * DBL_EPSILON ) /PyName=compareMultiPolygons/;
1216-
%Docstring
1217-
Compares two multipolygons for equality within a specified tolerance.
1218-
\param p1 first multipolygon
1219-
\param p2 second multipolygon
1220-
\param epsilon maximum difference for coordinates between the multipolygons
1221-
:return: true if multipolygons have the same number of polygons, the polygons have the same number
1222-
of rings, and each ring has the same number of points and all points are equal within the specified
1189+
static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * DBL_EPSILON );
1190+
%Docstring
1191+
Compares two geometry objects for equality within a specified tolerance.
1192+
The objects can be of type QgsPolyline, QgsPolygon or QgsMultiPolygon.
1193+
The 2 types should match.
1194+
\param p1 first geometry object
1195+
\param p2 second geometry object
1196+
\param epsilon maximum difference for coordinates between the objects
1197+
:return: true if objects are
1198+
- polylines and have the same number of points and all
1199+
points are equal within the specified tolerance
1200+
- polygons and have the same number of points and all
1201+
points are equal within the specified tolerance
1202+
- multipolygons and have the same number of polygons, the polygons have the same number
1203+
of rings, and each ring has the same number of points and all points are equal
1204+
within the specified
12231205
tolerance
12241206
.. versionadded:: 2.9
12251207
:rtype: bool
12261208
%End
1209+
%MethodCode
1210+
{
1211+
sipRes = false;
1212+
int state0;
1213+
int state1;
1214+
int sipIsErr = 0;
1215+
1216+
if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
1217+
PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
1218+
{
1219+
PyObject *o0 = PyList_GetItem( a0, 0 );
1220+
PyObject *o1 = PyList_GetItem( a1, 0 );
1221+
if ( o0 && o1 )
1222+
{
1223+
// compare polyline - polyline
1224+
if ( sipCanConvertToType( o0, sipType_QgsPoint, SIP_NOT_NONE ) &&
1225+
sipCanConvertToType( o1, sipType_QgsPoint, SIP_NOT_NONE ) &&
1226+
sipCanConvertToType( a0, sipType_QVector_0100QgsPoint, SIP_NOT_NONE ) &&
1227+
sipCanConvertToType( a1, sipType_QVector_0100QgsPoint, SIP_NOT_NONE ) )
1228+
{
1229+
QgsPolyline *p0;
1230+
QgsPolyline *p1;
1231+
p0 = reinterpret_cast<QgsPolyline *>( sipConvertToType( a0, sipType_QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1232+
p1 = reinterpret_cast<QgsPolyline *>( sipConvertToType( a1, sipType_QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1233+
if ( sipIsErr )
1234+
{
1235+
sipReleaseType( p0, sipType_QVector_0100QgsPoint, state0 );
1236+
sipReleaseType( p1, sipType_QVector_0100QgsPoint, state1 );
1237+
}
1238+
else
1239+
{
1240+
sipRes = QgsGeometry::compare( *p0, *p1, a2 );
1241+
}
1242+
}
1243+
else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
1244+
PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
1245+
{
1246+
PyObject *oo0 = PyList_GetItem( o0, 0 );
1247+
PyObject *oo1 = PyList_GetItem( o1, 0 );
1248+
if ( oo0 && oo1 )
1249+
{
1250+
// compare polygon - polygon
1251+
if ( sipCanConvertToType( oo0, sipType_QgsPoint, SIP_NOT_NONE ) &&
1252+
sipCanConvertToType( oo1, sipType_QgsPoint, SIP_NOT_NONE ) &&
1253+
sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPoint, SIP_NOT_NONE ) &&
1254+
sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPoint, SIP_NOT_NONE ) )
1255+
{
1256+
QgsPolygon *p0;
1257+
QgsPolygon *p1;
1258+
p0 = reinterpret_cast<QgsPolygon *>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1259+
p1 = reinterpret_cast<QgsPolygon *>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1260+
if ( sipIsErr )
1261+
{
1262+
sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPoint, state0 );
1263+
sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPoint, state1 );
1264+
}
1265+
else
1266+
{
1267+
sipRes = QgsGeometry::compare( *p0, *p1, a2 );
1268+
}
1269+
}
1270+
else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
1271+
PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
1272+
{
1273+
PyObject *ooo0 = PyList_GetItem( oo0, 0 );
1274+
PyObject *ooo1 = PyList_GetItem( oo1, 0 );
1275+
if ( ooo0 && ooo1 )
1276+
{
1277+
// compare multipolygon - multipolygon
1278+
if ( sipCanConvertToType( ooo0, sipType_QgsPoint, SIP_NOT_NONE ) &&
1279+
sipCanConvertToType( ooo1, sipType_QgsPoint, SIP_NOT_NONE ) &&
1280+
sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, SIP_NOT_NONE ) &&
1281+
sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, SIP_NOT_NONE ) )
1282+
{
1283+
QgsMultiPolygon *p0;
1284+
QgsMultiPolygon *p1;
1285+
p0 = reinterpret_cast<QgsMultiPolygon *>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1286+
p1 = reinterpret_cast<QgsMultiPolygon *>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1287+
if ( sipIsErr )
1288+
{
1289+
sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, state0 );
1290+
sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, state1 );
1291+
}
1292+
else
1293+
{
1294+
sipRes = QgsGeometry::compare( *p0, *p1, a2 );
1295+
}
1296+
}
1297+
}
1298+
}
1299+
}
1300+
}
1301+
}
1302+
}
1303+
}
1304+
%End
12271305

12281306
QgsGeometry smooth( const unsigned int iterations = 1, const double offset = 0.25,
12291307
double minimumDistance = -1.0, double maxAngle = 180.0 ) const;

‎scripts/sipify_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ done < <(
4242
${GP}sed -n -r 's/^%Include (.*\.sip)/core\/\1/p' python/core/core.sip
4343
${GP}sed -n -r 's/^%Include (.*\.sip)/gui\/\1/p' python/gui/gui.sip
4444
${GP}sed -n -r 's/^%Include (.*\.sip)/analysis\/\1/p' python/analysis/analysis.sip
45-
${GP}sed -n -r 's/^%Include (.*\.sip)/server\/\1/p' python/analysis/server.sip
45+
${GP}sed -n -r 's/^%Include (.*\.sip)/server\/\1/p' python/server/server.sip
4646
)
4747

4848
echo " => $count files sipified!"

‎src/core/geometry/qgsgeometry.h

Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,8 @@ class CORE_EXPORT QgsGeometry
10421042
*/
10431043
static QgsPolygon createPolygonFromQPolygonF( const QPolygonF &polygon ) SIP_FACTORY;
10441044

1045+
#ifndef SIP_RUN
1046+
10451047
/** Compares two polylines for equality within a specified tolerance.
10461048
* \param p1 first polyline
10471049
* \param p2 second polyline
@@ -1051,7 +1053,7 @@ class CORE_EXPORT QgsGeometry
10511053
* \since QGIS 2.9
10521054
*/
10531055
static bool compare( const QgsPolyline &p1, const QgsPolyline &p2,
1054-
double epsilon = 4 * std::numeric_limits<double>::epsilon() SIP_PYARGDEFAULT( 4 * DBL_EPSILON ) ) SIP_PYNAME( comparePolylines );
1056+
double epsilon = 4 * std::numeric_limits<double>::epsilon() );
10551057

10561058
/** Compares two polygons for equality within a specified tolerance.
10571059
* \param p1 first polygon
@@ -1062,7 +1064,7 @@ class CORE_EXPORT QgsGeometry
10621064
* \since QGIS 2.9
10631065
*/
10641066
static bool compare( const QgsPolygon &p1, const QgsPolygon &p2,
1065-
double epsilon = 4 * std::numeric_limits<double>::epsilon() SIP_PYARGDEFAULT( 4 * DBL_EPSILON ) ) SIP_PYNAME( comparePolygons );
1067+
double epsilon = 4 * std::numeric_limits<double>::epsilon() );
10661068

10671069
/** Compares two multipolygons for equality within a specified tolerance.
10681070
* \param p1 first multipolygon
@@ -1074,7 +1076,124 @@ class CORE_EXPORT QgsGeometry
10741076
* \since QGIS 2.9
10751077
*/
10761078
static bool compare( const QgsMultiPolygon &p1, const QgsMultiPolygon &p2,
1077-
double epsilon = 4 * std::numeric_limits<double>::epsilon() SIP_PYARGDEFAULT( 4 * DBL_EPSILON ) ) SIP_PYNAME( compareMultiPolygons );
1079+
double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1080+
#else
1081+
1082+
/** Compares two geometry objects for equality within a specified tolerance.
1083+
* The objects can be of type QgsPolyline, QgsPolygon or QgsMultiPolygon.
1084+
* The 2 types should match.
1085+
* \param p1 first geometry object
1086+
* \param p2 second geometry object
1087+
* \param epsilon maximum difference for coordinates between the objects
1088+
* \returns true if objects are
1089+
* - polylines and have the same number of points and all
1090+
* points are equal within the specified tolerance
1091+
* - polygons and have the same number of points and all
1092+
* points are equal within the specified tolerance
1093+
* - multipolygons and have the same number of polygons, the polygons have the same number
1094+
* of rings, and each ring has the same number of points and all points are equal
1095+
* within the specified
1096+
* tolerance
1097+
* \since QGIS 2.9
1098+
*/
1099+
static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * DBL_EPSILON );
1100+
% MethodCode
1101+
{
1102+
sipRes = false;
1103+
int state0;
1104+
int state1;
1105+
int sipIsErr = 0;
1106+
1107+
if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
1108+
PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
1109+
{
1110+
PyObject *o0 = PyList_GetItem( a0, 0 );
1111+
PyObject *o1 = PyList_GetItem( a1, 0 );
1112+
if ( o0 && o1 )
1113+
{
1114+
// compare polyline - polyline
1115+
if ( sipCanConvertToType( o0, sipType_QgsPoint, SIP_NOT_NONE ) &&
1116+
sipCanConvertToType( o1, sipType_QgsPoint, SIP_NOT_NONE ) &&
1117+
sipCanConvertToType( a0, sipType_QVector_0100QgsPoint, SIP_NOT_NONE ) &&
1118+
sipCanConvertToType( a1, sipType_QVector_0100QgsPoint, SIP_NOT_NONE ) )
1119+
{
1120+
QgsPolyline *p0;
1121+
QgsPolyline *p1;
1122+
p0 = reinterpret_cast<QgsPolyline *>( sipConvertToType( a0, sipType_QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1123+
p1 = reinterpret_cast<QgsPolyline *>( sipConvertToType( a1, sipType_QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1124+
if ( sipIsErr )
1125+
{
1126+
sipReleaseType( p0, sipType_QVector_0100QgsPoint, state0 );
1127+
sipReleaseType( p1, sipType_QVector_0100QgsPoint, state1 );
1128+
}
1129+
else
1130+
{
1131+
sipRes = QgsGeometry::compare( *p0, *p1, a2 );
1132+
}
1133+
}
1134+
else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
1135+
PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
1136+
{
1137+
PyObject *oo0 = PyList_GetItem( o0, 0 );
1138+
PyObject *oo1 = PyList_GetItem( o1, 0 );
1139+
if ( oo0 && oo1 )
1140+
{
1141+
// compare polygon - polygon
1142+
if ( sipCanConvertToType( oo0, sipType_QgsPoint, SIP_NOT_NONE ) &&
1143+
sipCanConvertToType( oo1, sipType_QgsPoint, SIP_NOT_NONE ) &&
1144+
sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPoint, SIP_NOT_NONE ) &&
1145+
sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPoint, SIP_NOT_NONE ) )
1146+
{
1147+
QgsPolygon *p0;
1148+
QgsPolygon *p1;
1149+
p0 = reinterpret_cast<QgsPolygon *>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1150+
p1 = reinterpret_cast<QgsPolygon *>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1151+
if ( sipIsErr )
1152+
{
1153+
sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPoint, state0 );
1154+
sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPoint, state1 );
1155+
}
1156+
else
1157+
{
1158+
sipRes = QgsGeometry::compare( *p0, *p1, a2 );
1159+
}
1160+
}
1161+
else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
1162+
PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
1163+
{
1164+
PyObject *ooo0 = PyList_GetItem( oo0, 0 );
1165+
PyObject *ooo1 = PyList_GetItem( oo1, 0 );
1166+
if ( ooo0 && ooo1 )
1167+
{
1168+
// compare multipolygon - multipolygon
1169+
if ( sipCanConvertToType( ooo0, sipType_QgsPoint, SIP_NOT_NONE ) &&
1170+
sipCanConvertToType( ooo1, sipType_QgsPoint, SIP_NOT_NONE ) &&
1171+
sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, SIP_NOT_NONE ) &&
1172+
sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, SIP_NOT_NONE ) )
1173+
{
1174+
QgsMultiPolygon *p0;
1175+
QgsMultiPolygon *p1;
1176+
p0 = reinterpret_cast<QgsMultiPolygon *>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1177+
p1 = reinterpret_cast<QgsMultiPolygon *>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1178+
if ( sipIsErr )
1179+
{
1180+
sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, state0 );
1181+
sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPoint, state1 );
1182+
}
1183+
else
1184+
{
1185+
sipRes = QgsGeometry::compare( *p0, *p1, a2 );
1186+
}
1187+
}
1188+
}
1189+
}
1190+
}
1191+
}
1192+
}
1193+
}
1194+
}
1195+
% End
1196+
#endif
10781197

10791198
/** Smooths a geometry by rounding off corners using the Chaikin algorithm. This operation
10801199
* roughly doubles the number of vertices in a geometry.

‎tests/src/python/providertestbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ def testExtent(self):
711711
QgsRectangle(-71.123, 66.33, -65.32, 78.3))
712712
provider_extent = QgsGeometry.fromRect(self.provider.extent())
713713

714-
self.assertTrue(QgsGeometry.comparePolylines(provider_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001))
714+
self.assertTrue(QgsGeometry.compare(provider_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001))
715715

716716
def testUnique(self):
717717
self.assertEqual(set(self.provider.uniqueValues(1)), set([-200, 100, 200, 300, 400]))

‎tests/src/python/test_provider_ogr_gpkg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def testGeopackageExtentUpdate(self):
191191
self.assertTrue(vl.commitChanges())
192192
reference = QgsGeometry.fromRect(QgsRectangle(0.5, 0.0, 1.0, 1.0))
193193
provider_extent = QgsGeometry.fromRect(vl.extent())
194-
self.assertTrue(QgsGeometry.comparePolylines(provider_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001),
194+
self.assertTrue(QgsGeometry.compare(provider_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001),
195195
provider_extent.asPolygon()[0])
196196

197197
# Test deleting a geometry that touches the bbox
@@ -200,7 +200,7 @@ def testGeopackageExtentUpdate(self):
200200
self.assertTrue(vl.commitChanges())
201201
reference = QgsGeometry.fromRect(QgsRectangle(0.5, 0.0, 1.0, 0.5))
202202
provider_extent = QgsGeometry.fromRect(vl.extent())
203-
self.assertTrue(QgsGeometry.comparePolylines(provider_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001),
203+
self.assertTrue(QgsGeometry.compare(provider_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001),
204204
provider_extent.asPolygon()[0])
205205

206206
def testSelectSubsetString(self):

‎tests/src/python/test_provider_wfs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def testWFS10(self):
408408
self.assertEqual(vl.featureCount(), 0)
409409
reference = QgsGeometry.fromRect(QgsRectangle(400000.0, 5400000.0, 450000.0, 5500000.0))
410410
vl_extent = QgsGeometry.fromRect(vl.extent())
411-
assert QgsGeometry.comparePolylines(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt())
411+
assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt())
412412

413413
with open(sanitize(endpoint, '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&TYPENAME=my:typename&SRSNAME=EPSG:32631'), 'wb') as f:
414414
f.write("""
@@ -651,7 +651,7 @@ def testWFS10_latlongboundingbox_in_WGS84(self):
651651

652652
reference = QgsGeometry.fromRect(QgsRectangle(399999.9999999680439942, 5399338.9090830031782389, 449999.9999999987776391, 5500658.0448500607162714))
653653
vl_extent = QgsGeometry.fromRect(vl.extent())
654-
assert QgsGeometry.comparePolylines(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt())
654+
assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt())
655655

656656
def testWFST10(self):
657657
"""Test WFS-T 1.0 (read-write)"""
@@ -2016,7 +2016,7 @@ def testWrongCapabilityExtent(self):
20162016

20172017
reference = QgsGeometry.fromRect(QgsRectangle(2, 49, 2, 49))
20182018
vl_extent = QgsGeometry.fromRect(vl.extent())
2019-
assert QgsGeometry.comparePolylines(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt())
2019+
assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt())
20202020

20212021
# Same with restrictToRequestBBOX=1
20222022
vl = QgsVectorLayer("url='http://" + endpoint + "' typename='my:typename' version='2.0.0' restrictToRequestBBOX=1", 'test', 'WFS')
@@ -2157,15 +2157,15 @@ def testGeomedia(self):
21572157
# Extent before downloading features
21582158
reference = QgsGeometry.fromRect(QgsRectangle(243900.3520259926444851, 4427769.1559739429503679, 1525592.3040170343592763, 5607994.6020106188952923))
21592159
vl_extent = QgsGeometry.fromRect(vl.extent())
2160-
assert QgsGeometry.comparePolylines(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt())
2160+
assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt())
21612161

21622162
# Download all features
21632163
features = [f for f in vl.getFeatures()]
21642164
self.assertEqual(len(features), 2)
21652165

21662166
reference = QgsGeometry.fromRect(QgsRectangle(500000, 4500000, 510000, 4510000))
21672167
vl_extent = QgsGeometry.fromRect(vl.extent())
2168-
assert QgsGeometry.comparePolylines(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt())
2168+
assert QgsGeometry.compare(vl_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001), 'Expected {}, got {}'.format(reference.exportToWkt(), vl_extent.exportToWkt())
21692169
self.assertEqual(features[0]['intfield'], 1)
21702170
self.assertEqual(features[1]['intfield'], 2)
21712171

‎tests/src/python/test_qgsgeometry.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def testSimplifyIssue4189(self):
340340
"""Test we can simplify a complex geometry.
341341
342342
Note: there is a ticket related to this issue here:
343-
https://issues.qgis.org/issues/4189
343+
http://hub.qgis.org/issues/4189
344344
345345
Backstory: Ole Nielson pointed out an issue to me
346346
(Tim Sutton) where simplify ftools was dropping
@@ -1671,7 +1671,7 @@ def testConvertToType(self):
16711671
assert compareWkt(expWkt, wkt), "convertToType failed: from multiline to polygon. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
16721672

16731673
def testRegression13053(self):
1674-
""" See https://issues.qgis.org/issues/13053 """
1674+
""" See http://hub.qgis.org/issues/13053 """
16751675
p = QgsGeometry.fromWkt('MULTIPOLYGON(((62.0 18.0, 62.0 19.0, 63.0 19.0, 63.0 18.0, 62.0 18.0)), ((63.0 19.0, 63.0 20.0, 64.0 20.0, 64.0 19.0, 63.0 19.0)))')
16761676
assert p is not None
16771677

@@ -1680,7 +1680,7 @@ def testRegression13053(self):
16801680
assert compareWkt(expWkt, wkt), "testRegression13053 failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
16811681

16821682
def testRegression13055(self):
1683-
""" See https://issues.qgis.org/issues/13055
1683+
""" See http://hub.qgis.org/issues/13055
16841684
Testing that invalid WKT with z values but not using PolygonZ is still parsed
16851685
by QGIS.
16861686
"""
@@ -1692,7 +1692,7 @@ def testRegression13055(self):
16921692
assert compareWkt(expWkt, wkt), "testRegression13055 failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
16931693

16941694
def testRegression13274(self):
1695-
""" See https://issues.qgis.org/issues/13274
1695+
""" See http://hub.qgis.org/issues/13274
16961696
Testing that two combined linestrings produce another line string if possible
16971697
"""
16981698
a = QgsGeometry.fromWkt('LineString (0 0, 1 0)')
@@ -1711,7 +1711,7 @@ def testReshape(self):
17111711
wkt = g.exportToWkt()
17121712
assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
17131713

1714-
# Test reshape a geometry involving the first/last vertex (https://issues.qgis.org/issues/14443)
1714+
# Test reshape a geometry involving the first/last vertex (http://hub.qgis.org/issues/14443)
17151715
g.reshapeGeometry([QgsPoint(0.5, 1), QgsPoint(0, 0.5)])
17161716

17171717
expWkt = 'Polygon ((0 0.5, 0 0, 1 0, 1 0.5, 0.5 1, 0 0.5))'
@@ -4114,6 +4114,21 @@ def testCentroid(self):
41144114
self.assertTrue(compareWkt(result, exp, 0.00001),
41154115
"centroid: mismatch using QgsAbstractGeometry methods Input {} \n Expected:\n{}\nGot:\n{}\n".format(t[0], exp, result))
41164116

4117+
def testCompare(self):
4118+
lp = [QgsPoint(1, 1), QgsPoint(2, 2), QgsPoint(1, 2), QgsPoint(1, 1)]
4119+
lp2 = [QgsPoint(1, 1.0000001), QgsPoint(2, 2), QgsPoint(1, 2), QgsPoint(1, 1)]
4120+
self.assertTrue(QgsGeometry.compare(lp, lp)) # line-line
4121+
self.assertTrue(QgsGeometry.compare([lp], [lp])) # pylygon-polygon
4122+
self.assertTrue(QgsGeometry.compare([[lp]], [[lp]])) # multipyolygon-multipolygon
4123+
# handling empty values
4124+
self.assertFalse(QgsGeometry.compare(None, None))
4125+
self.assertFalse(QgsGeometry.compare(lp, [])) # line-line
4126+
self.assertFalse(QgsGeometry.compare([lp], [[]])) # pylygon-polygon
4127+
self.assertFalse(QgsGeometry.compare([[lp]], [[[]]])) # multipolygon-multipolygon
4128+
# tolerance
4129+
self.assertFalse(QgsGeometry.compare(lp, lp2))
4130+
self.assertTrue(QgsGeometry.compare(lp, lp2, 1e-6))
4131+
41174132

41184133
if __name__ == '__main__':
41194134
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.