1.0.0 • Published 5 years ago

multipolygon-to-js-array v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

multipolygon-to-js-array

Convert Multiploygon data to JS array.

Build Status Coverage Status

Tech

multipolygon-to-js-array uses a number of open source projects to work properly:

Setup

npm install --save multipolygon-to-js-array

Usage

const Convert = require('multipolygon-to-js-array');

const data = 'MULTIPOLYGON (((121.5084001170001 16.59158600700005, 121.508331995 16.59068907600005, 121.5082491630001 16.58922843100004, 121.508076779 16.58777499900003, 121.5080869200001 16.58664605500007, 121.5079830980001 16.58522653800003, 121.5083788520001 16.58357880900007, 121.5110527090001 16.57842555600007, 121.5112836340001 16.57823109400005, 121.511599635 16.57779355400004, 121.511830559 16.57747755200006, 121.5121100990001 16.57721016700003, 121.5124625620001 16.57620139300008, 121.512474716 16.57587323800004, 121.5124868690001 16.57530200500003, 121.51214656 16.57468215600005, 121.51164825 16.57395292200005, 121.5111742480001 16.57329661100005, 121.510748862 16.57283476300006, 121.5106151690001 16.57253091600006, 121.510578707 16.57228783800002, 121.5105908610001 16.57209337500007, 121.5106759390001 16.57178952800007, 121.5105908610001 16.57150998800006, 121.510517938 16.57125475600003, 121.510262706 16.57074429300008, 121.5101897830001 16.57047690700006, 121.510116859 16.57014875200002, 121.5098812580001 16.56999285700005, 121.5096947180001 16.57043545900007, 121.5071868130001 16.57618010000004, 121.505404773 16.58039997100008, 121.505190928 16.58077063500002, 121.504951545 16.58147212700004, 121.504901407 16.58162881000004, 121.504832466 16.58177922600004, 121.5041217040001 16.58337954200005, 121.504007654 16.58383574400006, 121.503337607 16.58541819600003, 121.503351863 16.58657295800003, 121.5034088880001 16.58685808400003, 121.503551452 16.58835499800006, 121.503722527 16.58978063000006, 121.5036847920001 16.59008999700006, 121.5035222400001 16.59050798800007, 121.503208746 16.59084470400006, 121.50287203 16.59126269500007, 121.5028139760001 16.59136719300005, 121.5031809620001 16.59147063100005, 121.5036833620001 16.59152273200004, 121.5038589550001 16.59144847000005, 121.5048484870001 16.59162120700006, 121.5055952260001 16.59162969300007, 121.505965056 16.59180432800002, 121.5064888820001 16.59188072000006, 121.507241882 16.59182615400005, 121.5084001170001 16.59158600700005)))';

const array = Convert(data);
/*
Values:

[[121.5084001170001,16.59158600700005],[121.508331995,16.59068907600005],[121.5082491630001,16.58922843100004],[121.508076779,16.5877749990
0003],[121.5080869200001,16.58664605500007],[121.5079830980001,16.58522653800003],[121.5083788520001,16.58357880900007],[121.5110527090001,16.57842555600007],[121.5112836340001,16.57823109400005],[121.511599635,16.57779355400004],[121.511830559,16.57747755200006],[121.5121100990001,16.57721016700003],[121.5124625620001,16.57620139300008],[121.512474716,16.57587323800004],[121.5124868690001,16.57530200500003],[121.51214656,16.57468215600005],[121.51164825,16.57395292200005],[121.5111742480001,16.57329661100005],[121.510748862,16.57283476300006],[121.5106151690001,16.57253091600006],[121.510578707,16.57228783800002],[121.5105908610001,16.57209337500007],[121.5106759390001,16.57178952800007],[121.5105908610001,16.57150998800006],[121.510517938,16.57125475600003],[121.510262706,16.57074429300008],[121.5101897830001,16.57047690700006],[121.510116859,16.57014875200002],[121.5098812580001,16.56999285700005],[121.5096947180001,16.57043545900007],[121.5071868130001,16.57618010000004],[121.505404773,16.58039997100008],[121.505190928,16.58077063500002],[121.504951545,16.58147212700004],[121.504901407,16.58162881000004],[121.504832466,16.58177922600004],[121.5041217040001,16.58337954200005],[121.504007654,16.58383574400006],[121.503337607,16.58541819600003],[121.503351863,16.58657295800003],[121.5034088880001,16.58685808400003],[121.503551452,16.58835499800006],[121.503722527,16.58978063000006],[121.5036847920001,16.59008999700006],[121.5035222400001,16.59050798800007],[121.503208746,16.59084470400006],[121.50287203,16.59126269500007],[121.5028139760001,16.59136719300005],[121.5031809620001,16.59147063100005],[121.5036833620001,16.59152273200004],[121.5038589550001,16.59144847000005],[121.5048484870001,16.59162120700006],[121.5055952260001,16.59162969300007],[121.505965056,16.59180432800002],[121.5064888820001,16.59188072000006],[121.507241882,16.59182615400005],[121.5084001170001,16.59158600700005]]
*/

Tests

 jay@ThinkPad  /usr/share/nginx/html/multipolygon-to-js-array  npm test

> multipolygon-to-js-array@1.0.0 test /usr/share/nginx/html/multipolygon-to-js-array
> jest test --coverage

 PASS  __tests__/index.test.js
  testing index.js
    ✓ it should call anonymous function that accepts MULTIPOLYGON string and should return array of coordinates (4ms)
    ✓ it should call anonymous function that accepts empty string and should return empty array

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |      100 |      100 |      100 |      100 |                   |
 index.js |      100 |      100 |      100 |      100 |                   |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        0.826s, estimated 1s
Ran all test suites matching /test/i