https://github.com/simonepri/geojson-geometries
⛏ Extract elementary geometries from a GeoJSON inheriting properties.
https://github.com/simonepri/geojson-geometries
extract geojson geometries nodejs
Last synced: about 1 year ago
JSON representation
⛏ Extract elementary geometries from a GeoJSON inheriting properties.
- Host: GitHub
- URL: https://github.com/simonepri/geojson-geometries
- Owner: simonepri
- License: mit
- Created: 2017-12-04T21:52:10.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-02T14:24:14.000Z (about 6 years ago)
- Last Synced: 2025-04-28T16:09:56.432Z (about 1 year ago)
- Topics: extract, geojson, geometries, nodejs
- Language: JavaScript
- Size: 21.5 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
geojson-geometries
⛏ Extract elementary geometries from a GeoJSON inheriting properties.
Coded with ❤️ by Simone Primarosa.
## Install
```bash
$ npm install --save geojson-geometries
```
## Usage
```javascript
const GeoJsonGeometries = require('geojson-geometries');
const geojson = {type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [102.0, 0.5]
},
properties: {prop0: 'value0'}
}, {
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]
},
properties: {prop1: 'value1'}
}, {
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [
[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]
]
},
properties: {prop2: 'value2'}
}]
};
const extracted = new GeoJsonGeometries(geojson);
extracted.points
// => {
// type: "FeatureCollection",
// features: [{
// type: "Feature",
// geometry: {
// type: "Point",
// coordinates: [102, 0.5]
// },
// properties: {prop0: 'value0'}
// }]
// }
extracted.lines
// => {
// type: "FeatureCollection",
// features: [{
// type: "Feature",
// geometry: {
// type: "LineString",
// coordinates: [[[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]]
// },
// properties: {prop1: 'value1'}
// }]
// }
extracted.polygons
// => {
// type: "FeatureCollection",
// features: [{
// type: "Feature",
// geometry: {
// type: "Polygon",
// coordinates: [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]
// },
// properties: {prop2: 'value2'}
// }]
// }
```
### new GeoJsonGeometries(geoJson, [options])
Create an instance of the geometries extractor.
| Param | Type | Description |
| --- | --- | --- |
| geoJson | Object | The GeoJSON from which extract the geometries. |
| [options] | Object | Optional options. |
| options.ignorePoints | boolean | If true the extractor will ignore geometries of type Point. |
| options.ignoreLines | boolean | If true the extractor will ignore geometries of type LineString. |
| options.ignorePolygon | boolean | If true the extractor will ignore geometries of type Polygon. |
### geoJsonGeometries.points ⇒ Array.<Object>
Returns the list of geometries of type Point found in the GeoJSON.
**Kind**: instance property of [GeoJsonGeometries](#GeoJsonGeometries)
**Returns**: Array.<Object> - A FeatureCollection of points with inherited properties if any.
### geoJsonGeometries.lines ⇒ Array.<Object>
Returns the list of geometries of type LineString found in the GeoJSON.
**Kind**: instance property of [GeoJsonGeometries](#GeoJsonGeometries)
**Returns**: Array.<Object> - A FeatureCollection of lines with inherited properties if any.
### geoJsonGeometries.polygons ⇒ Array.<Object>
Returns the list of geometries of type Polygon found in the GeoJSON.
**Kind**: instance property of [GeoJsonGeometries](#GeoJsonGeometries)
**Returns**: Array.<Object> - A FeatureCollection of polygons with inherited properties if any.
## Authors
- **Simone Primarosa** - *Github* ([@simonepri][github:simonepri]) • *Twitter* ([@simoneprimarosa][twitter:simoneprimarosa])
See also the list of [contributors][contributors] who participated in this project.
## License
This project is licensed under the MIT License - see the [license][license] file for details.
[contributors]: https://github.com/simonepri/geojson-geometries-lookup/contributors
[license]: https://github.com/simonepri/geojson-geometries-lookup/tree/master/license
[github:simonepri]: https://github.com/simonepri
[twitter:simoneprimarosa]: http://twitter.com/intent/user?screen_name=simoneprimarosa