Skip to content

A small JavaScript library to convert wkt to a js object, which include geometry type and coordinates.

Notifications You must be signed in to change notification settings

JackShell2020/wktParse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wktParse

A small JavaScript library to convert wkt to a js object, which include geometry type and coordinate.

一个小的JavaScript插件库,用于将wkt数据转成一个包含图形类型和坐标的js对象,

  • example
var wkt = "MULTIPOLYGON (((119.77532958984375 33.74432373046875, 119.77490234375 33.7454833984375, 119.7742919921875 33.74609375, 119.77288818359375 33.74652099609375, 119.7720947265625 33.7476806640625, 119.7705078125 33.74627685546875, 119.768310546875 33.7454833984375, 119.7677001953125 33.7454833984375, 119.7677001953125 33.74371337890625, 119.7686767578125 33.7432861328125, 119.76971435546875 33.7432861328125, 119.769287109375 33.74169921875, 119.7705078125 33.74151611328125, 119.77008056640625 33.7388916015625, 119.7677001953125 33.73248291015625, 119.7720947265625 33.73028564453125, 119.77447509765625 33.72930908203125, 119.777099609375 33.72808837890625, 119.7808837890625 33.726318359375, 119.78192138671875 33.728515625, 119.7830810546875 33.728271484375, 119.78350830078125 33.7301025390625, 119.78387451171875 33.7288818359375, 119.7852783203125 33.7301025390625, 119.7874755859375 33.72869873046875, 119.788330078125 33.7301025390625, 119.7896728515625 33.7322998046875, 119.790283203125 33.7322998046875, 119.7943115234375 33.73687744140625, 119.7896728515625 33.7388916015625, 119.7874755859375 33.7388916015625, 119.7852783203125 33.73992919921875, 119.7830810546875 33.7410888671875, 119.78192138671875 33.7410888671875, 119.781494140625 33.74151611328125, 119.7808837890625 33.74169921875, 119.77947998046875 33.74212646484375, 119.7786865234375 33.7432861328125, 119.77752685546875 33.7432861328125, 119.7764892578125 33.7432861328125, 119.7764892578125 33.743896484375, 119.77532958984375 33.74432373046875), (119.7708740234375 33.7388916015625, 119.7720947265625 33.7388916015625, 119.77288818359375 33.7388916015625, 119.7742919921875 33.73870849609375, 119.77447509765625 33.7373046875, 119.7730712890625 33.73712158203125, 119.77227783203125 33.7373046875, 119.7708740234375 33.7388916015625)))"
var result = WKTParser(wkt);
console.log(JSON.stringify(result));

"{"geomType":"MULTIPOLYGON","coordinates":[[[[119.77532958984375,33.74432373046875],[119.77490234375,33.7454833984375],[119.7742919921875,33.74609375],[119.77288818359375,33.74652099609375],[119.7720947265625,33.7476806640625],[119.7705078125,33.74627685546875],[119.768310546875,33.7454833984375],[119.7677001953125,33.7454833984375],[119.7677001953125,33.74371337890625],[119.7686767578125,33.7432861328125],[119.76971435546875,33.7432861328125],[119.769287109375,33.74169921875],[119.7705078125,33.74151611328125],[119.77008056640625,33.7388916015625],[119.7677001953125,33.73248291015625],[119.7720947265625,33.73028564453125],[119.77447509765625,33.72930908203125],[119.777099609375,33.72808837890625],[119.7808837890625,33.726318359375],[119.78192138671875,33.728515625],[119.7830810546875,33.728271484375],[119.78350830078125,33.7301025390625],[119.78387451171875,33.7288818359375],[119.7852783203125,33.7301025390625],[119.7874755859375,33.72869873046875],[119.788330078125,33.7301025390625],[119.7896728515625,33.7322998046875],[119.790283203125,33.7322998046875],[119.7943115234375,33.73687744140625],[119.7896728515625,33.7388916015625],[119.7874755859375,33.7388916015625],[119.7852783203125,33.73992919921875],[119.7830810546875,33.7410888671875],[119.78192138671875,33.7410888671875],[119.781494140625,33.74151611328125],[119.7808837890625,33.74169921875],[119.77947998046875,33.74212646484375],[119.7786865234375,33.7432861328125],[119.77752685546875,33.7432861328125],[119.7764892578125,33.7432861328125],[119.7764892578125,33.743896484375],[119.77532958984375,33.74432373046875]],[[119.7708740234375,33.7388916015625],[119.7720947265625,33.7388916015625],[119.77288818359375,33.7388916015625],[119.7742919921875,33.73870849609375],[119.77447509765625,33.7373046875],[119.7730712890625,33.73712158203125],[119.77227783203125,33.7373046875],[119.7708740234375,33.7388916015625]]]]}"

  • Install the project dependencies.

    npm install

  • Developing a demo for the browser.

    npm run start

  • Create a bundle for the browser.

    npm run build

  • Open index.html to see the result.

    open index.html

About

A small JavaScript library to convert wkt to a js object, which include geometry type and coordinates.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published