Using peewee ORM with spatialite databases?

المشرف العام

Administrator
طاقم الإدارة
I would like to use the peewee orm in front of some Spatialite databases. Getting peewee to connect to a Spatialite database was relatively simple, and basically boiled down to:

class SpatialiteDatabase(SqliteExtDatabase): def __init__(self, *args, **kwargs): super(SpatialiteDatabase, self).__init__(*args, **kwargs) self.load_extension('mod_spatialite') def initialize_connection(self, conn): LOG.warn('initializing spatialite metadata') self.execute_sql('select InitSpatialMetadata(1);')playhouse.db_url.schemes['spatialite'] = SpatialiteDatabaseSo, great, now we can get a connection to a database with the Spatialiteextension enabled. But I'm not clear how to create Peewee models withgeometry columns, since unlike in, say, PostGIS, Spatialite requiresthe use of particular SQL functions (like AddGeometryColumn) tomanipulate tables.

Ultimately, I would like to be able to write a model something like this:

class Placemark(Model): id = PrimaryKeyField() name = TextField() alias = CharField(20) geom = GeometryField(srid=4326, geom_type='POINT')And get the equivalent of:

CREATE TABLE "placemark" ( "id" INTEGER NOT NULL PRIMARY KEY, "name" TEXT NOT NULL, "alias" VARCHAR(20) NOT NULL,);SELECT AddGeometryColumn("placemark", "geom", 4326, "POINT", "XY");My best option so far has been to populate the geometry fields manually after the fact.



أكثر...
 
أعلى