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

which-polygon

Package Overview
Dependencies
Maintainers
28
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

which-polygon

Index for matching points against a set of GeoJSON polygons

  • 2.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
increased by9.97%
Maintainers
28
Weekly downloads
 
Created
Source

A simple index for matching points and bboxes against a set of GeoJSON polygons to find what polygon it belongs to. For example, determining the country of a location given a countries GeoJSON.

Build Status Coverage Status

Example usage

var geojson = require('./countries.json');
var query = whichPolygon(geojson);

query([30.5, 50.5]).admin; // 'Ukraine'

The input GeoJSON must be a feature collection of polygons or multipolygons. The query returns the properties of the matched polygon feature.

By default, the query returns properties of the first polygon that has been found (object or null). To return an array of all found polygon properties, use option multi as the second argument:

query([14.3, 51.2], true); // [{props1}, {props2}, {props3}, ...] || null

Once the index is built, queries are pretty fast — 17 seconds to query 1 million random locations on a Macbook Pro in this particular case.

You can also query all polygons that intersect a given bbox:

var query = whichPolygon(geojson);
var results = query.bbox([30.5, 50.5, 30.51, 50.51]);
results[0].admin; // 'Ukraine'

Keywords

FAQs

Package last updated on 16 Feb 2023

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