0.0.0 • Published 9 years ago

geojson-polygon-center v0.0.0

Weekly downloads
224
License
MIT
Repository
-
Last release
9 years ago

A simple function that finds the central point of a GeoJSON polygon.

Install it with npm install geojson-polygon-center.

> var polygonCenter = require('geojson-polygon-center')
> var geojsonFeatureCollection = {
...   "type": "FeatureCollection",
...   "features": [
...     {
.....       "type": "Feature",
.....       "properties": {},
.....       "geometry": {
.......         "type": "Point",
.......         "coordinates": [
.......           -7.734374999999999,
.......           46.07323062540838
.......         ]
.......       }
.....     },
...     {
.....       "type": "Feature",
.....       "properties": {},
.....       "geometry": {
.......         "type": "Polygon",
.......         "coordinates": [
.......           [
.......             [
.......               -7.734026312828064,
.......               46.07364371067343
.......             ],
.......             [
.......               -7.73364007472992,
.......               46.0733962320346
.......             ],
.......             [
.......               -7.73359715938568,
.......               46.07358230630263
.......             ],
.......             [
.......               -7.733838558197021,
.......               46.073781405074676
.......             ],
.......             [
.......               -7.734026312828064,
.......               46.07364371067343
.......             ]
.......           ]
.......         ]
.......       }
.....     }
...   ]
... }
> var point = geojsonFeatureCollection.features[0]
> point.geometry.type
'Point'
> var center = polygonCenter(polygon.geometry)
> center
{ type: 'Point', coordinates: [ 0, 0 ] }
>
> var polygon = geojsonFeatureCollection.features[1]
> polygon.geometry.type
'Polygon'
> var center = polygonCenter(polygon.geometry)
> center
{ type: 'Point',
  coordinates: [ -7.733811736106873, 46.07358881855464 ] }