LuciadCPillar C# 2024.0.01
Luciad.Formats.Geopackage.GeoPackageModelDecoder Class Reference

This class is a factory that provides new instances of a Model. More...

Static Public Member Functions

static Luciad.Models.Model Decode (Luciad.Formats.Geopackage.GeoPackageDataSource dataSource)
 Creates a model for a OGC GeoPackage file. More...
 
static Luciad.Models.Model Decode (Luciad.Formats.Geopackage.GeoPackageDataSource dataSource, Luciad.Formats.Geopackage.GeoPackageModelDecoderOptions options)
 Creates a model for a OGC GeoPackage file. More...
 
static System.Collections.Generic.IList< Luciad.Formats.Geopackage.GeoPackageTableMetadataDiscoverTables (string source, bool includeUnsupportedDataTypes)
 Discovers the available tables in the given source file. More...
 

Detailed Description

This class is a factory that provides new instances of a Model.

This specific model can be either a IFeatureModel or a IRasterModel giving the ability to access the data within a GeoPackage file.

Member Function Documentation

◆ Decode() [1/2]

static Luciad.Models.Model Luciad.Formats.Geopackage.GeoPackageModelDecoder.Decode ( Luciad.Formats.Geopackage.GeoPackageDataSource  dataSource)
inlinestatic

Creates a model for a OGC GeoPackage file.

Parameters
dataSourceThe data source description to use for data retrieval.
Returns
the decoded model for the GeoPackage table.
Exceptions
System.IO.IOExceptionwhen decoding the GeoPackage file fails.

◆ Decode() [2/2]

static Luciad.Models.Model Luciad.Formats.Geopackage.GeoPackageModelDecoder.Decode ( Luciad.Formats.Geopackage.GeoPackageDataSource  dataSource,
Luciad.Formats.Geopackage.GeoPackageModelDecoderOptions  options 
)
inlinestatic

Creates a model for a OGC GeoPackage file.

Supported versions

The GeoPackage decoder allows decoding files following the OGC GeoPackage specification.

  • OGC GeoPackage files, compliant with version 1.0.1 of the OGC GeoPackage specification.
  • OGC GeoPackage files, compliant with version 1.1.0 of the OGC GeoPackage specification.
  • OGC GeoPackage files, compliant with version 1.2.1 of the OGC GeoPackage specification.
  • OGC GeoPackage files, compliant with version 1.3.0 of the OGC GeoPackage specification.

Supported tables

The supported table types are

One table at a time
A GeoPackage file is a SQLite database file which can contain several tables with different kinds of information such as Features, Attributes and Tiles. The model supports decoding features and raster data (tiles table). If no table name is specified the first table of one of the supported table types is used.

Use the method GeoPackageModelDecoder.DiscoverTables to retrieve the list of tables within the GeoPackage file.

Feature data

Supported geometries
The basic simple geometry types as defined in the GeoPackage specification as Geometry Type Codes (Core) are all supported. The table below lists all supported geometry types and how their geometry is available in the feature model.
Geometry Type Codes Description for geometry in model
Point Point
LineString Polyline
CircularString CircularArcBy3Points (or a collection of...)
Polygon Polygon
MultiPoint MultiGeometry with Point sub-geometries
MultiLineString MultiGeometry with Polyline sub-geometries
MultiPolygon MultiGeometry with Polygon sub-geometries
GeometryCollection MultiGeometry
Custom geometries extension
On top of the geometries from the GeoPackage specifications a few additional geometries are supported by Luciad.
Custom Geometry Type Codes Description for geometry in model
LcdCircle Patch with CircleByCenterPoint as base geometry
LcdEllipse Patch with Ellipse as base geometry
LcdEllipticalArc EllipticalArc

For curve geometries there is an implicit curve interpolation based on the type of Coordinate Reference System (CRS). When the CRS is a geodetic coordinate reference, e.g. WGS84, the interpolation is geodesic, otherwise the curve interpolation is linear.

Remarks
The decoder does not support the full specification. The following paragraphs list the restrictions.
Type conversions
The data model supports a set of basic data types, i.e., Integer, Double and Text. The SQLite data types are converted into data model types in a way that you don't lose information except for the following types INTEGER 6,8 and TEXT UTF-16BE, UTF-16LE.
Elevation & measure
GeoPackage can store feature table geometries with or without optional elevation (Z) and/or measure (M). Support is limited to decoding 2D/3D coordinates, the measure (M) value is not supported and is skipped.
Extension mechanism support
The feature model supports the "gpkg_rtree_index" (embedded rtree spatial indices) GeoPackage extension to generate more efficient SQL spatial queries. Other GeoPackage extensions are not supported or exploited at this stage.
Query filtering support
A FeatureQuery expression filter can be used to order and filter the features that has to be loaded in memory. The filtering is done by the database and only the resulted features are loaded in memory.
Caching
Current implementation of the GeoPackage model does not perform any internal caching to improve performance. It means that all the consecutive queries (even if they are identical) are always executed against the database. It may result in a poor visual performance in some scenarios where the big number of features are constantly queried.
Editing
The feature model can be made editable using the GeoPackageModelDecoderOptions. The decoded model's IFeatureModel.GetUpdater method returns an IFeatureModelUpdater which can be used to modify the model. Changes to the model are not automatically persisted into the gpkg file, persisting is done using the FeatureModelPersistenceManager, accessed using IFeatureModel.GetPersistenceManager.
Editing limitations
Editing currently does not change the GeoPackage's metadata, only the feature's table itself (and the related RTree tables if present). Features that would violate the constraints of the GeoPackage can't be added. Specifically:
  • Features holding a geometry that require a missing extension can't be added.
  • If the measure value is defined as mandatory by the GeoPackage file, features can't be added. This is also true for updates that don't affect the geometry. Removing features is still possible in this case.
  • If the GeoPackage file's 'geometry_type_name' restricts allowed geometry types, features holding a geometry of a disallowed type can't be added.
