我正在使用OpenLayers
读取多边形var features = format.read(strGML);
这是GML字符串结构
<gml:featureMember xmlns:gml="http://www.opengis.net/gml xsi:schemaLocation="http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/1.0.0/gmlsf.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<feature:feature xmlns:feature="http://example.com/feature">
<feature:geometry>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:posList>591674.39 5022898.05 545682.5 4722908.1 571701.44 5322909.29 651691.25 5022904.6 591674.39 5022898.05
</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</feature:geometry>
</feature:feature>
阅读后(有效)我需要迭代这个多边形的每个点并读取坐标。我尝试了各种尝试,但是无法让它发挥作用。这样做的正确方法是什么?
答案 0 :(得分:1)
无论如何,我找到了解决方案:
var newPoints = []; var feature = features[0]; var points = feature.geometry.getVertices(); for (var i=0; i<points.length; i++) { var lon = points[i].x; var lat = points[i].y; var point = new OpenLayers.Geometry.Point(lon, lat); // do something with Points newPoints.push(point); }