[GIS] dissolve / ST_Union function that will close gaps between features

dissolvepostgisunion

I've been reading a number of related threads about ST_Union, ST_SnapToGrid and ST_Dump but I haven't been able to solve my problem.

The problem is I am trying to merge Tiger/line census tracts that have been simplified but I get gaps where the tracts aren't flush. I simplified the tracts with ST_SimplifyPreserveTopology(geom, .0003) and I'm running ST_Union(ST_SnapToGrid(geom, .00001)) but I still get gaps. I've also tried using ST_SnapToGrid around of the initial simplification but I don't see a difference. I've also tried wrapping ST_Dump around the Union but I don't see a difference there either.

I thought ST_ExteriorRing was promising but my GROUP BY creates three concentric polygons (doughnuts) and ST_ExteriorRing seems to create three overlapping circles. Unless I'm doing something wrong.

I'm outputting my query as geojson and putting that on a leaflet map. Here is what those gaps look like at different zoom levels.

enter image description here
enter image description here
enter image description here

If anyone has any ideas on making a gapless polygon of census tracts under 80mb I'm all ears.

Best Answer

I found a much easier way to simplify a shapefile while preserving its topology by using the node.js command-line library mapshaper https://github.com/mbloch/mapshaper. You could also use topojson on the command line https://github.com/mbostock/topojson/wiki/Command-Line-Reference, but that will output only in topojson. Mapshaper outputs to a variety of formats.