npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

point-in-geopolygon

v1.0.1

Published

Determine if a point is inside a GeoJSON feature (polygon or Multipolygon).

Downloads

2,574

Readme

Example 1 (Determine if a point is inside a GeoJSON Polygon)

The GeoJSON Polygon is defined by an array of its vertex. The first vertex in the array and the last one MUST be the same point.

var inside = require('point-in-geopolygon');
var jad = [ [ [ 2, 2 ], [ 5, 2 ], [ 5, 6 ], [ 2, 6 ],[ 2, 2 ] ] ];
 
console.log([inside.polygon(jad,[3,3] ),inside.polygon(jad,[4,3]),inside.polygon(jad, [9,12])]);

output

[ true, true, false ]

Example 2 (Determine if a point is inside a GeoJSON data source)

var inside= require('point-in-geopolygon');
var map= JSON.parse('{ "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": {"city": "Myland","time": "+1"}}]}');
 
console.log([inside.feature(map,[100,0.5] ),inside.feature(map,[0,0])]);

output

[ { id: 0, properties: { city: 'Myland', time: '+1' },  type: 'Polygon' }, -1 ]

Methods

var inside = require('point-in-geopolygon');

inside.polygon(geoPolygone,point)

Return boolean whether point is inside geojson polygon. Point should be a 2-item array of coordinates. Geojson polygon should be an array of 2-item arrays of coordinates first and last vertex are the same exp: [[p1,p2,p4,p1]] where pi=[xi,yi] The method does not distinguish between clockwise and anti clockwise polygon vertex arrangement.

inside.feature(geoJsonObj,point)

GeoJson Feature supported are Polygon and Multipolygon. Point should be a 2-item array of coordinates. Geojson object contains features array describing different region exp: Geojson.features=[Obj0,Obj1,Obj2..] where Obji={"type":"Feature","geometry":{"type":"Polygon","coordinates"...}} The Method returns object if the point is inside geoJson Object feature else -1. Returned object {id, properties, type} id: feature rank in the features array GeoJson Object. properties: feature properties type: feature geometry type The method does not distinguish between clockwise and anti clockwise polygon vertex arrangement.

Install

npm install point-in-geopolygon

Todos

  • The method will distinguish between clockwise and anticlockwise polygon vertex arrangement

License

MIT

Free Software, Hell Yeah!