1

I am currently working on a project that involves storing polygons in a GeoDjango field. I am using Google Maps to draw the polygons, but I am encountering an error when I try to save them. The error message is

django.contrib.gis.geos.error.GEOSException: Error encountered checking Geometry returned from GEOS C function "GEOSWKTReader_read_r

Specifically, I am able to save polygons in this format: 'POLYGON ((66.98106581568717 30.179605233947377,66.97718849521253 30.176396998548686,66.98106581568717 30.179605233947377))', but I am unable to save polygons in this format: 'POLYGON((66.98707396388053 30.176192128250534,66.98281566332209 30.17265923177731,66.9889954728924 30.17028474252859))'.

How can I modify the format of the polygon so that it can be saved in the GeoDjango field without encountering the error message?

4
  • Neither of those strings is valid Well-Known Text. A Polygon must have at least four vertices, with the first and last being the same location. Commented Apr 24, 2023 at 0:30
  • @Vince So how to modify the polygon format to meet the requirements for a valid Well-Known Text format ? Can you provide an example of a valid Well-Known Text format for a polygon with four or more vertices? Are there any you recommend for converting a polygon to a valid Well-Known Text format because i am drawing polygon on "google map using google map api".? Are there any other common mistakes or issues to be aware of when working with Well-Known Text formats and polygons in GeoDjango? Commented Apr 24, 2023 at 20:42
  • @Vince Please note that I am able to save a polygon with three vertices (points) in the format by drawing it in the admin panel without encountering any errors. The first example I provided was drawn in the admin panel. Commented Apr 24, 2023 at 20:42
  • The first example is a degenerate polygon (a line that doubles back on itself). The second one fails because it does not close. Neither is a valid Polygon, but the second is treated as an error. Note that it's the same format, but different values in that format. WKT is vague on orientation, but exterior rings generally wrap counterclockwise. The second would likely not fail if the first vertex were repeated as the fourth vertex. Commented Apr 24, 2023 at 22:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.