2
POLYGON ((162353.9901277053 564298.9605047705,162352.3101277038 564286.9905047683, 162353.9901277053 564298.9605047705))

output need

[[162353.9901277053, 564298.9605047705], [162352.3101277038, 564286.9905047683],[ 162353.9901277053, 564298.9605047705]]

I've been looking at Turf,unfortunately not found

swatchai
  • 17,400
  • 3
  • 39
  • 58
BKS
  • 21
  • 1
  • 3

1 Answers1

3

You can use Terraformer.WKT.parse to convert WKT POLYGON to GeoJSON, then get the coordinates out of it. Here is the runnable code.

// 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/terraformer@1.0.8"></script>
<script src="https://unpkg.com/terraformer-wkt-parser@1.1.2"></script>
swatchai
  • 17,400
  • 3
  • 39
  • 58