5

I have several detailed contiguous areas. I need to turn each one into KML, but when I do so, the end result is too large (in terms of memory). Using PostGIS I need to simplify these geometries but keep them contiguous.

I have tried calling ST_SimplifyPreserveTopology with a GEOMETRYCOLLECTION created by ST_Collect, but the areas are no longer contiguous.

Previously I think I have succeeded in simplifying areas while at the same time keeping shared borders in line with each other by using desktop applications. However, I am looking for a way to do the same using PostGIS.

  • 4
    ST_PreserveTopology targets individual polygons and aims to avoid simplifications that would create self-intersection and the like, due to a polygon's inner rings being simplified separately from the outer ring. This is of no use with adjacent polygons, so can't be done with Postgis. One option is to instead convert your data to TopoJSON and use the simplify command line tool. The reason this works is because TopoJSON stores arcs, not polygons directly, so a change to an arc, will be reflected in all adjacent polygons. – John Powell Mar 15 '16 at 14:58
  • @JohnBarça Just to clarify, did you mean to say ST_SimplifyPreserveTopology (and does what you say apply to ST_Simplify as well as ST_SimplifyPreserveTopology)? – zod Mar 15 '16 at 15:24
  • Sorry, yes, I did. And, ST_Simplify does not even preserve the topology of individual polygons. – John Powell Mar 15 '16 at 15:36
  • 1
    Did you see this question ..particularly the response from Paul Ramsey? – elrobis Mar 15 '16 at 17:37
  • thanks @elrobis. I had seen other similar posts (that were not postgis). all sounds a bit frightening, as it seems to lose the connection between the geometry and its data, only to reconnect them at the end using ST_PointOnSurface (what guarantee is there that that point will be in both shapes, when we just changed one of their shapes?). – zod Mar 15 '16 at 19:15
5

You can simplify your polygons using two ways:

  • Without topology support: just transform polygones to lines, simplify, rebuild the polygons and reattach attributes with Point in Polygon. You will find a first recipe on the PostGIS wiki

  • With topology support. There is another recipe available on the PostGIS wiki. IMO, it's the recommended way.

In both case, for simplifying, you can choose the ST_Simplify and ST_SimplifyPreserveTopology functions based on Douglas-Peucker algorithm or the ST_SimplifyVW function based on the Visvalingam-Whyatt algorithm if you use PostGIS 2.2+.

  • Thank you. The second method looks promising to me. Right now I have been given a simplified source, which solves my problem for the moment. I shall probably return to this later. – zod Mar 18 '16 at 9:12
3

I have posted another solution on my blog at www.spheraware.com/blog/post/late-tessellate. This approach is still a work in progress but it has been effective for me. You simplify first and then fix the alignment problems. It's much faster than the "disassemble-simplify-reassemble" recipe and there is no need to create a topology or additional tables.

2

You can use ST_SnapToGrid(geom,0.01) to align all your vertices to a grid with a certain precision (0.01 in the example). There is the risk of losing small geometries or creating complex geometries though, so find out first how much precision your data needs in the first place. Also, it assumes the vertices of adjacent faces are at exactly the same location.

Reference: http://postgis.net/docs/ST_SnapToGrid.html

  • Thanks. I did try this snap to grid method. Either the grid was too large, and shapes became rectangles, or there were still gaps. – zod Mar 18 '16 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.