Opened 5 years ago
Closed 4 years ago
#4636 closed defect (fixed)
ST_Subdivide degrade data
Reported by: | sirsosp | Owned by: | strk |
---|---|---|---|
Priority: | high | Milestone: | PostGIS GEOS |
Component: | postgis | Version: | 2.5.x -- EOL |
Keywords: | Cc: |
Description
I use the ST_Subdivide function very often without problem but for a dataset, I get a completely unexpected degraded result.
Attachments (5)
Change History (22)
by , 5 years ago
Attachment: | st_subdivide_bug.PNG added |
---|
by , 5 years ago
Attachment: | test2_for_stsubdivide_202002071354.sql.zip added |
---|
comment:1 by , 5 years ago
here is the SQL Query to reproduce the issue :
DROP TABLE IF EXISTS data_olivier.test_for_stsubdivide_processed; CREATE TABLE data_olivier.test_for_stsubdivide_processed AS SELECT ST_Multi(ST_Subdivide(geom,500))::geometry(MultiPolygon , 2154) AS geom, cod19niv4, cod19niv5 FROM data_olivier.test2_for_stsubdivide ;
follow-up: 5 comment:2 by , 5 years ago
I'm afraid ST_Subdivide uses intersection heavily, which is an algorithm that does not avoid creating new vertices, which in turn is prone to degradation/collapses.
Ideally we'd have an algorithm to only split at vertices, such functionality is currently completely missing from PostGIS core (C implmentation).
comment:3 by , 5 years ago
Did you see the screenshot st_subdivide_bug.PNG in attached file ? It seems that there is a kind of snaptogrid.
comment:4 by , 5 years ago
Kind of snaptogrid is what you get when floating precision operation can't complete due to some robustness issue (lines almost parallel that intersect, usually).
Even if the problem occurs on a very small portion of the geometry, precision reduction is applied to the whole geometry, incrementally, until the operation succeeds.
comment:5 by , 5 years ago
Hi, Perhaps our company could help and fund this feature, just let me know how contact. Thx !
Replying to strk:
Ideally we'd have an algorithm to only split at vertices, such functionality is currently completely missing from PostGIS core (C implmentation).
comment:6 by , 5 years ago
Milestone: | PostGIS 2.5.4 → PostGIS 2.5.5 |
---|
comment:8 by , 5 years ago
The new JTS overlay code is almost complete and will be ready to port shortly. This might provide the reliable intersection required.
comment:9 by , 4 years ago
Milestone: | PostGIS 2.5.5 → PostGIS 3.1.0 |
---|
comment:10 by , 4 years ago
Great news. Trying the OverlayNG implementation not only returns a non-degraded output but also does so in 13 seconds rather than 9 minutes !
I'm attaching the resulting subdivided data. And an image comparing old and new generation overlay outputs in a random spot.
by , 4 years ago
Attachment: | comparison.png added |
---|
Comparing old and new generation GEOS Overlay outputs
by , 4 years ago
Attachment: | test_for_stsubdivide_processed_overlayng.sql.gz added |
---|
Processing output with OverlayNG
comment:11 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
I've enabled debugging of BinaryOp in GEOS to find out what was going on and I found that in one of the recursive intersection cases all the heuristics fail until geometry precision reduction step is entered. The precision reduction starts with a grid of 1e-16 and grows the grid by 10 everytime the intersection fails with a topology exception. The biggest grid eventually succeeding is 1, which is visible in the output as a grid.
This also explains the time difference, as it basically takes 16 attempts only in the precision reduction step, not counting earlier attempts with snapping and common-bits removal…
More stats: precision reduction is engaged 26 times. Of these, 2 times we have to get down to 1 as a grid size (I guess this is due to using the same middle-line for the binary subdivision of the same input polygon). All the other 24 cases work at the very first 1e-16 grid size.
comment:12 by , 4 years ago
Interesting enough (Martin, are you reading this?) the OverlayNG code also requires (in a single case) multiple iterations over the precision reduction loop, but succeeds earlier (succeeds at 1e-10).
comment:13 by , 4 years ago
The OverlayNGSnapIfNeeded instead succeeds after the first snapping, never entering precision reduction
comment:14 by , 4 years ago
@strk: good news that OverlayNGSnapIfNeeded works first time. The new snapping heuristic works very well. How does performance compare?
What is the final resolution of this? Are you working on a new ST_Subdivide that will use OverlayNG?
comment:15 by , 4 years ago
Performance is great, but it's comparing to the performance of entering the GEOS heuristic so not sure it is a valid comparison.
I'm working on exposing an ST_Subdivide taking a gridSize parameter to opt-in for the OverlayNG (it's an opt-in because of the Z drop)
comment:16 by , 4 years ago
Milestone: | PostGIS 3.1.0 → PostGIS GEOS |
---|
Moving to GEOS milestone as it is expected that 3.9 will fix the issue.
input data