Changeset: c9dad0b3b0f5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c9dad0b3b0f5
Modified Files:
        geom/sql/conformance/Tests/T48.test
        geom/sql/conformance/Tests/T49.test
        geom/sql/conformance/Tests/T8.test
        testing/sqllogictest.py
Branch: Dec2025
Log Message:

Normalize order of coordinates in POLYGON.


diffs (65 lines):

diff --git a/geom/sql/conformance/Tests/T48.test 
b/geom/sql/conformance/Tests/T48.test
--- a/geom/sql/conformance/Tests/T48.test
+++ b/geom/sql/conformance/Tests/T48.test
@@ -1,5 +1,5 @@
 query T rowsort
 SELECT ST_AsText(ST_Difference(named_places.boundary, forests.boundary)) FROM 
named_places, forests WHERE named_places.name = 'Ashton' AND forests.name = 
'Green Forest'
 ----
-POLYGON ((84 48, 84 42, 56 34, 62 48, 84 48))
+POLYGON ((56 34, 62 48, 84 48, 84 42, 56 34))
 
diff --git a/geom/sql/conformance/Tests/T49.test 
b/geom/sql/conformance/Tests/T49.test
--- a/geom/sql/conformance/Tests/T49.test
+++ b/geom/sql/conformance/Tests/T49.test
@@ -1,5 +1,5 @@
 query T rowsort
 SELECT ST_AsText(ST_Union(shore, boundary)) FROM lakes, named_places WHERE 
lakes.name = 'Blue Lake' AND named_places.name = 'Goose Island'
 ----
-POLYGON ((66 23, 73 9, 48 6, 52 18, 66 23))
+POLYGON ((48 6, 52 18, 66 23, 73 9, 48 6))
 
diff --git a/geom/sql/conformance/Tests/T8.test 
b/geom/sql/conformance/Tests/T8.test
--- a/geom/sql/conformance/Tests/T8.test
+++ b/geom/sql/conformance/Tests/T8.test
@@ -1,5 +1,5 @@
 query T rowsort
 SELECT ST_AsText(boundary) FROM named_places WHERE name = 'Goose Island'
 ----
-POLYGON ((67 13, 67 18, 59 18, 59 13, 67 13))
+POLYGON ((59 13, 67 13, 67 18, 59 18, 59 13))
 
diff --git a/testing/sqllogictest.py b/testing/sqllogictest.py
--- a/testing/sqllogictest.py
+++ b/testing/sqllogictest.py
@@ -64,6 +64,9 @@ ptszre = re.compile(r'-?\d+(?:\.\d+)? -?
 # geos 3.13 introduced parentheses around EMPTY in MULTIPOLYGON (but not
 # in all cases)
 geosere = re.compile(r'MULTIPOLYGON \(EMPTY\)')
+# ordering of coordinates in POLYGONs may differ
+polyre = re.compile(r'POLYGON \(\((?P<coords>((\d+(\.\d+)?) (\d+(\.\d+)?))'
+                    r'(, ((\d+(\.\d+)?) (\d+(\.\d+)?)))+)\)\)')
 
 architecture = platform.machine()
 if architecture == 'AMD64':     # Windows :-(
@@ -577,6 +580,21 @@ class SQLLogic:
                     if res is not None:
                         col = col[:res.start(0)] + 'MULTIPOLYGON EMPTY' \
                             + col[res.end(0):]
+                    res = polyre.search(col)
+                    if res is not None:
+                        # normalize order of coordinates in POLYGON
+                        coords = res.group('coords')
+                        points = coords.split(', ')
+                        if points[0] == points[-1]:
+                            s = 0
+                            for i in range(len(points)):
+                                if points[i] < points[s]:
+                                    s = i
+                            if s != i:
+                                points = points[s:-1] + points[0:s+1]
+                                col = col[:res.start('coords')] \
+                                    + ', '.join(points) \
+                                    + col[res.end('coords'):]
                 nrow.append(col)
             ndata.append(nrow)
         data = ndata
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to