Name

ST_RemoveSmallParts — Removes small parts (polygon rings or linestrings) of a geometry.

Synopsis

geometry ST_RemoveSmallParts(geometry geom, double precision minSizeX, double precision minSizeY);

Descrição

Returns a geometry without small parts (exterior or interior polygon rings, or linestrings).

This function can be used as preprocessing step for creating simplified maps, e. g. to remove small islands or holes.

It evaluates only geometries of type (MULTI)POLYGON and (MULTI)LINESTRING. Other geometries remain unchanged.

If minSizeX is greater than 0, parts are sorted out if their width is smaller than minSizeX.

If minSizeY is greater than 0, parts are sorted out if their height is smaller than minSizeY.

Both minSizeX and minSizeY are measured in coordinate system units of the geometry.

For polygon types, evaluation is done separately for each ring which can lead to one of the following results:

  • the original geometry,

  • a POLYGON with all rings with less vertices,

  • a POLYGON with a reduced number of interior rings (having possibly less vertices),

  • a POLYGON EMPTY, or

  • a MULTIPOLYGON with a reduced number of polygons (having possibly less interior rings or vertices), or

  • a MULTIPOLYGON EMPTY.

For linestring types, evaluation is done for each linestring which can lead to one of the following results:

  • the original geometry,

  • a LINESTRING with a reduced number of vertices,

  • a LINESTRING EMPTY,

  • a MULTILINESTRING with a reduced number of linestrings (having possibly less vertices), or

  • a MULTILINESTRING EMPTY.

Example: ST_RemoveSmallParts() applied to a multi-polygon. Blue parts remain.

Availability: 3.5.0

Exemplos

SELECT ST_AsText(
                        ST_RemoveSmallParts(
                        ST_GeomFromText('MULTIPOLYGON(
                                ((60 160, 120 160, 120 220, 60 220, 60 160), (70 170, 70 210, 110 210, 110 170, 70 170)),
                                ((85 75, 155 75, 155 145, 85 145, 85 75)),
                                ((50 110, 70 110, 70 130, 50 130, 50 110)))'),
                                50, 50));
                
                st_astext
                ---------
                        MULTIPOLYGON(((60 160,120 160,120 220,60 220,60 160)),((85 75,155 75,155 145,85 145,85 75)))
                
SELECT ST_AsText(
                        ST_RemoveSmallParts(
                        ST_GeomFromText('LINESTRING(10 10, 20 20)'),
                                50, 50));
                
                st_astext
                ---------
                        LINESTRING EMPTY