Planetary-scale answers, unlocked.
A Hands-On Guide for Working with Large-Scale Spatial Data. Learn more.
Authors
A geofence is a virtual boundary drawn around a real place on a map. When a phone, car or ship crosses that boundary, software records it: going in is an entry, and going out is an exit. The check is simple. The result depends on how often the device reports its position. If a ship reports once every 15 minutes and spends 10 minutes inside a zone, the visit can fall between two reports and go uncounted.
We tested that on the right whale speed zones off the U.S. East Coast. Ships 65 feet or longer must slow to 10 knots inside these zones during set seasons. We ran a geofence check in Wherobots on 42.7 million positions of those ships from March 2024. With one position per minute, we counted 7,689 zone visits. With one position every 15 minutes, 203 of those visits went uncounted, and all 203 were shorter than 15 minutes.
Google's Android developer guide, Create and monitor geofences says: "the latitude, longitude, and radius define a geofence, creating a circular area, or fence, around the location of interest." Washington's My Health My Data Act defines one in law as "a virtual boundary that is 2,000 feet or less from the perimeter of the physical location."
A geofence does not have to be a circle. A port, a school campus or a speed zone is usually a polygon: a shape made of straight edges between corner points. The right whale zones in our test are polygons and circles cut by the coastline.
Geofencing is the process of checking locations against geofences and acting on the result. The action can be an alert, a log entry, a rule that applies only inside the zone, or an ad.
Each location is a point: a latitude and a longitude. The core question is whether the point falls inside the geofence polygon. Computer scientists call this the point-in-polygon problem.
The common method is to draw a line from the point in one direction and count how many polygon edges the line crosses. An odd count means the point is inside; an even count means it is outside. Moshe Shimrat published this method as Algorithm 112 in Communications of the ACM in 1962. Eric Haines compared the speed of several point-in-polygon methods in Point in Polygon Strategies (Graphics Gems IV, 1994). Kai Hormann and Alexander Agathos covered the cases where a point sits on an edge in The point in polygon problem for arbitrary polygons (Computational Geometry, 2001).
In SQL (Structured Query Language), the test is a function such as ST_Intersects or ST_Contains. ST_Contains returns false for a point on the boundary; ST_Intersects returns true.
ST_Intersects
ST_Contains
One inside-or-outside answer is a state. An event comes from comparing two states in time order:
Android's geofencing API uses these three events. Google's guide recommends the dwell event to "reduce 'alert spam'". A device near the edge can flip in and out, because each reported location is a few meters off. The app developer sets the dwell time, called the loitering delay.
A phone app tracks a few geofences. A fleet or shipping system checks millions of locations against thousands of zones. That is a spatial join: a join between two tables on a spatial test in place of a shared key. A spatial index finds the few zones near each point before the exact test runs. The R-tree, which Antonin Guttman introduced in R-trees: a dynamic index structure for spatial searching (ACM SIGMOD, 1984), is one such index.
Speed zones at sea. The National Oceanic and Atmospheric Administration (NOAA) runs NOAA Fisheries, the agency that protects marine mammals. It requires most vessels 65 feet or longer to travel at 10 knots or less in set zones along the East Coast at set times of year. These zones are Seasonal Management Areas (SMAs). Each one is a geofence with a season attached.
The rule is section 224.105 of Title 50 of the Code of Federal Regulations (CFR), written 50 CFR 224.105. It took effect through a 2008 final rule.
Fleets and vehicles. Fleet software records when a truck enters or leaves a depot or a customer site, which gives arrival and departure times. Jean-François Reclus and Kristen Reed-Drouard described geofencing to control and manage heavy goods vehicles at the 16th Intelligent Transport Systems (ITS) World Congress in Stockholm in 2009.
Phones and apps. An app can register up to 100 geofences per user on an Android device, according to Android's guide. A store app can alert a store when a customer arrives to pick up an order.
Marketing. Geofencing marketing sends an ad or a notification when a phone enters an area such as a store or a stadium. It uses the same entry check.
Law enforcement. A geofence warrant asks a company for records of every device inside an area during a time window.
Geofencing needs a stream of locations. The legal questions are about who holds that stream and who can ask for it.
Phones. Android's API alerts an app when the phone enters or leaves a registered geofence. The app needs location permission to register geofences. Phone locations from Wi-Fi networks can be tens of meters off, so Android's guide recommends a radius of at least 100 to 150 meters.
Health care. Washington's My Health My Data Act makes it unlawful to place a geofence around an in-person health care facility for three uses. They are identifying or tracking people seeking care, collecting their health data, and sending them ads.
Geofence warrants. In United States v. Chatrie, police served Google with a warrant after a 2019 bank robbery near Richmond, Virginia. Google first returned 19 accounts linked to devices within 150 meters of the bank in the 30 minutes before and after the robbery, the Supreme Court news site SCOTUSblog reported.
On June 29, 2026, the Supreme Court held 6 to 3 that getting these records was a Fourth Amendment search. Justice Elena Kagan wrote for the majority. The Court sent the case back to decide whether the search was reasonable. Earlier, in United States v. Smith (2024), the Fifth Circuit held geofence warrants to be general warrants, which the Fourth Amendment forbids.
Where the data sits. In December 2023 Google announced that Location History, renamed Timeline, would be saved on the user's device.
In this section we run a geofence check on a month of ship positions. We ran it in WherobotsDB, the spatial SQL engine in Wherobots, which comes from the original creators of Apache Sedona. Ships broadcast their position by AIS (Automatic Identification System), a radio system that reports a ship's identity, position, course and speed. The geofences are the right whale SMAs.
North Atlantic right whales are endangered. NOAA Fisheries estimated 384 right whales alive at the start of 2024. Vessel strikes are one of the threats it lists. Angelia Vanderlaan and Christopher Taggart studied this in Vessel collisions with whales: the probability of lethal injury based on vessel speed (Marine Mammal Science, 2007). They found that the chance a strike kills a whale falls below one half at 11.8 knots.
Claim. A geofence check is one spatial join. Its result depends on how often each ship reports its position. With a report every minute, ships near a zone edge produce a few false entries and exits, and a dwell rule removes them. With a report every 15 minutes, short visits go uncounted.
What would support it. At one position per minute, few visits are short re-entries. When we keep fewer positions, the visits we lose are the short ones.
What would break it. Many visits at one position per minute are re-entries within minutes, so most raw events are false. Or keeping fewer positions loses long visits as often as short ones.
The positions come from NOAA Marine Cadastre AIS data for 2024. These are daily GeoParquet files of U.S. AIS records, downsampled by NOAA to one position per vessel per minute. Larger ships carry a Class A transmitter. It reports every 2 to 10 seconds while underway, under the AIS standard of the International Telecommunication Union, ITU-R M.1371. So NOAA's files already keep only a few of the reports each ship sent.
We loaded all 31 days of March 2024 into Wherobots: 235,256,466 positions from 37,812 vessels. We kept positions between 24 and 46 degrees north and 60 and 82 degrees west: 61,586,520 positions from 14,190 vessels. The rule applies to vessels 65 feet (19.8 meters) or longer, so we kept positions from ships with a reported length of at least 19.8 meters: 42,691,450 positions. A few ships have two rows in the same minute. We kept the first row per ship per minute, which left 42,680,220 positions from 5,987 ships.
The zone boundaries come from NOAA's Seasonal Management Areas map data. There are 10 zones. Nine were in season for all of March. The Great South Channel zone runs from April 1 to July 31, so we left it out.
Step 1 is the geofence check: a spatial join between the positions and the zones.
sedona.sql("""SELECT CAST(get_json_object(props,'$.objectid') AS INT) zid, get_json_object(props,'$.location') zone, geom FROM org_catalog.geofence.sma WHERE get_json_object(props,'$.location') <> 'Great South Channel'""").createOrReplaceTempView("z") sedona.sql("""SELECT mmsi, t, ts, sog, vessel_type, length, geom FROM ( SELECT mmsi, t, CAST(unix_timestamp(t) AS BIGINT) ts, sog, vessel_type, length, geom, ROW_NUMBER() OVER (PARTITION BY mmsi, CAST(unix_timestamp(t) / 60 AS BIGINT) ORDER BY t) r FROM org_catalog.geofence.ais_east_2024_03 WHERE length >= 19.8) WHERE r = 1""").createOrReplaceTempView("p") sedona.sql("SELECT p.mmsi, p.ts, z.zid FROM p JOIN z ON ST_Intersects(z.geom, p.geom)").writeTo("org_catalog.geofence.inside").createOrReplace()
mmsi is the ship's radio identity number. sog is speed over ground in knots, as the ship's transmitter reported it.
mmsi
sog
Step 2 turns inside-or-outside states into visits. For each ship that entered a zone, the query lines up all its positions in time order. It flags each one as in or out of that zone, in the table tr. A visit starts at an inside position whose previous position was outside, or came more than 30 minutes earlier:
tr
WITH s AS ( SELECT *, LAG(inz) OVER w AS pin, LAG(ts) OVER w AS pts FROM tr WINDOW w AS (PARTITION BY zid, mmsi ORDER BY ts)), b AS (SELECT *, CASE WHEN inz = 1 AND (pin IS NULL OR pin = 0 OR ts - pts > 1800) THEN 1 ELSE 0 END AS st FROM s), g AS (SELECT *, SUM(st) OVER (PARTITION BY zid, mmsi ORDER BY ts ROWS UNBOUNDED PRECEDING) AS vid FROM b WHERE inz = 1) SELECT zid, mmsi, vid, MIN(ts) t_in, MAX(ts) t_out, COUNT(*) n_rec FROM g GROUP BY zid, mmsi, vid
Step 3 keeps fewer positions. For each ship and zone, the query keeps the first position in each 5-minute or 15-minute block. A visit counts as missed when no kept position falls inside the zone between its entry and exit:
WITH th AS (SELECT zid, mmsi, ts, inz FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY zid, mmsi, CAST(ts / 900 AS BIGINT) ORDER BY ts) r FROM tr) WHERE r = 1), hit AS (SELECT v.zid, v.mmsi, v.vid, MAX(th.inz) found FROM v LEFT JOIN th ON th.zid = v.zid AND th.mmsi = v.mmsi AND th.ts BETWEEN v.t_in AND v.t_out GROUP BY v.zid, v.mmsi, v.vid) SELECT COUNT(*) visits, SUM(CASE WHEN COALESCE(found, 0) = 0 THEN 1 ELSE 0 END) missed FROM hit
The spatial join found 1,716,855 positions inside the 9 zones, from 1,576 ships. Step 2 grouped them into 7,689 visits. 329 visits had a single position, and 393 lasted less than 3 minutes.
Few visits were false re-entries. 106 visits (1.4%) started within 10 minutes of the same ship leaving the same zone, and 22 within 3 minutes. We applied a dwell rule: merge visits split by 10 minutes or less outside the zone, then keep visits of 3 minutes or more. That left 7,208 visits, 6.3% fewer than the raw count.
Keeping fewer positions lost only short visits. At one position every 5 minutes, 80 of the 7,689 visits (1.0%) had no position inside the zone. All 80 lasted less than 5 minutes. At one position every 15 minutes, 203 visits (2.6%) went uncounted: 152 of 470 visits under 5 minutes (32.3%) and 51 of 309 visits of 5 to 15 minutes (16.5%). No visit of 15 minutes or more was missed at either rate.
On March 28, 2024, a ship crossed a corner of the Block Island Sound zone off Montauk, New York. It reported 12 positions inside the zone over 13 minutes, at 8.3 to 9.9 knots.
The map shows 63 of its one-minute positions. Keeping one position every 15 minutes leaves 5 of them, and none of those is inside the zone. A line drawn between the kept positions crosses the zone, but the geofence check only tests the positions.
The geofence check also gives the speed of each ship at each position inside the zones. We compared moving ships inside the zones with moving ships in the waters around them. "Moving" means a reported speed of 1 knot or more. We left out vessels reporting the military or law enforcement type, since the rule exempts federal vessels and state law enforcement vessels on duty.
"Around them" means within 30 nautical miles (55.6 km) of a zone's edge. We buffered each zone by that distance with ST_Buffer on the spheroid, then tested positions with ST_Intersects.
ST_Buffer
Inside the zones, 8.3% of moving positions were over 10 knots, with a median speed of 7.5 knots. Within 30 nautical miles outside the zones, 32.1% were over 10 knots, with a median of 8.2 knots. Every one of the 1,528 ships inside a zone also had positions in the nearby waters. Their own positions there were over 10 knots 34.0% of the time. The Mid-Atlantic band off Georgia and the Carolinas had the highest share inside a zone, at 18.6%.
These numbers count positions. Measuring compliance with the rule needs more data. Speed comes from each ship's own transmitter. Ships may deviate from the limit to keep a safe maneuvering speed, and a few ships report no length. Ships also slow down near ports for other reasons, so the gap between inside and outside is not all caused by the rule.
NOAA's 2020 assessment of the speed rule reported that in most zones more than 85% of vessels subject to the rule kept speeds under 10 knots. Our position share inside the zones, 91.7% at or under 10 knots, is in the same range.
The claim held. At one position per minute, 1.4% of visits were re-entries within 10 minutes, and a dwell rule cut the visit count by 6.3%. At one position every 15 minutes, 2.6% of all visits went uncounted. They were 32.3% of visits under 5 minutes and 16.5% of visits of 5 to 15 minutes. No longer visit was lost.
The NOAA files keep one position per ship per minute, so this test cannot measure visits shorter than a minute.
Point in polygon (1962 to 2001). Shimrat's 1962 algorithm counted edge crossings. Haines (1994) compared the speed of crossing tests, angle-summing tests and grid methods. Hormann and Agathos (2001) gave a test that handles points on the boundary and polygons whose edges cross each other.
Spatial indexes (1984). Guttman's R-tree grouped nearby shapes into nested boxes, so a query reads only the boxes near a point. Spatial databases use R-trees and similar indexes to run point-in-polygon joins on large tables.
Geofencing for vehicles (2009). Reclus and Reed-Drouard applied geofences to heavy goods vehicles in a paper at the ITS World Congress.
Speed zones for whales (2007 to 2014). Vanderlaan and Taggart (2007) linked vessel speed to the chance that a strike kills a whale. NOAA set the 10-knot zones in a 2008 rule.
Paul Conn and Gregory Silber wrote Vessel speed restrictions reduce risk of collision-related mortality for North Atlantic right whales (Ecosphere, 2013). They estimated that the restrictions cut the risk of a strike killing a whale by 80 to 90%. David Laist, Amy Knowlton and Daniel Pendleton wrote Effectiveness of mandatory vessel speed limits for protecting North Atlantic right whales (Endangered Species Research, 2014). They mapped right whale carcasses from vessel strikes against the 10 zones, before and after the rule.
Geofences at scale (2015 onward). Checking every position of every ship against every zone is a spatial join over millions of rows. Jia Yu, Jinxuan Wu and Mohamed Sarwat introduced GeoSpark (ACM SIGSPATIAL, 2015) to run spatial joins on Apache Spark, a system that splits data processing across many machines. Yu, Zongsi Zhang and Sarwat described how it divides spatial data across machines in Spatial data management in Apache Spark: the GeoSpark perspective and beyond (GeoInformatica, 2018). GeoSpark became Apache Sedona, the engine WherobotsDB is built on.
The Wherobots post Streaming Spatial Data into Wherobots with Spark Structured Streaming runs the same check on live data. Each micro-batch of incoming asset positions is joined to a table of geofence polygons with ST_Intersects. A micro-batch is the small group of records a stream processes at one time.
Wherobots is the AI Context Engine for Physical World Data. Run geofence checks on your own location data at cloud.wherobots.com.
A geofence is a virtual boundary drawn around a real place on a map. When a phone, car or ship crosses that boundary, software records it. Going in is an entry, and going out is an exit. Each event can start an action, such as an alert, a log entry or a notification.
Geofencing needs a location to work, so the device or service that runs it reads your location. On an Android phone, an app can register up to 100 geofences with the operating system and gets an alert when the phone enters or leaves one. The app needs location permission to register geofences.
In law enforcement, a geofence warrant asks a company for records of devices that were inside an area during a time window. In June 2026 the U.S. Supreme Court held in Chatrie v. United States that getting those records is a Fourth Amendment search.
In cars and trucks, a geofence is a zone in fleet or vehicle software. The software records when a vehicle enters or leaves a depot, a customer site or a restricted area, and can send an alert. Fleets use these events to log arrival and departure times and to check that vehicles stay on approved routes. Research on heavy goods vehicles has used geofences to control where trucks may drive.
With geofencing, software turns a stream of locations into events tied to a place: entered, left, or stayed for a set time. Software can then act on each event, with no person watching a map. One example is a speed rule that applies only inside a zone. Others are a delivery app that alerts a store when a courier arrives, and a fleet log of arrival and departure times.
Geofencing itself is legal and common in apps, fleets and shipping. Some uses are limited by law. Washington’s My Health My Data Act bans geofences around in-person health care facilities for some uses. These are tracking people seeking care, collecting their health data and sending them ads.
Geofence warrants, which ask a company for every device inside an area during a time window, are a Fourth Amendment search under the 2026 Supreme Court decision in Chatrie v. United States.
A geofence warrant asks a company that stores location history, such as Google, for records of every device inside an area during a time window. In Chatrie v. United States, the warrant asked for devices within 150 meters of a bank in the 30 minutes before and after a 2019 robbery, and Google returned 19 accounts. The Supreme Court held 6 to 3 that this was a search and sent the case back to decide whether it was reasonable.
A geofence is only as accurate as the location that feeds it and how often that location arrives. Android’s documentation recommends a radius of 100 to 150 meters to cover the error of locations from Wi-Fi networks, and says alerts usually arrive within 2 minutes. In a test on March 2024 ship positions, with one position every 15 minutes, 32.3% of zone visits shorter than 5 minutes went uncounted.
Geofencing marketing sends an ad or a notification to a phone when it enters an area, such as a store or an event. It uses the same entry check as any other geofence. Some laws limit it: Washington state bans geofences around health care facilities for ads to people seeking care.
Store each geofence as a polygon in one table and each location as a point in another. A spatial join with ST_Intersects or ST_Contains returns the points inside each geofence. Window functions then order each device’s points by time and mark where it moved from outside to inside (an entry) or from inside to outside (an exit).
What is a Kelvin Wave? Speed, El Niño and 2026 Data
A Kelvin wave is a long, low ocean wave that carries warm water east along the equator in an El Niño. In the 30 days to 10 November 2026, the sea at San Diego stood a record 41.2 cm above NOAA's tide prediction.
What Is an ETL Pipeline? Steps, Examples and Spatial ETL
An ETL (extract, transform, load) pipeline moves data from sources into storage. Learn the steps with examples. Then see a spatial mistake that passed the usual checks: rounding coordinates emptied 27% of Denver's building outlines.
What is an MCP Server? Spatial Context for AI Agents
An MCP server gives AI agents tools to call. With no tools, Claude Code gave no count of San Francisco's buildings. Via Wherobots MCP, it counted 162,538.
share this article
Awesome that you’d like to share our articles. Where would you like to share it to: