Package Exports
- geojson-polygon-center
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (geojson-polygon-center) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 ] }