Yesterday someone told me that Geoalchemy was a good choice to support spatial extensions if I want to use Sqlalchemy. It really did good. Thanks for him a lot.
But I have not found a convenient way to create spatial index with Geoalchemy. Must I run this SQL directly?
CREATE SPATIAL INDEX sp_index ON my_class (
geom_col
);
Is there a convenient way to do it without directly writing the SQL?
Thanks!
When creating a table with table.create()
GeoAlchemy will automatically create an index for the geometry column.
Also, SQLAlchemy Index
instances have a create
method. See the "Indexes" section in http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#metadata-constraints. I'm not sure if you'll be able to create a spatial index in MySQL with that but it's worth a try.
With GeoAlchemy, there are 2 steps you should take to create Spatial Index on the geometry column
- add attr 'spatial_index' to the geometry column
- Call the GeometryDDL extension
Example:
# note that spatial_index will set the column to not null
class Building(Base):
geom = GeometryColumn(Point(2, spatial_index=True))
GeometryDDL(Building.__table__)
来源:https://stackoverflow.com/questions/10462455/is-there-a-convenient-way-to-create-spatial-index-with-sqlalchemy-or-geoalchemy