Hi,
A SQLite feature source has five tables in a database. It has the "main" XXXXXXX table with attributes and four idx_XXXXXXX_geometry_XXX tables.
Could you please provide us with a DELETE query which allows to delete features by a where clause in SQLIte?
Do you have a query which allows to delete all feature source related tables from a SQLite database and vacuum the data?
I think it is OK to add and populate a main table column in SQLite and use it in the Map Control layer search or style settings, but please confirm this.
Do you have a code sample to delete SQLite feature by a where clause? Query and delete features one by one in a loop could take a lot of time if we need to delete thousands of features.
Thanks,
Gene
Bulk update OSM data in SQLite
Hi Gene,
Please try following code to delete features by a where clause.
featureLayer.FeatureSource.ExecuteNonQuery(sqlStatement);
One thing please remember is to delete the index table after
deleting the features in main table. For example:
featureLayer.FeatureSource.ExecuteNonQuery("delete from osm_road5m_linestring where id=137150"); //Delete features from main table.
featureLayer.FeatureSource.ExecuteNonQuery("delete from idx_osm_road5m_linestring_geometry where id=137150"); // Delete index records from index table.
But it prefers to delete features by transactions just like the
following:
featureLayer.FeatureSource.BeginTransaction();
for (int i = 0; i < ids.Length; i++)
{
string id = ids;
featureLayer.FeatureSource.DeleteFeature(id);
if (i % 200 == 0)
{
featureLayer.FeatureSource.CommitTransaction();
featureLayer.FeatureSource.BeginTransaction();
}
}
featureLayer.FeatureSource.CommitTransaction();
Did you mean that the style of the features are based on the
value, if so, please see: “ClassBreakStyle”
or “ValueStyle”.
Any misunderstood something here please let me know.
Thanks,
Peter
Peter,
I don’t want to develop a tool to delete features in a SQLite database. I would like to delete features in the SQLite Browser or in the sqlite3.exe command shell by a where clause. And usually I don’t know features IDs.
Does it mean that the following queries will delete features and clean related data in all five tables, if first somehow I get features ID by a where clause?
delete from TABLENAME where ID in (xxxxxxxxxx)
//Delete features from main table.
delete from idx_TABLENAME
_geometry where ID in (xxxxxxxxxx) // Delete index records from index table.
Thanks,
Gene
Hi Gene,
The following query scripts which are used to delete features from “mian table” and “index table” work fine with map suite, also it’s same to what we have done in our products.
delete from TABLENAME where ID in (xxxxxxxxxx) //Delete features from main table.
delete from idx_TABLENAME _geometry where ID in (xxxxxxxxxx) // Delete index records from index table.
Thanks,
Peter
Thank you Peter,
What about the _node, _parent, and _rowid tables? Does it mean that these tables’ rows will be deleted somehow automatically? I don’t see any triggers in the OSM SQLite database.
Thanks,
Gene
Any updates on this?
Thanks,
Gene
Hi Gene,
Sorry for the delay on this.
Those three tables are automatically generated from the using the RTREE module in SQLite. That module will maintain those three tables, no need to delete from them.
So please recreate the spatial index after committing the changes. There are two options to do this:
1. Use the SQL command.
2. Call the "SQLiteFeatureSource.CreateSpatialIndex" method.
More information: sqlite.org/rtree.html
Thanks,
Peter
Thank you Peter. I’ll try both these ways.
Gene,
Please let us know if any updates.
Thanks,
Troy