A polygon is provided as an array of points, which is in geojson format.
wicket.wrtie() incorrectly returns a POINT( ... ) rather than a POLYGON ( ... )
let coords = [
[ 28.324979200606098,-25.74442504898913 ]
[ 28.327136778694015,-25.73978746165716 ]
[ 28.323643915439302,-25.7358147570423 ]
[ 28.317993541281737,-25.736479619044854 ]
[ 28.315835810504456,-25.74111718371399 ]
[ 28.3193286065439,-25.745089909049103 ]
[ 28.324979200606098,-25.74442504898913 ]
]
let wicket = new Wkt.Wkt(`{"coordinates": [${coords}], "type": "Polygon"}`)
console.log(wicket.write())
// POLYGON((28.324979200606098 -25.74442504898913))
This is because the above statement turns coords into a string.
So from "coordinates" : [ [ [x,y], [x,y], ... ] ]
into "coordinates" : "x,y,x,y,x,y,...".
This is an invalid format and should rather be "coordinates": "[[[x,y],[x, ],... ]]", however a POINT ( ... ) is still returned as if it was correct notation
Thus the stringified version of coords is invalid, but unfortunately is the result of the syntax shown above and is expected.
Ideally the invalid syntax should be handled and simply thrown as is done with other invalid cases.
Using JSON.stringify is the solution and correct way of stringifying arrays.
A polygon is provided as an array of points, which is in geojson format.
wicket.wrtie()incorrectly returns aPOINT( ... )rather than aPOLYGON ( ... )This is because the above statement turns
coordsinto a string.So from
"coordinates" : [ [ [x,y], [x,y], ... ] ]into
"coordinates" : "x,y,x,y,x,y,...".This is an invalid format and should rather be
"coordinates": "[[[x,y],[x, ],... ]]", however aPOINT ( ... )is still returned as if it was correct notationThus the stringified version of
coordsis invalid, but unfortunately is the result of the syntax shown above and is expected.Ideally the invalid syntax should be handled and simply
thrownas is done with other invalid cases.Using
JSON.stringifyis the solution and correct way of stringifying arrays.