Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am trying to insert Polygon data in table then I get an error

The error message is the following:

"Error: geometry contains non-closed rings"

My code is shown below:

CREATE TABLE GhanaRegions (
  Id serial,
  Geometry geometry DEFAULT NULL,
  PRIMARY KEY (Id)
);

INSERT INTO GhanaRegions(Geometry) VALUES (ST_GeomFromText('POLYGON ((-0.024861 10.856,
-0.0250165 10.8561,
-0.0252813 10.8562,
-0.0254853 10.8563,
-0.0256633 10.8565,
-0.0259642 10.8566,
-0.0262956 10.8568,
-0.0265517 10.8572,
-0.0267774 10.8576,
-0.0270798 10.8579,
-0.0273258 10.8581,
0.02766 10.8584))'));
like image 291
Gyan Shukla Avatar asked Feb 01 '16 10:02

Gyan Shukla


1 Answers

The first and the last points must be the same point. If they are different, the ring is not closed and the polygon cannot be built.

Solution: the first point must be used twice, as first and as last point:

INSERT INTO GhanaRegions(Geometry) VALUES (ST_GeomFromText('POLYGON ((
-0.024861 10.856,
-0.0250165 10.8561,
-0.0252813 10.8562,
-0.0254853 10.8563,
-0.0256633 10.8565,
-0.0259642 10.8566,
-0.0262956 10.8568,
-0.0265517 10.8572,
-0.0267774 10.8576,
-0.0270798 10.8579,
-0.0273258 10.8581,
0.02766 10.8584,
-0.024861 10.856
))'));
like image 151
Tom-db Avatar answered Nov 15 '22 09:11

Tom-db