Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading Polygon from flat array returns Point without throwing error #145

Open
Portur opened this issue Apr 17, 2020 · 0 comments
Open

Reading Polygon from flat array returns Point without throwing error #145

Portur opened this issue Apr 17, 2020 · 0 comments

Comments

@Portur
Copy link

Portur commented Apr 17, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant