1

I am new to GeoDjango. I have created Admin interface for my Model. It loads correctly. I am also able to draw the Polygon on map(At client side) but when I save It tells me Invalid input and throws some error in console.

Model

from django.contrib.gis import models


Poly(models.Model):
    poly_gon = models.Polygone()
    objects = models.GeoManager()

Admin interface

from django.contrib.gis import admin
from myapp.models import Poly


admin.site.register(Poly)

Error at Client side(On the polygon field in red colour)

"Invalid geometry value."

Error at server side(in terminal, after starting server with runserver command)

Error in server side: GEOS_ERROR: ParseException: Expected 'Z', 'M', 'ZM', 'EMPTY' or '(' but encountered : ')'

GEOS_ERROR: ParseException: Expected 'Z', 'M', 'ZM', 'EMPTY' or '(' but encountered : ')'

Error creating geometry from value 'SRID=4326;POLYGON()' (Error encountered checking Geometry returned from GEOS C function "GEOSWKTReader_read_r".)

I was able to enter data to my Poly from shell by following code.

from django.contrib.gis.geos import GEOSGeometry
from myapp.models import Poly
p = Poly(poly_gon=GEOSGeometry("""POLYGON((-87.6705551147461 41.89135645852043, -87.64171600341797 41.89288988217029, -87.63690948486328 41.880110226947934, -87.66368865966797  41.87806524488436, -87.68016815185547 41.887267148816726, -87.6705551147461 41.89135645852043))"""))
p.save()
2
  • How are you saving the polygon on the map side? Also, maybe this is just a typo in the question but you have models.Polygone written down.
    – djq
    Mar 10 '15 at 1:54
  • From your error message my guess is that you are pasting the geometry wrongly in the admin interface. For instance, in the admin, you should add the geometry without the quotes. What exactly are you putting into the form on the admin site?
    – yellowcap
    Mar 10 '15 at 18:59
2

admin.site.register(Poly, admin.GeoModelAdmin)

or

admin.site.register(Poly, admin.OSMGeoAdmin) # for openstreet map

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.