Skip to content

Commit a58746c

Browse files
authored
Merge pull request #732 from hafenkran/fix/mvt-ring-orientation
fix ring orientation for ST_AsMVTGeom and add orientation tests
2 parents fbd5681 + b50c9e2 commit a58746c

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/spatial/modules/geos/geos_module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ struct ST_AsMVTGeom {
366366
if (!bind_data.clip) {
367367

368368
// But first orient in place
369-
snapped.orient_polygons(true);
369+
snapped.orient_polygons(false);
370370

371371
res_data[out_idx] = lstate.Serialize(result, snapped);
372372
continue;
@@ -389,7 +389,7 @@ struct ST_AsMVTGeom {
389389
auto cleaned_clipped = clipped.get_gridded(1.0);
390390

391391
// Also orient the polygons in place
392-
cleaned_clipped.orient_polygons(true);
392+
cleaned_clipped.orient_polygons(false);
393393

394394
res_data[out_idx] = lstate.Serialize(result, cleaned_clipped);
395395
}

test/sql/mvt/st_asmvtgeom.test

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# name: test/sql/mvt/st_asmvtgeom.test
2+
# description: Test that ST_AsMVTGeom produces correct ring orientation according to MVT spec
3+
# group: [mvt]
4+
5+
require spatial
6+
7+
# Verify that ST_AsMVTGeom produces CW exterior rings in tile coordinates
8+
#
9+
# Input: CCW Polygon in geographic coordinates (Y-up)
10+
# Expected: CW Polygon in tile coordinates (Y-down)
11+
# MVT Spec: "Exterior rings must be oriented clockwise [...] (when viewed in screen coordinates)"
12+
query I
13+
SELECT ST_AsText(
14+
ST_AsMVTGeom(
15+
ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'),
16+
ST_Extent(ST_GeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))')),
17+
4096
18+
)
19+
);
20+
----
21+
POLYGON ((2048 4096, 0 4096, 0 2048, 2048 2048, 2048 4096))
22+
23+
# Verify Polygon with holes
24+
#
25+
# Input: Polygon with CCW exterior and CW hole in geographic coordinates (Y-up)
26+
# Expected: Exterior is CW in screen coords (Y-down), interior is CCW (per MVT spec)
27+
query I
28+
SELECT ST_AsText(
29+
ST_AsMVTGeom(
30+
ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 3 1, 3 3, 1 3, 1 1))'),
31+
ST_Extent(ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))')),
32+
4096
33+
)
34+
);
35+
----
36+
POLYGON ((4096 4096, 0 4096, 0 0, 4096 0, 4096 4096), (1024 1024, 1024 3072, 3072 3072, 3072 1024, 1024 1024))
37+
38+
# Verify Multi-Polygon
39+
#
40+
# Input: Two CCW polygons in geographic coordinates (Y-up)
41+
# Expected: Both polygons are CW in screen coords (Y-down)
42+
query I
43+
SELECT ST_AsText(
44+
ST_AsMVTGeom(
45+
ST_GeomFromText('MULTIPOLYGON(((0 0, 1 0, 1 1, 0 1, 0 0)), ((2 2, 3 2, 3 3, 2 3, 2 2)))'),
46+
ST_Extent(ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))')),
47+
4096
48+
)
49+
);
50+
----
51+
MULTIPOLYGON (((1024 4096, 0 4096, 0 3072, 1024 3072, 1024 4096)), ((3072 2048, 2048 2048, 2048 1024, 3072 1024, 3072 2048)))

0 commit comments

Comments
 (0)