Converter tool

Point in Polygon Lookup for CSV Points

Match every latitude and longitude row of a CSV to the polygon or multipolygon that contains it, with holes respected, a region name added to each row, counts per region and a list of points that fall outside every region.

CSV or XLSX

1. Your points

Or paste the table

GeoJSON with Polygon or MultiPolygon features

2. Your regions

Or paste GeoJSON

Point in Polygon Lookup for CSV Points

Operator: Abdulla Al Fahad. How tools are built and checked

Which sales territory is this address in, which flood zone, which neighbourhood? When the answer has to be written next to thousands of rows, the job is a point-in-polygon test. This tool takes a CSV of latitude and longitude points and a GeoJSON file of Polygon or MultiPolygon features, writes the name of the containing region on every row with holes respected, and reports counts per region and the points that match nothing.

Key features

  • Polygon, MultiPolygon, Feature, FeatureCollection and GeometryCollection input, with holes treated as excluded
  • Region name taken from any feature property or the feature number, with optional columns holding every property of the matched feature
  • Overlapping regions: take the first in the file, or list all and count the point in each
  • Boundary points counted as inside or as outside, by choice
  • Counts per region including regions with zero points, and unmatched points and skipped rows as separate exports

How polygons, holes and multipolygons are tested and what happens on boundaries and overlaps

GeoJSON coordinates are longitude then latitude in WGS84, as RFC 7946 requires. Coordinates outside -180 to 180 and -90 to 90 are refused, because they point to a projected file. Files up to 40 MB are read. Rings that are not closed are closed, rings with fewer than three usable points are skipped and reported, and Point, LineString and null features are ignored with a count.

The points table needs a latitude and a longitude column in decimal degrees or DMS text. Blank or non-numeric coordinates, rows whose latitude exceeds 90 but whose longitude fits, and hemisphere letters in the wrong column (40.5E under latitude) are skipped with the reason in the status column.

How it works

Every polygon gets a bounding box and is registered in a uniform grid over the data extent, so a point meets only the few polygons whose box touches its cell. A point is inside a polygon when a ray cast to the right crosses the outer ring an odd number of times and no hole ring an odd number of times; a point lying on an edge within a tiny tolerance is a boundary point and follows your setting. A polygon whose box covers more than a quarter of the grid (a country-sized shape among city districts, say) is kept in a short separate list that every point checks, so it is not copied into thousands of cells.

Common use cases

  • A retailer assigning 12,000 customer addresses to 38 sales territories supplied as one GeoJSON, then counting customers per territory.
  • An insurer tagging incident points with flood-zone polygons, where holes mark protected areas.
  • A public-health analyst placing case locations in neighbourhoods and checking which neighbourhoods have zero cases.
  • A survey team checking which plot of a multipolygon field set each GPS reading falls in.

How to use this tool

  1. Drop the points file, or paste the table, and check the latitude and longitude columns.
  2. Drop the GeoJSON file or paste its text.
  3. Choose the property that names regions, the overlap rule and the boundary rule.
  4. Read the counts and the table, then download the points with regions, the counts or the unmatched points.

Example

Ten store locations checked against three delivery zones (A Harbour with a hole, B Islands as a MultiPolygon, C Express overlapping A), first match wins, boundary counts as inside

store,lat,lon
Harbour kiosk,10.5,10.5
Pocket cafe,5.0,5.0
Ring road depot,1.5,8.0
Island north,5.0,25.0
Island east,3.0,45.0
West shop,7.0,2.0
On the edge,0.0,10.0
Far away,60.0,60.0
Swapped,-122.2,10.5
Blank,,

Region column and counts

Harbour kiosk: A Harbour
Pocket cafe: outside every region (it stands in A Harbour's hole)
Ring road depot: A Harbour (inside C Express too; listing all gives "A Harbour; C Express")
Island north and Island east: B Islands
On the edge: A Harbour, or outside if boundary points are set to outside
Far away: outside every region
Swapped: skipped, latitude and longitude look swapped
Counts: A Harbour 4, B Islands 2, C Express 0; 2 outside, 2 skipped

Common pitfalls

Polygons that cross the antimeridian must be split at 180 degrees, as RFC 7946 says. An unsplit ring that jumps from 179 to -179 is tested as a very wide shape.

RFC 7946 wants exterior rings counter-clockwise and holes clockwise, and older files often break that. This tool decides inside or outside by counting ray crossings and takes the first ring of a polygon as the outer boundary whatever its direction, so a clockwise exterior still works here. Other software, including some that reads the same file afterwards, can treat a clockwise exterior as a hole or as the whole world outside it.

The test is planar in longitude and latitude, which suits regions of ordinary size but treats long edges as straight lines rather than great circles. Points in a projected CRS, such as British National Grid metres, are not reprojected; they are skipped as out of range.

  • A MultiPolygon of islands counts a point in any island for the whole feature, so counts per region add the parts together.
  • On a tiling of adjacent regions a point exactly on a shared edge matches both neighbours when boundaries count as inside. Set boundaries to outside if you would rather such points fall out as unmatched.

Common errors and how to fix them

Feature 1 has coordinates outside longitude -180 to 180 and latitude -90 to 90. The boundaries look projected; reproject them to WGS84 longitude/latitude first.
Export the layer again in EPSG:4326, for example with ogr2ogr -t_srs EPSG:4326 or the export dialog of your GIS.
No Polygon or MultiPolygon geometry found. Point and line features cannot contain points.
Load a boundary layer, not a layer of points or roads.
This GeoJSON is larger than 40 MB. Simplify the boundaries first.
Simplify the layer, for instance with mapshaper; city-scale points gain nothing from sub-metre boundary detail.

Best practices

  • Give every feature a unique name or id property and choose it as the region name; duplicates are listed as Name (feature 3) so counts are not merged.
  • Run the unmatched export through a sanity check: points outside every region are usually bad coordinates, not true outsiders.
  • Check a few points near boundaries on a web map before trusting a large file.

Holes and multipolygons

A polygon's first ring is its outer boundary and later rings are holes. A MultiPolygon is a list of such polygons. A point belongs to a feature when it is inside the outer ring of any of its polygons and inside none of that polygon's holes.

What the counts mean

With the first-match rule every point is counted once. With list-all, a point inside two overlapping regions is counted in both, and the region counts can add up to more than the number of points.

Frequently asked questions

Why does a point inside a hole match nothing?

Holes are excluded by design. A point in a hole belongs to another feature if one fills the hole, and to none otherwise.

Does the order of features matter?

Only for overlaps under the first-match rule, where the earlier feature wins. Reorder the file or list all regions.

Can I use a shapefile or KML?

Only GeoJSON is read. Convert other layers to GeoJSON in a GIS first, or flatten properties with the GeoJSON to CSV converter if you only need the attributes.

How is a 200,000-point file handled?

Rows are tested one by one against the polygons whose bounding boxes share the point's grid cell, plus the few oversized polygons kept aside, so the work grows with the points rather than with points times polygons. Thousands of nearly identical, full-extent polygons are the exception: each point must then be tested against all of them.