Skip to content

jaycenhorton/multipolygon-to-polygon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a utility to merge a MultiPolygon into a single Polygon

This tool reads in a GeoJSON file containing two disconnected polygons. It finds the closest points of each polygon and then redraws the polygons with a single line connecting the two.

Setup

yarn install

Example

yarn run merge -i test.geojson -o out.json

Use it globally

Use Yarn

yarn add global m2p

Or NPM

npm install -g m2p

Then use it anywhere

m2p -i test.geojson -o output.json

Output example:

The closest point in polygon 1 to polygon 2 is [ -76.054358, 39.284373 ]
The closest point in polygon 1 to polygon 2 is [ -76.054401, 39.284506 ]
Polygons redrawn with connection between [ -76.054358, 39.284373 ] and [ -76.054401, 39.284506 ]

The GeoJSON to be written to the output file is:

 {"type":"Feature","properties":{},"geometry":{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[-76.054358,39.284373],[-76.054144,39.283128],[-76.053908,39.281882],[-76.0535,39.280254],[-76.053479,39.279972],[-76.053135,39.279889,0],[-76.053135,39.279889],[-76.05026,39.280288],[-76.050164,39.280354],[-76.050164,39.280886],[-76.050389,39.2814],[-76.050668,39.281699],[-76.051075,39.281982],[-76.051419,39.282248],[-76.051204,39.282248],[-76.050367,39.28165],[-76.049048,39.280952],[-76.048747,39.280894],[-76.048458,39.280935],[-76.048243,39.280869],[-76.045861,39.283061],[-76.046226,39.284199],[-76.046698,39.285387],[-76.050024,39.284988],[-76.053393,39.284506],[-76.054358,39.284373],[-76.054401,39.284506],[-76.052599,39.284789],[-76.052835,39.285835],[-76.053157,39.286234],[-76.053092,39.286433],[-76.052728,39.286533],[-76.052449,39.286449],[-76.05232,39.286184],[-76.052685,39.285935],[-76.052599,39.285395],[-76.052449,39.284822],[-76.048951,39.285287],[-76.048908,39.286964],[-76.048286,39.287114],[-76.048157,39.287031],[-76.048265,39.285503],[-76.0482,39.285353],[-76.048071,39.285403],[-76.04688,39.285544],[-76.04688,39.285544],[-76.04569,39.285752],[-76.045625,39.286051],[-76.045486,39.287853],[-76.045389,39.288716],[-76.045336,39.289538],[-76.04569,39.289887],[-76.04569,39.28997],[-76.045936,39.290103],[-76.04629,39.290153],[-76.04791,39.290045],[-76.048447,39.290153],[-76.048865,39.29007],[-76.049209,39.290194],[-76.049531,39.290236],[-76.050067,39.29002],[-76.050764,39.289887],[-76.051462,39.289854],[-76.051869,39.289821],[-76.052502,39.289613],[-76.052824,39.289389],[-76.053243,39.289381],[-76.053661,39.289364],[-76.054358,39.289206],[-76.055174,39.289472],[-76.055539,39.289547],[-76.055871,39.289721],[-76.056011,39.289846],[-76.056215,39.289962],[-76.056397,39.29007],[-76.057062,39.290062],[-76.057405,39.290012],[-76.057749,39.290003],[-76.058543,39.289954],[-76.059165,39.290103],[-76.06041,39.289887],[-76.060345,39.289538],[-76.060098,39.28899],[-76.059766,39.288525],[-76.059208,39.287961],[-76.058671,39.287695],[-76.057255,39.28723],[-76.056043,39.28679],[-76.055195,39.286051],[-76.054519,39.285029],[-76.054358,39.284373]]]}]}}


The WKT is:

 "POLYGON((-76.054358 39.284373,-76.054144 39.283128,-76.053908 39.281882,-76.0535 39.280254,-76.053479 39.279972,-76.053135 39.279889),(-76.054401 39.284506,-76.052599 39.284789,-76.052835 39.285835,-76.053157 39.286234,-76.053092 39.286433,-76.052728 39.286533,-76.052449 39.286449,-76.05232 39.286184,-76.052685 39.285935,-76.052599 39.285395,-76.052449 39.284822,-76.048951 39.285287,-76.048908 39.286964,-76.048286 39.287114,-76.048157 39.287031,-76.048265 39.285503,-76.0482 39.285353,-76.048071 39.285403,-76.04688 39.285544))"

The file was saved!

About

Utility for converting a GeoJSON with multiple polygons into a GeoJSON with one connected polygon

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published