Menu
  • HOME
  • TAGS

How to create a migration script to add a Geometry column in SQLAlchemy-Migrate?

flask,flask-sqlalchemy,sqlalchemy-migrate,flask-migrate,geoalchemy2

If you are following Miguel Grinberg's tutorial you are using SQLite database. GeoAlchemy2 – if I'm not wrong – supports only PostgreSQL/PostGIS, as @dirn pointed out in the comment. The solution would be to get a PostgreSQL server running. SQLAlchemy deals fine with PostreSQL. Once you got it, just edit your...

Representing Coordinates in GeoAlchemy2

python,geoalchemy2

That would be in the Well-Known Binary format; you can use the geoalchemy2.functions.ST_AsText to convert them to the WKT text format. This would work in the database itself, thus you'd apply this to your query to ask for the results in WKT instead of WKB; that is in your SQLAlchemy...

How to order a geospatial query by distance from the query point

sqlalchemy,flask-sqlalchemy,geoalchemy2

Alright, I figured it out, but wow that wasn't obvious, especially if you're not intimately familiar with Geoalchemy2. In my case above, you have to tack: .order_by(func.ST_Distance(cls.geoLoc, geo)) to the end of the code that's in my question. Basically, ST_Distance is a function that takes in a two points and...