Hi all,
is it possible to load a Feature Layer from a GeoPackage without adding it to the map ?
I'm using ArcGIS Pro SKD version 3.2 with Visual Studio 2022.
Solved! Go to Solution.
In ArcGIS Pro 3.3 you can load using similar code
string path = "c:\Temp\dbgt.gpkg";
var datastore = new Database(new SQLiteConnectionPath(path))
var database = _datastore as Database;
IReadOnlyList<string> tableNames = database.GetTableNames();
foreach (string tableName in tableNames)
{
QueryDescription queryDescription = database.GetQueryDescription(tableName);
TableDefinition tableDefinition = database.GetDefinition(queryDescription);
if (queryDescription.IsSpatialQuery())
{
FeatureClass b = (FeatureClass)database.OpenTable(queryDescription);
}
else
{
Table a = database.OpenTable(queryDescription);
}
In ArcGIS Pro 3.3 you can load using similar code
string path = "c:\Temp\dbgt.gpkg";
var datastore = new Database(new SQLiteConnectionPath(path))
var database = _datastore as Database;
IReadOnlyList<string> tableNames = database.GetTableNames();
foreach (string tableName in tableNames)
{
QueryDescription queryDescription = database.GetQueryDescription(tableName);
TableDefinition tableDefinition = database.GetDefinition(queryDescription);
if (queryDescription.IsSpatialQuery())
{
FeatureClass b = (FeatureClass)database.OpenTable(queryDescription);
}
else
{
Table a = database.OpenTable(queryDescription);
}
@nicogis I get the error below when I attempt to open a table in snowflake. Do you know what would be a good solution for the error?
Thanks so much, that's what I was looking for
Sometimes there is other data that is in the geopackage file (for example raster data) that is not returned by the Database.GetTableNames method.
In this instance you could use the the ItemFactory and Item classes to obtain the content. Here's an example snippet.
var otherUris = new List<Uri>();
var tableUris = new List<Uri>();
var item = ItemFactory.Instance.Create(gpkgPath, ItemFactory.ItemType.PathItem);
var children = item.GetItems();
foreach (var child in children)
{
var childPath = child.Path;
if (child.TypeID == "sqlite_table")
tableUris.Add(new Uri(childPath));
else
otherUris.Add(new Uri(childPath));
}
// now use LayerFactory and StandloneTableFactory to
// create layers / tables