I have OSM data stored in PostGIS.

After running the following query:

select st_astext(st_forcepolygonccw(st_transform(geom,32633))), st_geometrytype(geom) from osm_versions.polygon_v1
limit 10

I get this result.

As you may see only 2 out of 10 spatial objects consist of more than 1 node yet all of them have GeometryType ST_Polygon. As a polygon is "a plane figure that is described by a finite number of straight line segments connected to form a closed polygonal chain" (after Wikipedia) I have no use for "polygons" with less than 3 nodes.

My questions are: Is there any command that returns, given a set of geometries, a subset of geometries that consists of more than 2 nodes? How should I proceed in order to filter out "polygons" with less than 3 nodes?

As for the question how come that points are counted as polygons, I have no idea as the data were provided by an external source.

  • 1
    Your premise is flawed. A polygon geometry is defined by four vertices (the last must be identical to the first).
    – Vince
    Apr 17, 2020 at 13:06
  • I know, yet I have "polygons" with 1 node. And I got a problem. If my question are badly formulated, then please, do feel free to reformulate them and edit my post. As for the "3 nodes" I forgot about the "closing node", but it should have no practical consequences as points consists of 1 node, lines of 2 and polygons, as you said, of al least 4, thus 4 is the only number in this context that islarger than 3.
    – Bartors
    Apr 17, 2020 at 13:11
  • 3
    Select the ones having ST_IsValid='true'. OSM has also invalid polygons which have enough vertices but no area because the vertices are along a line.
    – user30184
    Apr 17, 2020 at 13:15
  • 1
    Thanks, would you mind writing an answer so I can accept it?
    – Bartors
    Apr 17, 2020 at 13:32

1 Answer 1


You can filter out polygons with too few vertices and also geometries which are invalid for any other reason with a PostGIS function ST_IsValid

OSM data often contains for example polygons which have enough vertices but no area because the vertices are located along a line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.