I have a
spatialite data set without a spatial index on the geometry column and I would like to create it.
OGR command line I can use the following to create it (OGR Spatialite driver):
ogrinfo db.sqlite -sql "SELECT CreateSpatialIndex('the_table','GEOMETRY')"
I would like to do this using the
python bindings instead and I have tried to mimic the command line procedure:
driver = ogr.GetDriverByName('SQLite') data_source = driver.CreateDataSource('db.sqlite', ['SPATIALITE=YES']) layer = data_source.CreateLayer('the_table', None, ogr.wkbLineString25D, ['SPATIAL_INDEX=NO']) data_source.ExecuteSQL('SELECT CreateSpatialIndex(\'the_table\', \'' + layer.GetGeometryColumn() + '\'')
The above returns the error message:
ERROR 1: In ExecuteSQL(): sqlite3_prepare_v2(SELECT CreateSpatialIndex('the_table', 'GEOMETRY'): near "'GEOMETRY'": syntax error
What should I do different to make this work?
The answer to the obvious question, "why do I create a spatialite file without the spatial index just to create it afterwards?" is because I need to do bulk insertion.