C#에서 GML(Geography Markup Language) 파일 읽기
Contents
[
Hide
]
Geography Markup Language (GML)
Aspose.GIS는 Geography Markup Language(GML)에서 피처를 읽을 수 있는 기능을 제공합니다. 스키마가 있는 경우 스키마 옵션을 지정할 수 있습니다.
스키마를 지정하여 GML 파일에서 피처 읽기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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")); | |
} | |
} |
스키마를 지정하지 않고 GML 파일에서 피처 읽기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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")); | |
} | |
} |