I need a strategy for bulk loading a shape file into a SQLite db.
Didn’t find a sample on it and the feature source only expose a GetAllFeatures() member.
I would prefer a DataReader pattern for this task.
Is it an option exist in MapSuite?
Regards
Peter
Loading a shape file to SQLite
Hi Peter,
Map Suite supports both Shape file and Sqlite
data formats, also including the conversion between them as well, but one
requirement is that we need some codes here, just shown as following:
ShapeFileFeatureSource shapefileFeatureSource =
new
ShapeFileFeatureSource(@
"File Path Name"
, ShapeFileReadWriteMode.ReadOnly);
shapefileFeatureSource.Open();
SqliteFeatureSource sqliteFeatureSource =
new
SqliteFeatureSource(@
"Data Source=..."
,
"table_name"
,
"id"
,
"geometry"
);
sqliteFeatureSource.Open();
// Insert data from a shapefile into the new database
sqliteFeatureSource.BeginTransaction();
for
(
int
i = 1; i < shapefileFeatureSource.GetCount(); i++)
{
Feature feature = shapefileFeatureSource.GetFeatureById(i.ToString(),ReturningColumnsType.AllColumns);
sqliteFeatureSource.AddFeature(feature);
}
sqliteFeatureSource.CommitTransaction();
Thanks,
Johnny
Hi Johnny,
Elegant solution - right on spot.
But are featureIds guaranteed to be continuous in [1 … FeatureCount]?
What happens if a feature was deleted from the shape file in the middle of the sequence prior to this import (I don’t know the history of all the files I’m planning to import…)?
Thanks,
Peter
Hi Peter,
All these problems have been taken into account, thus if you are using ShapeFielFeatureSource, the featureIds will be guaranteed to be continuous, the deleted or invalid records will be skipped as well.
Thanks,
Johnny