iggy
iggy

Reputation: 1743

Postgis declare a polygon from a text string

I would like to declare a regular polygon, in this case a square without duplicated points. The problem is that the following statement returns 5, but one would expect 4.

SELECT ST_NPoints(ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'));

But without the last point I get an error

ERROR: geometry contains non-closed rings

What am I missing?

Upvotes: 0

Views: 342

Answers (1)

Mike T
Mike T

Reputation: 43642

In the GIS world, polygons are formed using LinearRings, which are closed LineStrings. To be closed, the start and end points must be identical. So with the GIS convention, a triangle has four points, a square has five points, etc.

More here.

Upvotes: 1

Related Questions