Lesen von GML Geography Markup Language Dateien in C#

Geography Markup Language (GML)

Aspose.GIS bietet die Möglichkeit, Features aus Geography Markup Language (GML) zu lesen. Es ermöglicht Ihnen, die Schemaoption anzugeben, falls vorhanden.

Lesen von Features aus GML-Datei durch Angabe des Schemas

// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET
GmlOptions options = new GmlOptions
{
// In this example we specify custom schemaLocation, since there is no 'schemaLocation' in GML file.
SchemaLocation = "http://www.aspose.com schema.xsd",
LoadSchemasFromInternet = false,
};
Console.WriteLine("");
Console.WriteLine("custom schema location...");
using (VectorLayer layer = VectorLayer.Open(dataDir + "file_without_schema_location.gml", Drivers.Gml, options))
{
foreach (Feature feature in layer)
{
Console.WriteLine(feature.GetValue<string>("attribute"));
}
}

Lesen von Features aus GML-Datei ohne Angabe des Schemas

// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET
// Case 1: we try to load schema from Internet.
// first, we create an instance of GmlOptions class.
GmlOptions options = new GmlOptions
{
// In order to read GML layers features description, Aspose.GIS reads XML schema attached to it.
// Usually, it is specified in GML files root tag as 'schemaLocation' attribute. If it is not, you need to specify GML schema location
// youself. In this examples we don't specify it (keep it null), so Aspose.GIS will try to read schema location from XML file.
SchemaLocation = null,
// 'schemaLocation' may contain references to schemas located on the Internet. In this case, you need to set this property to 'true' in
// order to allow Aspose.GIS to load schemas from internet.
// Basically, if you don't mind Aspose.GIS using internet, you can always keep this true.
LoadSchemasFromInternet = true,
};
// then, we pass it to 'VectorLayer.Open'
Console.WriteLine("from internet loading...");
using (VectorLayer layer = VectorLayer.Open(dataDir + "file.gml", Drivers.Gml, options))
{
foreach (Feature feature in layer)
{
Console.WriteLine(feature.GetValue<string>("attribute"));
}
}
// Case 2: we try to restore the attributes schema by data in file.
Console.WriteLine("");
Console.WriteLine("restoration by file data...");
using (VectorLayer layer = VectorLayer.Open(dataDir + "file.gml", Drivers.Gml, new GmlOptions(){RestoreSchema = true}))
{
foreach (Feature feature in layer)
{
Console.WriteLine(feature.GetValue<string>("attribute"));
}
}