GIS Tools

Language

Made withfor the GIS community

Point in Polygon

Find which points fall inside polygon boundaries

Geoprocessing
Try Example:

Points Layer

Drop files here or click to browse

Supported formats: GeoJSON

GeoJSON

Polygon Layer

Drop files here or click to browse

Supported formats: GeoJSON

GeoJSON

Options

About Point in Polygon

  • Tests each point against all polygon boundaries
  • Choose to export inside points, outside points, or all points tagged
  • Optionally transfer polygon attributes to matching points
  • Use cases: address within district, sensor in zone, customer in territory

What Is a Point in Polygon Test?

A point in polygon (PIP) test asks whether a given point lies inside, outside, or on the boundary of a polygon. It is the most fundamental spatial query in GIS and computational geometry. Every time you use a spatial filter, compute a spatial join, geocode to a region, or identify which country a location belongs to, a point-in-polygon test is happening under the hood. At scale, the question becomes: for a set of N points and a set of M polygons, which points fall inside which polygons? This point in polygon test is the basis for spatial query point in polygon workflows, spatial joins, area-based attribute assignment, and geofencing.

The Point in Polygon tool on gis.tools runs PIP queries between a point layer and a polygon layer directly in your browser. Drop in both layers, click Run, and the tool tells you (and records on each point) which polygon each point falls inside. The output is a point layer where each feature has an added attribute pointing to the containing polygon's ID (or null if outside all polygons). There is no upload, no account, no cloud processing.

Point in polygon is often cited as the textbook example of computational geometry because it has an elegant algorithm (the ray casting / even-odd rule) that every GIS student learns. Modern implementations add spatial indexing and winding-number refinements to handle real data efficiently and correctly.

How Point in Polygon Testing Works

Ray Casting Algorithm

The classical algorithm shoots a ray from the point in any direction and counts how many times it crosses the polygon boundary:

  1. From the test point, cast a ray (e.g., eastward horizontally)
  2. Count intersections between the ray and the polygon's edges
  3. If the count is odd, the point is inside; if even, the point is outside

This works for simple polygons and is the basis of turf.booleanPointInPolygon, Shapely.contains, and most GIS implementations.

Winding Number

For complex polygons with holes or self-intersections, the winding number algorithm is more robust. It counts how many times the polygon boundary winds around the test point; nonzero winding means inside.

Spatial Indexing for Batch Queries

For large point and polygon sets, naive pairwise testing is O(n*m) and unacceptable. Modern implementations use an R-tree or STR-tree on the polygon layer to quickly find candidate polygons whose bounding boxes contain the test point, then run the exact PIP test only on candidates. This reduces expected time to O(n log m).

Key Parameters and Options

Boundary Behavior

Choose whether points exactly on the boundary count as inside, outside, or explicitly flagged as boundary.

Multi-Match Mode

If a point falls inside multiple polygons (when polygons overlap), decide whether to record only the first match, the last match, all matches, or just a count.

Output Format

Add the polygon ID or attribute to each point, or emit one row per point-polygon match.

Preserve Unmatched Points

Optionally include points not inside any polygon with null attribute values.

Practical Applications

Geocoding to Administrative Regions

Given a list of addresses (as lat/lon points) and administrative boundary polygons, assign each address to its city, ZIP code, state, or country. This is the spatial query point in polygon workflow at the core of basic geocoding.

Census and Survey Analysis

Assign point-level survey responses to census tracts, block groups, or school attendance areas for demographic aggregation.

Fleet and Asset Tracking

Geofencing: is the vehicle currently inside the authorized zone? Point-in-polygon is the geometric test behind geofence triggers.

Wildlife Movement Analysis

Assign GPS-collared animal locations to habitat types, protected areas, or private vs public land categories.

Emergency Response

When a 911 call comes in, which response zone contains the caller? A fast PIP query on pre-computed response polygons returns the answer.

Retail Customer Segmentation

Assign customer addresses to trade areas, catchment polygons, or competition zones.

Environmental Compliance

Check whether a proposed activity point (well, road segment, building) falls within a protected area or regulatory zone.

Disease Case Aggregation

Join point-level case reports to neighborhood polygons for rate calculation and hotspot mapping.