Id conflicts
If there are any id conflicts between the in-memory data and the GeoPackage file itself, the conflicting in-memory features get new ids assigned to them when the changes are persisted. The observers are notified of these changes.

One way conflicts can happen is if features wich already have an id are added to the model; for performance reasons the uniqueness of the id is only checked against the in-memory features, not against those in the GeoPackage file. Until the conflict is resolved by persisting the changes, the shadowed features in the GeoPackage file are not visible (i.e. they don't appear in query results).

Raster data

Image data

The following tile formats are supported:

  • PNG
  • JPEG
  • WebP
Elevation data

A sub-set of the Tiled Gridded Coverage Data, version 1.0, extension is supported to read elevation data.

The following elevation data formats are supported:

  • PNG
  • TIFF
Tile Matrix Set limitations.
Only tile matrix sets with a quad-tree structure are supported.

Coordinate references

Decoding of GeoPackage files is limited to coordinate references supported by the CoordinateReferenceProvider.Create method.

Example usage:

string source = @"test\resources\Data\GeoPackage\cities.gpkg";
try
{
var tables = GeoPackageModelDecoder.DiscoverTables(source, false);
Console.WriteLine("The GeoPackage file contains " + tables.Count + " table(s):");
foreach (var table in tables)
{
Console.WriteLine(" * Table '" + table.Name + "'");
{
var dataSource = GeoPackageDataSource.NewBuilder()
.Source(source)
.TableName(table.Name)
.Build();
try
{
Model model = GeoPackageModelDecoder.Decode(dataSource);
IFeatureModel featureModel = model as IFeatureModel;
QueryCallbackCounter callback = new QueryCallbackCounter();
featureModel.Query(FeatureQuery.All(), callback);
Console.WriteLine("contains " + callback.Count + " features.");
}
catch (IOException e)
{
Console.WriteLine("could not be decoded: " + e.Message);
}
}
else
{
Console.WriteLine("contains raster data.");
}
}
}
catch (IOException e)
{
Console.WriteLine("Failed to load GeoPackage file " + source + ": " + e.Message);
}
Describes a data source for GeoPackage.
Definition: GeoPackageDataSource.cs:18
string Source
The absolute path to the GeoPackage file.
Definition: GeoPackageDataSource.cs:81
static Luciad.Formats.Geopackage.GeoPackageDataSource.Builder NewBuilder()
Returns the builder class for creation of the GeoPackage data source.
Definition: GeoPackageDataSource.cs:55
This class is a factory that provides new instances of a Model.
Definition: GeoPackageModelDecoder.cs:17
static System.Collections.Generic.IList< Luciad.Formats.Geopackage.GeoPackageTableMetadata > DiscoverTables(string source, bool includeUnsupportedDataTypes)
Discovers the available tables in the given source file.
Definition: GeoPackageModelDecoder.cs:30
static Luciad.Models.Model Decode(Luciad.Formats.Geopackage.GeoPackageDataSource dataSource)
Creates a model for a OGC GeoPackage file.
Definition: GeoPackageModelDecoder.cs:47
Provides information about a GeoPackage table.
Definition: GeoPackageTableMetadata.cs:14
static string TypeFeatures
Type identifier for features.
Definition: GeoPackageTableMetadata.cs:51
Parameters
dataSourceThe data source description to use for data retrieval.
optionsOptions for decoding GeoPackage data, e.g. an option to make a feature model editable.
Returns
the decoded model for the GeoPackage table.
Exceptions
System.IO.IOExceptionwhen decoding the GeoPackage file fails.

◆ DiscoverTables()

static System.Collections.Generic.IList< Luciad.Formats.Geopackage.GeoPackageTableMetadata > Luciad.Formats.Geopackage.GeoPackageModelDecoder.DiscoverTables ( string  source,
bool  includeUnsupportedDataTypes 
)
inlinestatic

Discovers the available tables in the given source file.

Parameters
sourceThe absolute path to the GeoPackage file. The extension of the file should be '.gpkg'.
includeUnsupportedDataTypesWhether to include unsupported data types.
Returns
the discovered tables.
Exceptions
System.IO.IOExceptionwhen discovering the tables fails.