[postgis-users] Find holes in polygons

Nicolas Ribot nicky666 at gmail.com
Fri May 25 03:19:00 PDT 2007


> Hi,
>
> I look for a PostGIS function which checks if a polygon contains holes. Does
> PostGIS offer this function? If yes, can PostGIS tell where the hole was
> found?
>

NumInteriorRings is your friend:

[from doc]
NumInteriorRings(geometry)

    Return the number of interior rings of the first polygon in the
geometry. Return NULL if there is no polygon in the geometry.

Polygons' interior rings are holes.

What do you mean by "...where the holes was found"
You want the spatial extension of the holes (bbox) ?

If you want the holes' bbox, try:

DumpRings(geometry)

    This is a set-returning function (SRF). It returns a set of
geometry_dump rows, formed by a geometry (geom) and an array of
integers (path). The 'path' field holds the polygon ring index,
contains a single element: 0 for the shell, hole number for holes. The
'geom' field contains the corresponding ring as a polygon.

have a look a the arrays management in postgresql.

Nicolas



More information about the postgis-users mailing list