Step-by-Step Workflow in gis.tools

  1. Open the Point in Polygon tool
  2. Drag in the point layer
  3. Drag in the polygon layer
  4. Select the polygon attribute to attach to each point (e.g., REGION_ID or COUNTRY_NAME)
  5. Choose the boundary behavior and multi-match handling
  6. Click "Run Point in Polygon"
  7. Inspect the output points, now carrying their containing polygon's attributes
  8. Export as GeoJSON, KML, Shapefile, or CSV

Worked Example

An epidemiologist has 8,200 reported disease cases as lat/lon points and needs to assign each case to its census tract for a rate calculation. She drops the case points and the census tract polygons into the Point in Polygon tool, selects GEOID as the polygon attribute to attach, and clicks Run. The tool processes the 8,200 points against 1,430 census tracts in under a second using a spatial index, attaching a GEOID to each case. She exports the result as a CSV, imports into R, and computes per-tract incidence rates for a paper.

Common Pitfalls and Gotchas

  • CRS mismatch: points and polygons must share a CRS. Reproject with EPSG Reprojector & Coordinate Converter.
  • Boundary points: decide explicitly how to handle points on the edge β€” default behavior varies by library.
  • Overlapping polygons: if polygons overlap, a point may be "inside" multiple polygons. Choose multi-match mode carefully.
  • Self-intersecting polygons break even-odd tests. Fix with Geometry Repair.
  • Holes: points inside a hole should be reported as outside the outer ring. Confirm the tool handles this.
  • Longitude wrap: points near the antimeridian may be mistakenly classified due to polygon representation issues.
  • Performance: without spatial indexing, PIP is O(n*m). Always confirm the tool uses an index.
  • Null polygon attribute: if a point falls outside all polygons, the attached attribute should be explicitly null, not an empty string.

Tips for Best Results

  • Reproject both layers to the same CRS before running
  • Validate polygon geometry with GeoJSON Validator & Fixer first
  • Use De-duplication Tool on point input to reduce redundant tests
  • Include unmatched points in the output with null values to get a complete accounting
  • Pair with Spatial Join if you need the full polygon attributes attached, not just the ID

Comparison with Other GIS Approaches

PostGIS uses ST_Contains, ST_Within, or ST_Intersects with GIST spatial indexes for fast batch PIP queries. QGIS has Points in Polygon under Vector > Analysis Tools. ArcGIS Pro has Points in Polygon and Spatial Join. Shapely and GeoPandas in Python offer .within() and .contains(). Turf.js has turf.booleanPointInPolygon. For a single query, any of these work. For batch processing millions of points, PostGIS is the benchmark. The gis.tools browser version is ideal for one-off or medium-scale batch queries without any setup.

Performance Considerations

With a spatial index on the polygon layer, batch point-in-polygon queries scale to hundreds of thousands of points against tens of thousands of polygons in the browser. Without an index, you're limited to maybe a few thousand of each.

Data Privacy and Browser-Based Processing

Point locations are often sensitive (home addresses, medical case coordinates, customer locations). The point in polygon test runs fully in your browser. No raw point data is uploaded.

Related GIS Concepts

Ray casting algorithm is the classic PIP implementation. Winding number is a more robust variant for complex polygons. DE-9IM (Dimensionally Extended 9-Intersection Model) is the formal framework for spatial relationship tests including contains, within, and intersects. Spatial join is the batch generalization of PIP where polygon attributes are transferred to points. Geofencing is the real-time application of PIP for location-aware triggers. R-tree and STR-tree are the spatial indexes that make batch PIP efficient.

Frequently Asked Questions

How do I test if a point is inside a polygon?

Drop the point layer and polygon layer into the tool and click Run. The output adds a polygon ID column to each point.

What if a point is exactly on the boundary?

Boundary handling is configurable β€” treat as inside, outside, or explicitly flagged.

What if a point is inside multiple overlapping polygons?

Multi-match mode lets you keep the first, last, or all matches.

Can I use this as a spatial join?

Yes β€” PIP is a form of spatial join that transfers polygon attributes to points.

Does the tool handle polygons with holes?

Yes β€” points inside holes are correctly classified as outside the outer ring.

Related Tools on gis.tools

100% client-side processing - your data stays private and never leaves your device