2

From the docs on ST_SubDivide()

Turns a single geometry into a set in which each element has fewer than the maximum allowed number of vertices. Useful for converting excessively large polygons and other objects into small portions that fit within the database page size. Uses the same envelope clipping as ST_ClipByBox2D does, recursively subdividing the input geometry until all portions have less than the maximum vertex count. Minimum vertice count allowed is 8 and if you try to specify lower than 8, it will throw an error.

If one does this..

SELECT ST_Union(geom)
FROM (
  SELECT ST_SubDivide(geom)
  FROM tbl
  WHERE id = 1
) AS t;

Should the resulting ST_Union( ST_SubDivide(geom) ) be the same? What exactly does envelope clipping mean? Are we losing area or detail?

  • You mean that would the result of unioning the subdivisions be exactly the same as the original geometry? With complex multipolygons I would not be surprised if some fragments of the internal boundaries which are created by ST_SubDevide would remain after ST_Union. The result could then be a multipolygon with more members than the original, or even a GeometryCollection. – user30184 Jan 5 '17 at 7:53
  • That sounds horrifyingly un-useful. Is ST_SubDivide supposed to ease the breaking up a polygons for faster computation? If so, being subject to precision errors, and other things like the above sounds like it would totally mitigate the effectiveness of this... – Evan Carroll Jan 5 '17 at 8:02
  • I do not know if that happens. By experience complex multipolygons which can have half a million vertices or more tend to be hard to handle and therefore I would not be surprised. Do you have an example where round-tripping gives a different result? – user30184 Jan 5 '17 at 8:04
  • @user30184 gis.stackexchange.com/q/223362/6052 – Evan Carroll Jan 5 '17 at 8:47
3

In theory ST_Union(ST_Subdivide(geom)) should return exactly the same geometry as what you started with. In practice because of floating point precision it may be slightly different.

Envelope clipping is some internal geos algorithm. ST_ClipByBox2D was invented first and ST_SubDivide piggy-backed on the same logic from GEOS, which I assume involves breaking things into rectangles in some fashion.

Nope you aren't loosing any area or detail, just trading a geometry with many vertices for smaller geometries with fewer vertices.

  • If I have use case where they're not the same, it's a rounding error? – Evan Carroll Jan 5 '17 at 5:11
  • rounding error Or a bug. I would compare the resulting areas or lengths (if it's a linestring) and see how off they are. If it's not off by much, it's just a floating point error. Early in the development I did catch where it left off fragments, but those issues were fixed before official release, or at least I couldn't trigger after the fix. – LR1234567 Jan 5 '17 at 5:18
  • I'm using complex polygons from census data. I'll write a whole question then about how to work around this, and ask whether or not it's a bug. I'm unsure how to simplify it but I can provide a verbose test case and question, it's public data. – Evan Carroll Jan 5 '17 at 5:20

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.