Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

geojson-geometries-lookup

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geojson-geometries-lookup

Fast geometry in geometry lookup for large GeoJSONs

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.5K
decreased by-38.81%
Maintainers
1
Weekly downloads
 
Created
Source

geojson-geometries-lookup

Travis CI Codecov npm npm version npm dependencies npm dev dependencies

⚡️ Fast geometry in geometry lookup for large GeoJSONs.

With this package you can perform the following operations (and more) on a given GeoJSON.

  • Given a Point get all the Points intersecting it in the GeoJSON inheriting properties.
  • Given a Point get all the Lines intersecting it in the GeoJSON inheriting properties.
  • Given a Point get all the Polygons containing it in the GeoJSON inheriting properties.
  • Given a Line get all the Lines containing it in the GeoJSON inheriting properties.
  • Given a Polygon get all the Lines containing it in the GeoJSON inheriting properties.
  • Given a Polygon get all the Polygons containing it in the GeoJSON inheriting properties.

Install

$ npm install --save geojson-geometries-lookup

Usage

const GeoJsonGeometriesLookup = require('geojson-geometries-lookup');

const geojson = {type: 'FeatureCollection',
  features: [{
    type: 'Feature',
    geometry: {
      type: 'Point',
      coordinates: [102.0, 0.5]
    },
    properties: {prop0: 'value0'}
  }, {
    type: 'Feature',
    geometry: {
      type: 'LineString',
      coordinates: [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.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 glookup = new GeoJsonGeometriesLookup(geojson);

const point1 = {type: "Point", coordinates: [102.0, 0.5]};
glookup.getContainers(point1);
// => {
//   type: 'FeatureCollection',
//   features: [{
//     type: 'Feature',
//     geometry: {
//       type: 'Point',
//       coordinates: [102.0, 0.5]
//     },
//     properties: {prop0: 'value0'}
//   }]
// }
glookup.countContainers(point1);
// => 1

glookup.getContainers(point1, {ignorePoints: true});
// => {
//   type: 'FeatureCollection',
//   features: []
// }
glookup.countContainers(point1, {ignorePoints: true});
// => 0

const point2 = {type: "Point", coordinates: [101.0, 0.0]};
glookup.getContainers(point2);
// => {
//   type: 'FeatureCollection',
//   features: [{
//     type: 'Feature',
//     geometry: {
//       type: 'LineString',
//       coordinates: [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.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'}
//   }]
// }
glookup.getContainers(point2, {ignorePolygons: true});
// => {
//   type: 'FeatureCollection',
//   features: [{
//     type: 'Feature',
//     geometry: {
//       type: 'LineString',
//       coordinates: [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0]]
//     },
//     properties: {prop1: 'value1'}
//   }]
// }
glookup.hasContainers(point1, {ignorePoints: true, ignoreLines: true});
// => true

const poly1 = {
  type: 'Polygon',
  coordinates: [
    [[100.0+0.25, 0.0+0.25], [101.0-0.25, 0.0+0.25], [101.0-0.25, 1.0-0.25], [100.0+0.25, 1.0-0.25], [100.0+0.25, 0.0+0.25]]
  ]
}
glookup.getContainers(poly1, {ignorePoints: true, ignoreLines: true});
// => {
//   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 GeoJsonGeometriesLookup(geoJson, [options])

Create an instance of the GeoJSON lookup class.

ParamTypeDescription
geoJsonObjectThe GeoJSON for which create the lookup data.
[options]ObjectOptional options.
options.ignorePointsbooleanIf true the extractor will ignore geometries of type Point.
options.ignoreLinesbooleanIf true the extractor will ignore geometries of type LineString.
options.ignorePolygonbooleanIf true the extractor will ignore geometries of type Polygon.

geoJsonGeometriesLookup.forEachCotainer(geometry, [options]) ⇒ boolean

Iterate on each geometry that completely contains the geometry provided.

Kind: instance method of GeoJsonGeometriesLookup
Returns: boolean - The number of geometries that completely contains the geometry provided iterated. The interiors of both geometries must intersect and, the interior and boundary of the secondary (geometry b) must not intersect the exterior of the primary (geometry a).

ParamTypeDescription
geometryObjectThe geometry of type Point, LineString or Polygon for which to check if a container exists.
[options]ObjectOptional options.
options.limitbooleanIf greater than 0 it will limit the number of results on which iterate.
options.ignorePointsbooleanIf true will ignore geometries of type Point.
options.ignoreLinesbooleanIf true will ignore geometries of type LineString.
options.ignorePolygonbooleanIf true will ignore geometries of type Polygon.

geoJsonGeometriesLookup.getContainers(geometry, [options]) ⇒ Object

Gets the geometries that completely contains the geometry provided.

Kind: instance method of GeoJsonGeometriesLookup
Returns: Object - A FatureCollection of geometries that completely contains the geometry provided. The interiors of both geometries must intersect and, the interior and boundary of the secondary (geometry b) must not intersect the exterior of the primary (geometry a).

ParamTypeDescription
geometryObjectThe geometry of type Point, LineString or Polygon for which to count containers.
[options]ObjectOptional options.
options.limitbooleanIf greater than 0 it will limit the number of results returned.
options.ignorePointsbooleanIf true will ignore geometries of type Point.
options.ignoreLinesbooleanIf true will ignore geometries of type LineString.
options.ignorePolygonbooleanIf true will ignore geometries of type Polygon.

geoJsonGeometriesLookup.hasContainers(geometry, [options]) ⇒ boolean

Checks if there is at least one geometry that completely contains the geometry provided.

Kind: instance method of GeoJsonGeometriesLookup
Returns: boolean - True if there is at least one geometry that completely contains the geometry provided. The interiors of both geometries must intersect and, the interior and boundary of the secondary (geometry b) must not intersect the exterior of the primary (geometry a).

ParamTypeDescription
geometryObjectThe geometry of type Point, LineString or Polygon for which to check if a container exists.
[options]ObjectOptional options.
options.ignorePointsbooleanIf true will ignore geometries of type Point.
options.ignoreLinesbooleanIf true will ignore geometries of type LineString.
options.ignorePolygonbooleanIf true will ignore geometries of type Polygon.

geoJsonGeometriesLookup.countContainers(geometry, [options]) ⇒ number

Counts the number of geometries that completely contains the geometry provided.

Kind: instance method of GeoJsonGeometriesLookup
Returns: number - The number of geometries that completely contains the geometry provided. The interiors of both geometries must intersect and, the interior and boundary of the secondary (geometry b) must not intersect the exterior of the primary (geometry a).

ParamTypeDescription
geometryObjectThe geometry of type Point, LineString or Polygon for which to count containers.
[options]ObjectOptional options.
options.limitbooleanIf greater than 0 it will stop counting when this number of containers has been found.
options.ignorePointsbooleanIf true will ignore geometries of type Point.
options.ignoreLinesbooleanIf true will ignore geometries of type LineString.
options.ignorePolygonbooleanIf true will ignore geometries of type Polygon.

Authors

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.

Keywords

FAQs

Package last updated on 05 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc