geojson-geometries
⛏ Extract elementary geometries from a GeoJSON inheriting properties.
Coded with ❤️ by Simone Primarosa.
Install
$ npm install --save geojson-geometries
Usage
const GeoJsonGeometries = ; const geojson = type: 'FeatureCollection' features: type: 'Feature' geometry: type: 'Point' coordinates: 1020 05 properties: prop0: 'value0' type: 'Feature' geometry: type: 'LineString' coordinates: 1020 00 1030 10 1040 00 1050 10 properties: prop1: 'value1' type: 'Feature' geometry: type: 'Polygon' coordinates: 1000 00 1010 00 1010 10 1000 10 1000 00 properties: prop2: 'value2' ; const extracted = geojson; extractedpoints// => {// type: "FeatureCollection",// features: [{// type: "Feature",// geometry: {// type: "Point",// coordinates: [102, 0.5]// },// properties: {prop0: 'value0'}// }]// } extractedlines// => {// 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'}// }]// } extractedpolygons// => {// 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'}// }]// }
API
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. |
Array.<Object>
geoJsonGeometries.points ⇒ Returns the list of geometries of type Point found in the GeoJSON.
Kind: instance property of GeoJsonGeometries
Returns: Array.<Object>
- A FeatureCollection of points with inherited properties if any.
Array.<Object>
geoJsonGeometries.lines ⇒ Returns the list of geometries of type LineString found in the GeoJSON.
Kind: instance property of GeoJsonGeometries
Returns: Array.<Object>
- A FeatureCollection of lines with inherited properties if any.
Array.<Object>
geoJsonGeometries.polygons ⇒ Returns the list of geometries of type Polygon found in the GeoJSON.
Kind: instance property of GeoJsonGeometries
Returns: Array.<Object>
- A FeatureCollection of polygons with inherited properties if any.
Authors
- Simone Primarosa - Github (@simonepri) • Twitter (@simoneprimarosa)
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the license file for details.