I have looked at examples online on how to create a geometry field with peewee and this is what I came up with so far:
class GeometryField(Field):
db_field = 'geometry'
def db_value(self, value):
return fn.ST_GeomFromGeoJSON(value)
def python_value(self, value):
return fn.ST_AsGeoJSON(value)
I have added this definition to a table like so:
class GeoJSON(BaseModel):
geojson_id = UUIDField(primary_key=True, default=uuid.uuid4)
geometry = GeometryField()
Now, this thing wouldn't run and I don't understand what I missed to make it happen. My aim is to manage insertions of geometric entities into the DB so that later I can make use of PostGIS to query based on locations.
The error I'm getting in the init phase:
peewee.ProgrammingError: syntax error at or near "NOT" LINE 1: ...geojson_id" UUID NOT NULL PRIMARY KEY, "geometry" NOT NULL)
I init the table like so:
GeoJSON.create_table("geojsons")
What did I miss here? Did I need to do anything else before this geometryfield can be used? Is there a secret geom field that Peewee supports out of the box that I don't know about?