postgis多边形去孔洞

8667322-90e814fa0c4f786f.png
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这个函数是返回多边形的外边界,是不管内部情况的。但是只支持polygon类型。

SELECT st_exteriorring(geom) geom from split_polygon csp where csp.name='aaa';
8667322-c1483bb7ebc09cca.png
image.png

根据外边界再重新生成多边形的话,就生成了不带内环的多边形了。

SELECT ST_BuildArea(st_exteriorring(geom)) geom from split_polygon csp where csp.name='aaa';

8667322-6978b9e426883448.png
image.png

从最终结果来看,效果是很好的,最主要的是简单。以后再遇到这种有孔洞的多边形,也容易处理。同时想要外边界也容易。但是只支持polygon类型,当然可以将MultPolygon拆解成polygon再处理。具体操作可以看postgis Multi类型转simple类型

转载自:https://blog.csdn.net/weixin_34019144/article/details/87379130

You may also like...