Is there a convenient way to create spatial index with Sqlalchemy or Geoalchemy?

我怕爱的太早我们不能终老 提交于 2019-12-04 16:21:19

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__)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!