|
| 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