# Checking a Point within a Polygon

**URL:** <https://forum.getodk.org/t/checking-a-point-within-a-polygon/50878>\
**Category:** Support\
**Created:** [November 18, 2024, 4:49pm UTC](https://forum.getodk.org/t/checking-a-point-within-a-polygon/50878 "2024-11-18T16:49:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Xiphware](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/xiphware/32/2587_2.png) [@Xiphware](https://forum.getodk.org/u/Xiphware)\
**Post date:** [November 18, 2024, 7:46pm UTC](https://forum.getodk.org/t/checking-a-point-within-a-polygon/50878/2 "2024-11-18T19:46:18Z")

</div>

What you are referring to is typically called a _geofence_.

There are a few different way you can do this, the simplest probably being a purely **circular fence** , which you can enforce by just measuring your distance to the center of the circle. A [distance()](https://docs.getodk.org/form-operators-functions/#distance) function will accomplish this for you, which sounds like what you are doing already.

A slightly complicated **rectangular fence** can be enforced by checking your GPS _latitude_ and _longitude_ each lie within a certain prescribed range. A long-ish [if()](https://docs.getodk.org/form-operators-functions/#if) statement comparing your location to each min & max latitude/longitude will do this for you.

An even more complicated (convex) **polygon fence** can be enforced with a rather more sophisticated algorithm and form; see [ODK geofence (v1)](https://forum.getodk.org/t/odk-geofence-v1/18656), and [Geofencing in ODK forms](https://forum.getodk.org/t/geofencing-in-odk-forms/38378)

But, wait for it...

...there is actually a new dedicated ODK geofence feature coming out Real Soon Now™ (!) If you poke around [javarosa](https://github.com/getodk/javarosa) - the form engine underneath ODK Collect - you might spot it:

> **[Release v4.4.0 · getodk/javarosa](https://github.com/getodk/javarosa/releases/tag/v4.4.0)**
>
> What's Changed
> 
> Additions needed for offline entity creation by @seadowg in #748
> Additions needed for offline entity updates by @seadowg in #749
> Expose action with entity by @seadowg in #755
> Add ab...

(or if you like deciphering code, start digging around [https://github.com/getodk/javarosa/blob/master/src/main/java/org/javarosa/xpath/expr/XPathFuncExpr.java](https://github.com/getodk/javarosa/blob/master/src/main/java/org/javarosa/xpath/expr/XPathFuncExpr.java))

This should show up in an upcoming release of ODK Collect/KoboCollect.

[Disclaimer: written by yours truly 😉]

---

_[View the full topic](https://forum.getodk.org/t/checking-a-point-within-a-polygon/50878)._
