MapPackage.CreateMetadataWriter Method
Creates a GeoPackageMetadataWriter to create and write metadata to an OGC GeoPackage file.
CreateMetadataWriter()
Creates a GeoPackageMetadataWriter to create and write metadata to an OGC GeoPackage file.Syntax
public GeoPackageMetadataWriter CreateMetadataWriter ()
Return Value
Example
// Save metadata to a GeoPackage file
static void createAndSaveMetadataToGeoPackage(string fileName)
{
// Create new map package
MapPackage mapPackage = new MapPackage(fileName);
// Create a vector table
string tableName = "places";
MapPackageVectorTable vectorTable = new MapPackageVectorTable(tableName, Crs.Wgs84LongLat);
// Create vector writer
var vectorWriter = mapPackage.CreateVectorWriter(vectorTable);
// Start a transaction
using (var txn = vectorWriter.BeginTransaction())
{
// Commit transaction to write the table
txn.Commit();
}
// Create two metadata entries, one for the entire package, and one for the table
var packageMetadata = new GeoPackageMetadata(GeoPackageMetadataScope.Series, // scope
"example.com", // uri
"Some interesting package metadata"); // metadata
var tableMetadata = new GeoPackageMetadata(GeoPackageMetadataScope.Dataset,
"example.com",
"Some interesting table metadata");
// Create a metadata writer
GeoPackageMetadataWriter metadataWriter = mapPackage.CreateMetadataWriter();
// Start a transaction
using (var txn = metadataWriter.BeginTransaction())
{
// Write the metadata, save the references for each respective entry
long packageMetadataRef = metadataWriter.WriteMetadata(packageMetadata);
long tableMetadataRef = metadataWriter.WriteMetadata(tableMetadata);
// Write the respective references
metadataWriter.WritePackageReference(packageMetadataRef);
metadataWriter.WriteTableReference(tableMetadataRef, tableName);
// Commit transaction
txn.Commit();
}
}
Platforms
Windows, Linux, Android