I have an isochrones layer and I want to calculate the population lays on the overlapping regions.
My first step is to create an intersection between all the isochrones. After that, I try to create a union with the intersections.
Unfortunately, ST_Union throws GEOSUnaryUnion: TopologyException
.
I've checked that all the geometries used for the union are valid.
Union query:
select st_union(the_geom) from isochrones_intersection;
ERROR: GEOSUnaryUnion: TopologyException: Input geom 0 is invalid: Self-intersection at or near point 2.3739051999999998 48.544292458332933 at 2.3739051999999998 48.544292458332933
Check geometries:
select count(*) from isochrones_intersection where st_isvalid(the_geom)=false;
count
-------
0
(1 row)
Here a pg_dump of isochrones_intersection
layer
I've tried several workarounds without success:
- Reproject the layer to 3857.
- ST_SnapToGrid to reduce precision.
Something similar appears at this post, but it looks they implemented a workaround which it's not useful for me.
I agree it's not an easy union.
EDIT
Adding versions:
PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6), 64-bit
POSTGIS="2.4.4 r16869" PGSQL="100" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.9.1, 04 March 2015" GDAL="GDAL 2.2.2, released 2017/09/15" LIBXML="2.9.4" LIBJSON="0.11" TOPOLOGY RASTER
I've also created a smaller version of the layer with the issue
Any ideas?