Opened 4 years ago
Closed 4 years ago
#4755 closed defect (invalid)
ST_Transform of valid polygon can produce invalid polygon
Reported by: | rouen | Owned by: | pramsey |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 3.1.0 |
Component: | postgis | Version: | 3.0.x |
Keywords: | ST_Transform | Cc: |
Description
Using ST_Transform to change SRID from 3857 to 4326 can produce invalid (self-intersecting) polygon from valid one.
Test case (this is simplified land polygon from OSM dataset):
WITH sample AS (
SELECT ST_GeomFromText('MULTIPOLYGON(((2382720.17390635 9089461.95191981,2382367.6918707 9089034.6330938,2383639.33894183 9088936.19228217,2383491.66250535 9088320.85158849,2382449.73433542 9088378.30497631,2382055.93050479 9088845.95402014,2381571.89109492 9088566.99620937,2382909.16100587 9087525.07043225,2383385.00730122 9087713.76366274,2382367.6918707 9086433.9341019,2383007.61196353 9086589.80403919,2382892.75251293 9086056.52215661,2383387.76802459 9086009.53671596,2384109.85303357 9086307.94844515,2383500.05599495 9084868.129924,2384106.96985876 9084899.76660559,2383959.29342227 9083792.17446382,2384344.89300643 9083513.24218185,2383385.00730122 9082274.42190291,2382950.18223823 9082971.7746775,2381932.87793967 9082873.34378008,2382088.74749067 9084563.39240152,2382671.24899015 9084481.35648623,2382310.2621454 9085268.94495686,2381481.64438374 9084021.89443657,2381875.44821437 9082331.85126724,2382523.57255366 9081798.56835936,2381982.09228655 9079919.82309238,2381916.46944672 9081101.23196672,2381645.72931316 9081019.18678447,2381350.37644019 9078295.40449812,2380538.16717147 9079558.84194849,2381055.03469917 9081757.55388556,2380267.42703791 9082643.61171947,2380710.45634737 9083168.68945391,2379931.06406453 9083021.01509475,2379233.7142464 9083759.36841078,2378442.67794482 9082959.88657981,2378604.00215088 9083424.05072713,2377563.78830111 9083562.16830069,2377341.87289622 9083907.25370813,2377807.53345815 9084052.13288586,2376895.52626593 9084309.0425308,2376862.720412 9084932.57788238,2377600.28996214 9085547.16258457,2376452.50808842 9085383.80323754,2376772.47370081 9086351.87675873,2377839.0034782 9086934.37453989,2379594.6899592 9089526.88193449,2380136.17022631 9089494.07408576,2379758.77488863 9090478.570831,2380341.26525615 9089937.0906658,2380251.02967691 9090511.38319048,2379397.79917583 9090659.06515612,2379307.55246464 9091061.06154116,2380316.65251674 9092365.52577592,2381383.19342608 9091717.39068873,2381227.31274312 9092652.66570207,2381670.34205258 9093128.5061353,2382991.20347059 9091815.82075834,2381965.6837936 9091020.04296678,2382195.4026948 9090019.11564374,2380972.99223445 9088796.72250146,2381941.08218614 9089764.79230159,2382720.17390635 9089461.95191981)))', 3857) AS geom
) SELECT ST_IsValid(sample.geom), ST_IsValid(ST_Transform(sample.geom, 4326)) FROM sample
Version info: POSTGIS="3.0.1 ec2a9aa" [EXTENSION] PGSQL="120" GEOS="3.7.1-CAPI-1.11.1 27a5e771" PROJ="Rel. 4.9.3, 15 August 2016" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.2.1" WAGYU="0.4.3 (Internal)"
Change History (2)
comment:1 by , 4 years ago
comment:2 by , 4 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
This is because there is a very narrow "gore" in the polygon, and due to rounding effects the transformation perturbs the coordinates forming the gore just enough to introduce a self-intersection.
One way to remove the self-intersection is to round the geometry to a lower precision.
ST_SnapToGrid(transform_geom, 0.0000001)
makes the geometry valid in this case.