Skip to content

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

Description

@Portur

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions