MapPackage.CreateVectorWriter Method
Creates a MapPackageVectorWriter to create and write vector data to a new table in an OGC GeoPackage file.
CreateVectorWriter(MapPackageVectorTable table)
Creates a MapPackageVectorWriter to create and write vector data to a new table in an OGC GeoPackage file.Syntax
public MapPackageVectorWriter CreateVectorWriter (
MapPackageVectorTable table
)
Parameters
Return Value
Remarks
Use this method when you want to use the MapPackageVectorWriter.WriteFeature method to write vector data to a GeoPackage. The features will be written to a new table in the OGC GeoPackage file this MapPackage is connected to.
Example
// Save features in a MemoryDataSet to a GeoPackage file
static void SaveFeaturesToGeoPackage(string filename, MemoryDataSet ds)
{
// Create new map package
var mapPackage = new MapPackage(filename);
// Create a vector table
var vectorTable = new MapPackageVectorTable("places", ds.Crs);
// Include the name and size attributes when writing features to the vector table
vectorTable.Attributes.Add(new MapPackageAttribute("name", AttributeType.String));
vectorTable.Attributes.Add(new MapPackageAttribute("size", AttributeType.Double));
// Create vector writer
var vectorWriter = mapPackage.CreateVectorWriter(vectorTable);
// Start a transaction
using (var txn = vectorWriter.BeginTransaction())
{
// Write features from the memory data set to the GeoPackage file
var fe = ds.GetFeatures().GetEnumerator();
while (fe.MoveNext())
{
vectorWriter.WriteFeature(fe.Current);
}
// Commit transaction
txn.Commit();
}
}
Platforms
Windows, Linux, Android