
image.png
有些情況會遇見一些多邊形帶有孔洞,這些帶有孔洞的多邊形,屬于較為復雜的多邊形,在有些情況下進行計算難以進行。最近找到一個簡單的方法處理,使用st_exteriorring與ST_BuildArea
geometry ST_ExteriorRing(geometry a_polygon);
Returns a line string representing the exterior ring of the POLYGON geometry. Return NULL if the geometry is not a polygon.
ST_ExteriorRing這個函數(shù)是返回多邊形的外邊界,是不管內部情況的。但是只支持polygon類型。
SELECT st_exteriorring(geom) geom from split_polygon csp where csp.name='aaa';

image.png
根據(jù)外邊界再重新生成多邊形的話,就生成了不帶內環(huán)的多邊形了。
SELECT ST_BuildArea(st_exteriorring(geom)) geom from split_polygon csp where csp.name='aaa';

image.png
從最終結果來看,效果是很好的,最主要的是簡單。以后再遇到這種有孔洞的多邊形,也容易處理。同時想要外邊界也容易。但是只支持polygon類型,當然可以將MultPolygon拆解成polygon再處理。具體操作可以看postgis Multi類型轉simple類型