Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ST_ConcaveHull of MultiPolygon returns disconnected result #1212

Open
nbvfgh opened this issue Dec 23, 2024 · 3 comments
Open

ST_ConcaveHull of MultiPolygon returns disconnected result #1212

nbvfgh opened this issue Dec 23, 2024 · 3 comments
Labels

Comments

@nbvfgh
Copy link

nbvfgh commented Dec 23, 2024

Considering following MultiPolygon:

SELECT ST_GeomFromText('MULTIPOLYGON (((0 0, 1 0, 2 1, 1 1, 0 0)), 
					((8 2, 8 4, 10 4, 10 2, 8 2)),
					((4 9, 5 9, 5 8, 4 8, 4 9)))');

图片

We calculate its concave shell with ST_ConcaveHull(geom, param_pctconvex, param_allow_holes):
As described in the document, the param_pctconvex controls the concaveness of the computed hull. A value of 0 produces a hull with maximum concaveness (but still a single polygon). And often values between 0.3 and 0.1 produce reasonable results.

Case param_pctconvex = 0.47:

WITH mp AS(
	SELECT ST_GeomFromText('MULTIPOLYGON (((0 0, 1 0, 2 1, 1 1, 0 0)), 
		                      ((8 2, 8 4, 10 4, 10 2, 8 2)),
		                      ((4 9, 5 9, 5 8, 4 8, 4 9)))'
	) geom
)
SELECT ST_AsText(ST_ConcaveHull(mp.geom, 0.47,false)),
	   ST_ConcaveHull(mp.geom, 0.47,false) from mp;

-- result:{ MULTIPOLYGON(((10 4,10 2,8 2,2 1,8 4,4 8,4 9,5 9,10 4)),((1 1,2 1,1 0,0 0,1 1))) }

图片

Case param_pctconvex = 0.25:

WITH mp AS(
	SELECT ST_GeomFromText('MULTIPOLYGON (((0 0, 1 0, 2 1, 1 1, 0 0)), 
		                      ((8 2, 8 4, 10 4, 10 2, 8 2)),
		                      ((4 9, 5 9, 5 8, 4 8, 4 9)))'
	) geom
)
SELECT ST_AsText(ST_ConcaveHull(mp.geom, 0.25,false)),
	   ST_ConcaveHull(mp.geom, 0.25,false) from mp;

-- result:{ MULTIPOLYGON(((8 4,4 8,4 9,5 9,5 8,8 4)),((2 1,8 4,10 4,10 2,8 2,2 1)),((1 1,2 1,1 0,0 0,1 1))) }

图片

Case param_pctconvex = 0:

WITH mp AS(
	SELECT ST_GeomFromText('MULTIPOLYGON (((0 0, 1 0, 2 1, 1 1, 0 0),(0 0, 1 1, 2 1, 0 0)), 
		                      ((8 2, 8 4, 10 4, 10 2, 8 2)),
		                      ((4 9, 5 9, 5 8, 4 8, 4 9)))'
	) geom
)
SELECT ST_AsText(ST_ConcaveHull(mp.geom, 0,false)),
	   ST_ConcaveHull(mp.geom, 0,false) from mp;

-- result:{ MULTIPOLYGON(((0 0,1 0,2 1,1 1,0 0)),((8 2,8 4,10 4,10 2,8 2)),((4 9,5 9,5 8,4 8,4 9))) }

图片

The above three examples do not meet expectations. When param_pctconvex is set to 0, it even degenerates into three original polygons

Version Info:
GEOS="3.13.0-CAPI-1.19.0

@nbvfgh
Copy link
Author

nbvfgh commented Dec 23, 2024

To add, when converted into a set of points, the result is as expected.

WITH mp AS(
	SELECT ST_GeomFromText('MULTIPOLYGON (((0 0, 1 0, 2 1, 1 1, 0 0)), 
		                      ((8 2, 8 4, 10 4, 10 2, 8 2)),
		                      ((4 9, 5 9, 5 8, 4 8, 4 9)))'
	) geom
)
SELECT ST_AsText(ST_ConcaveHull(ST_Points(mp.geom), 0,false)),
	   ST_ConcaveHull(ST_Points(mp.geom), 0,false) from mp;

-- result: { POLYGON((4 8,4 9,5 9,5 8,10 4,10 2,8 2,1 0,0 0,1 1,2 1,8 4,4 8)) }

图片

@nbvfgh nbvfgh changed the title ST_ConcaveHull gives unexpected result with MultiPolygon ST_ConcaveHull gives unexpected results of MultiPolygon Dec 23, 2024
@dr-jts dr-jts changed the title ST_ConcaveHull gives unexpected results of MultiPolygon ST_ConcaveHull of MultiPolygon returns disconnected result Dec 23, 2024
@dr-jts
Copy link
Contributor

dr-jts commented Dec 23, 2024

This is a limitation of the current algorithm. It can produce disconnected results for low threshold values.

It is possible to fix this, at the cost of some performance. It requires checking that the internal triangulation remains connected after each triangle "erosion".

@dr-jts dr-jts added the Bug label Dec 23, 2024
@nbvfgh
Copy link
Author

nbvfgh commented Dec 24, 2024

Thanks for your prompt reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants