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

Parsing the encode result is broken in CLI #71

Open
shabnomnom opened this issue Sep 4, 2020 · 1 comment
Open

Parsing the encode result is broken in CLI #71

shabnomnom opened this issue Sep 4, 2020 · 1 comment
Labels

Comments

@shabnomnom
Copy link

When attempting to save the result from the endcode flag, the outputted result is not the same as the outputted result from the GeoJSON node script. There is an issue with the parser of the input or output.

Steps to reproduce:

  1. polyline.json file includes:

[[-114.05130386352539,51.112359778280194],[-114.05130386352539,51.11947193091105],[-114.05611038208008,51.12324308281078][-114.06538009643555,51.126152046793365], [-114.0736198425293,51.12916855668462]]

  1. using : cat polyline.json | ./bin/polyline.bin.js --encode > encoded-poly.txt:

result in encoded-poly.txt:

"??????????_}hQ?????_qo]?~flW?_seK?~|hQ?_}hQ?_qo]?~reK?~|hQ?_seK?~|hQ?_}hQ?~reK?_{rc@?????~flW???????_ibE?_ibE?_seK?_glW?~reK???_ibE?~zrc@?_{rc@?~nyo@?_ibE?_oyo@?~po]?????????????????????????????????????_}hQ?????_qo]?~flW?_seK?~|hQ?_}hQ?_qo]?~reK?~|hQ?_seK?~|hQ?_}hQ?~reK?_{rc@?????~flW???????_oyo@?~po]?_}hQ?~zrc@?_oyo@?~zrc@?~|hQ?_y|u@?~nyo@???~hbE?_qo]?????????????????????????????????????_}hQ?????_qo]?_ibE?~po]???~hbE?_}hQ?_qo]?~zrc@?~reK?_oyo@?~nyo@???_oyo@?????~flW?????_ibE?_ibE?~hbE?_seK?~hbE?~|hQ?_oyo@?~zrc@?_{rc@?~dvi@?~hbE?_evi@?_ibE?????????????????????????????????????_}hQ?????_{rc@?~hbE?~reK?_qo]?~nyo@???_y|u@?~|hQ?~reK?~hbE?_seK?????????~flW?????_ibE?_glW?~po]?_glW?~|hQ?~reK?_glW?_seK?_ibE?_seK?~zrc@???_}hQ?~hbE?????????????????????????????????????_}hQ?????_evi@?~flW?_}hQ?~po]?_oyo@?~hbE?~flW?~reK?_}hQ?~|hQ?_evi@?~zrc@?????~flW?????_ibE?_evi@?~nyo@?_qo]?_seK?~|hQ???_ibE???_seK?~flW?_seK?~flW???????"

Compare to the result from the GeoJSON node script:

const polyline = require('@mapbox/polyline')
undefined
polyline.fromGeoJSON({ "type": "Feature",
... "geometry": {
..... "type": "LineString",
..... "coordinates": [[-114.05130386352539,51.112359778280194], [-114.05130386352539,51.11947193091105],[-114.05611038208008,51.12324308281078], [-114.06538009643555,51.126152046793365],[-114.0736198425293,51.12916855668462] ]
..... },
... "properties": {}
... });
'g{}vHrsbwTmk@?qV]eQ|x@{Qnr@'

@shabnomnom shabnomnom added the bug label Sep 4, 2020
@roblabs
Copy link

roblabs commented May 20, 2021

The array of [lat,lng] points is being passed into encode as a rawString. The proper fix would be to add JSON.parse() to what is passed to encode in the CLI wrapper file. Its unlikely that this fix would break other users. (requesting @ Mapbox team to review)


Change return polyline.encode(...)

return polyline.encode(rawString, p);

to

return polyline.encode(JSON.parse(rawString), p);

See:
https://github.com/mapbox/polyline/blob/4852d2468195f71cd240b50e48b87a8f5f4ce143/bin/polyline.bin.js#L75,L85


Testing with these commands encodes a polyline, but returns extra quotes:

# returns extra quotes due to an extra stringify
#   "w{qeFj`wjVwAzJJ?"
cat points.unencoded.txt | ./node_modules/.bin/polyline --encode

Where points.unencoded.txt contains:

[[37.77996,-122.51158],[37.7804,-122.51348],[37.78034,-122.51348]]

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

No branches or pull requests

2 participants