LuciadCPillar encoding support for GeoPackage
LuciadCPillar offers support for the creation of GeoPackage data sets and files. It can either create a GeoPackage data set and feature model from scratch for a given data type, or export an existing feature model. The encoding process supports both the creation of new files and the addition of GeoPackage data sets to existing files.
Creating an empty GeoPackage data set in a file
You can create an empty GeoPackage data set to fill up with feature data later. You can create such an empty data set in an existing GeoPackage file or in a new file.
To create a new data set, you need a file path, a data type
data type
data type
and a
coordinate reference
coordinate reference
coordinate reference
. The file path either points to a new file or to an
existing GeoPackage file. You must pass the data type and the reference to the GeoPackageFeatureModelCreateOptions
GeoPackageFeatureModelCreateOptions
GeoPackageFeatureModelCreateOptions
.
Then you call the createEmptyGeoPackageDataSet
createEmptyGeoPackageDataSet
createEmptyGeoPackageDataSet
function, as shown in the code sample.
The function creates the data set and also decodes an editable IFeatureModel
IFeatureModel
IFeatureModel
from
the new data set and returns it to you, ready for use.
See the API documentation
API documentation
API documentation
for more information.
std::string path = "test/resources/Data/GeoPackage/newGeoPackage.gpkg";
DataType dataType = createDataType();
auto reference = *CoordinateReferenceProvider::create("EPSG:4326");
auto options = GeoPackageFeatureModelCreateOptions::newBuilder().dataType(dataType).coordinateReference(reference).build();
auto expectedFeatureModel = GeoPackageModelEncoder::createEmptyGeoPackageDataSet(path, options);
if (!expectedFeatureModel) {
std::cout << "Failed to create feature model: " + expectedFeatureModel.error().getMessage();
}
std::shared_ptr<IFeatureModel> featureModel = *expectedFeatureModel;
DataType dataType = CreateDataType();
var path = "test/resources/Data/GeoPackage/newGeoPackage.gpkg";
var reference = CoordinateReferenceProvider.Create("epsg:4326");
var options = GeoPackageFeatureModelCreateOptions.NewBuilder()
.CoordinateReference(reference)
.DataType(dataType)
.Build();
try
{
IFeatureModel featureModel = GeoPackageModelEncoder.CreateEmptyGeoPackageDataSet(path, options);
}
catch (IOException e)
{
Console.WriteLine("Failed to create feature model: " + e.Message);
}
DataType dataType = createDataType();
String path = "resources/Data/GeoPackage/newGeoPackage.gpkg";
CoordinateReference reference = CoordinateReferenceProvider.create("epsg:4326");
GeoPackageFeatureModelCreateOptions options = GeoPackageFeatureModelCreateOptions.newBuilder().dataType(dataType).coordinateReference(reference).build();
try {
GeoPackageModelEncoder.createEmptyGeoPackageDataSet(path, options);
} catch (IOException e) {
Log.w("gpkg", "Failed to export feature model: " + e.getMessage());
}
Exporting an existing feature model
When you’re exporting
exporting
exporting
an existing feature model, you
need to specify the file path only, pointing either to a new file or an existing file. Setting the options
options
options
is optional. See the API documentation
API documentation
API documentation
for more information.
std::shared_ptr<IFeatureModel> featureModel = getFeatureModel();
std::string path = "test/resources/Data/GeoPackage/newGeoPackage.gpkg";
auto result = GeoPackageModelEncoder::exportFeatureModel(path, featureModel);
if (!result) {
std::cout << "Failed to export feature model: " + result.error().getMessage();
}
var path = "test/resources/Data/GeoPackage/newGeoPackage.gpkg";
IFeatureModel featureModel = GetFeatureModel();
try
{
GeoPackageModelEncoder.ExportFeatureModel(path, featureModel);
}
catch (IOException e)
{
Console.WriteLine("Failed to export feature model: " + e.Message);
}
IFeatureModel featureModel = getFeatureModel();
String path = "resources/Data/GeoPackage/newGeoPackage.gpkg";
try {
GeoPackageModelEncoder.exportFeatureModel(path, featureModel);
} catch (IOException e) {
Log.w("gpkg", "Failed to create feature model: " + e.getMessage());
}
Exporting or persisting a model
When you already have an editable GeoPackage IFeatureModel
IFeatureModel
IFeatureModel
and you want to persist
the changes you’ve made to it, you don’t have to export it. Instead, use the FeatureModelPersistenceManager
FeatureModelPersistenceManager
FeatureModelPersistenceManager
as explained in the GeoPackage editing article.