在VB.Net中解析GML的最佳方法是什么

时间:2014-08-05 05:31:29

标签: vb.net gml-geographic-markup-lan

我正在寻找解析GML以返回空间数据的最佳方法。例如,这是一个GML文件:

<?xml version="1.0" encoding="utf-8"?>
<gml:FeatureCollection xmlns:gml="http://www.opengis.net/gml"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:onecallgml="http://www.pelicancorp.com/onecallgml"
    xsi:schemaLocation="http://www.pelicancorp.com/onecallgml http://www.pelicancorp.com/digsafe/onecallgml.xsd">
<gml:featureMember>
    <onecallgml:OneCallReferral gml:id="digsite">
    <onecallgml:LocationDetails>    
    <gml:surfaceProperty>
    <gml:Polygon srsName="EPSG:2193">
    <gml:exterior>
    <gml:LinearRing>
    <gml:posList>
        1563229.00057526 5179234.72234694 1563576.83066077 5179352.36361939 1563694.22647617 5179123.23451613 1563294.42782719 5179000.13697214 1563229.00057526 5179234.72234694
    </gml:posList>
    </gml:LinearRing>
    </gml:exterior>
    </gml:Polygon>
    </gml:surfaceProperty>
    </onecallgml:LocationDetails>
    </onecallgml:OneCallReferral>
</gml:featureMember>
</gml:FeatureCollection>

如何遍历每个featureMember,然后遍历其多边形,然后将posList坐标转换为数组?

1 个答案:

答案 0 :(得分:0)

在VB.NET中处理XML时,我建议使用LINQ to XML。您可能希望提取更多信息(例如,要绑定到featureMember),但一个简单的示例可能是:

' You will need to import the XML namespace
Imports <xmlns:gml = "http://www.opengis.net/gml">
...
Dim xml As XElement = XElement.Parse(myGmlString) ' or some other method
Dim polys = (
    From fm In xml...<gml:featureMember>
    From poly In fm...<gml:Polygon>
    Select New With {
        .Name = poly.@srsName,
        .Coords = (poly...<gml:posList>.Value.Trim() _
            .Split({" "}, StringSplitOptions.RemoveEmptyEntries) _
            .Select(Function(x) CDbl(x))).ToArray()
    }
).ToList()

这将为您提供一个匿名类型列表,其中包含多边形名称,坐标为Double数组。

相关问题