How to actually use geoalchemy
The Notes for Spatialite section of the geoalchemy docs are not quite right.
The first three steps work OK… and by the way use this download link.
Ignore pyspatialite… it is a red herring that doesn’t install out of PIP because the setup script is based on parsing the front page of the SpatiaLite website for download links (which is dumb).
The final set up steps in the application look like this:
from sqlalchemy import create_engine from pysqlite2 import dbapi2 engine = create_engine('sqlite:////home/james/code/hg/PyCDS/pycds/data/crmp.sqlite', module = dbapi2, echo=True) x = engine.raw_connection() x.connection.enable_load_extension(True) cur = x.connection.execute("select load_extension('/usr/lib64/libspatialite.so')") res = cur.execute("Select st_x(the_geom) from meta_history") res.fetchall() # answers!
I’m not sure how to do this with sessions yet… maybe like this:
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from pysqlite2 import dbapi2 engine = create_engine('sqlite:////home/james/code/hg/PyCDS/pycds/data/crmp.sqlite', module = dbapi2, echo=True) session = sessionmaker(bind=engine)() session.connection().connection.enable_load_extension(True) session.execute("select load_extension('/usr/lib64/libspatialite.so')") res = session.execute("Select st_x(the_geom) from meta_history") res.fetchall() # answers!
Yup, that’s it.
blog comments powered by Disqus