POLYGON ((162353.9901277053 564298.9605047705,162352.3101277038 564286.9905047683, 162353.9901277053 564298.9605047705))
输出需求
[[162353.9901277053, 564298.9605047705], [162352.3101277038, 564286.9905047683],[ 162353.9901277053, 564298.9605047705]]
我一直在看草皮,很遗憾没有找到
您可以使用Terraformer.WKT.parse
将WKT POLYGON转换为GeoJSON,然后从中获取坐标。这是可运行的代码。
// Use Terraformer.WKT.parse() to convert WKT to GeoJSON
var geojson_pgons = Terraformer.WKT.parse('POLYGON ((162353.9901277053 564298.9605047705,162352.3101277038 564286.9905047683, 162353.9901277053 564298.9605047705))');
// get coordinates list of the first object
var poly0xys = geojson_pgons.coordinates[0];
// collect what we need
var result = [];
for (let i=0; i<poly0xys.length; i++) {
//console.log( poly0xys[i] );
result.push( poly0xys[i] );
}
console.log( result );
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/[email protected]"></script>