barberboy / geojson-polyline Goto Github PK
View Code? Open in Web Editor NEWConvert GeoJSON coordinates to and from encoded polylines. Supports all major GeoJSON types.
Home Page: https://github.com/barberboy/geojson-polyline#readme
Convert GeoJSON coordinates to and from encoded polylines. Supports all major GeoJSON types.
Home Page: https://github.com/barberboy/geojson-polyline#readme
While encoding GeoJSON into encoded Polyline, I detected sometimes that the result is not what is expected.
Here is the GeoJSON:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
-0.55461,
47.497491
],
[
-0.554074,
47.497393
],
[
-0.553654,
47.497298
],
[
-0.553135,
47.49717
],
[
-0.552639,
47.497018
],
[
-0.552086,
47.4968
]
]
},
"properties": {}
}
]
}
And the encoded polyline:
iz{`HhikBRkBPsAXeB\\cBj@mB
Here is a screenshot of both GeoJSON and polyline on a map:
It seems that a single point is wrong encoded (the fifth one) : [-0.552639,47.497018] is encoded as (47.49702,-0.55329)
Is there something wrong with the algorithm implementation?
I'm using the library in a Vue.js project and in every action this function gets called.
Here is my code:
imgSrc() {
if (!this.shape || !this.shape.features) return '/imgs/placeholder.jpg';
const { coordinates: enc } = encode(this.shape.features[0].geometry);
const width = 320;
const height = 240;
const fillColor = '0xFF000050';
const color = '0xFF000080';
const weight = 2;
const url = `https://maps.googleapis.com/maps/api/staticmap?size=${width}x${height}&maptype=satellite&path=fillcolor:${fillColor}|color:${color}|weight:${weight}|enc:${enc}&key=MyAPIkey`;
return encodeURI(url);
},
My project is a SPA, therefore, I think the function gets called in every render of my components.
I'll open a merge request with the solution I came up with.
I have tested this wonderful postgresql encoding function Google-Encoded-Polyline-PostGRESql-PostGIS-Implementation but there is a difference. In postgresql implementation he managed to output multipolygons as one string for example this one
cacoEbmxlNnI`FpJoe@xNsa@n[oGpCYfBMvASdOwCnAQbAE`A?bAFbAL~@T~@Z|@b@x@f@jAbAbAjAXb@q@FxDjErIjZxBdHpBnGbDbJpAhDjCtGdHnRsQlMvF~ORx@QrH{DnGcHrG{ArNnB`DoO~Lq@l@m@r@u`A}s@kJaDgIoC{J`LmAH_GsOaAwCyOV`BbB{@x@Sw@Ys@gEqJFEdCE`HCvDSyVyt@rVhK‡ywboEn{ylNrBIGkCqBFDlC
is a multipolygon with two polygons in it. In your implementation as far as I have seen, it splits multipolygons into polygons and decodes/encodes them as polyline/polygon. I was wondering in some way if I can decode it but I have no idea how to do that.
Hey,
Maybe I missed something in the documentation, but is it possible to convert from Google Polyline Encoding to Geojson?
> echo "yvd|Fh~gqNfEqKzBEkEvKwB?" | geojson-polyline fromPolyline
internal/streams/legacy.js:59
throw er; // Unhandled stream error in pipe.
^
Error: Invalid JSON (Unexpected "y" at position 0 in state STOP)
at Parser.proto.charError (/usr/local/lib/node_modules/geojson-polyline/node_modules/jsonparse/jsonparse.js:90:16)
at Parser.proto.write (/usr/local/lib/node_modules/geojson-polyline/node_modules/jsonparse/jsonparse.js:154:23)
Thanks!
When I produce a LineString with your library, it's not a full GeoJSON
{fo_FvwwlQxQ|SbExEbBpJhCzc@
FtRbSbZpAbBvAjCCEu@tEmB~CoWnKwl@bVq\\~N
becomes
{ type: 'LineString',
coordinates:
[ [ -96.6286, 36.78334 ],
[ -96.63195, 36.78033 ],
...
[ -96.65802, 36.78504 ],
[ -96.66058, 36.78977 ] ] }
Why is there no wrapper to produce a valid GeoJSON?
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates":
[ [ -96.6286, 36.78334 ],
[ -96.63195, 36.78033 ],
...
[ -96.65802, 36.78504 ],
[ -96.66058, 36.78977 ] ]
},
"properties": {}
}
I'm just curious, since every polyline js library I've tried out only outputs a GeoJSON fragment.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.