Select to view content in your preferred language

Load a feature layer form a GeoPackage

457
4
Jump to solution
06-18-2024 08:17 AM
GloboGlobo
New Contributor

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.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
nicogis
MVP Frequent Contributor

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);
    }

 

View solution in original post

4 Replies
nicogis
MVP Frequent Contributor

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);
    }

 

MK13
by
Frequent Contributor

@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?

MK13_0-1719277566581.png

 

0 Kudos
GloboGlobo
New Contributor

Thanks so much, that's what I was looking for

0 Kudos
NarelleChedzey
Esri Contributor

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

 

0 Kudos