
image.png
有些情況會(huì)遇見一些多邊形帶有孔洞,這些帶有孔洞的多邊形,屬于較為復(fù)雜的多邊形,在有些情況下進(jìn)行計(jì)算難以進(jìn)行。最近找到一個(gè)簡(jiǎn)單的方法處理,使用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這個(gè)函數(shù)是返回多邊形的外邊界,是不管內(nèi)部情況的。但是只支持polygon類型。
SELECT st_exteriorring(geom) geom from split_polygon csp where csp.name='aaa';

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

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