createSpatialIndex method

void createSpatialIndex(
  1. TableName tableName,
  2. String geometryName
)

Create a spatial index

@param e feature entry to create spatial index for

Implementation

void createSpatialIndex(TableName tableName, String geometryName) {
  if (!_supportsRtree) {
    // if no rtree is supported, the spatial index can't work.
    return;
  }
  String? pk = _sqliteDb.getPrimaryKey(tableName);
  if (pk == null) {
    throw new IOException(
        "Spatial index only supported for primary key of single column.");
  }

  var sqlList = GPKG_SPATIAL_INDEX;

  _sqliteDb.transaction((_db) {
    for (var sqlString in sqlList) {
      sqlString = sqlString.replaceAll("TTT", tableName.fixedName);
      sqlString = sqlString.replaceAll("CCC", geometryName);
      sqlString = sqlString.replaceAll("III", pk);
      _sqliteDb.execute(sqlString);
    }
  });
}