GeoWithinQ[reg,loc]
returns True if the location loc is contained within the region reg, and False otherwise.
GeoWithinQ[reg]
represents an operator form of GeoWithinQ that can be applied to a location.
GeoWithinQ
GeoWithinQ[reg,loc]
returns True if the location loc is contained within the region reg, and False otherwise.
GeoWithinQ[reg]
represents an operator form of GeoWithinQ that can be applied to a location.
Details and Options
- In GeoWithinQ[reg,loc], reg can be specified as an entity of a geo domain such as "City", "Country" or "HistoricalCountry"; a Dated[…] object; a GeoVariant[…] expression or an extended GeoGraphics primitive. The location loc can additionally be specified as a GeoPosition or related point-like location object.
- For time-dependent entities, GeoWithinQ[reg,loc] returns by default whether loc is contained in reg at some moment in their history. If the entities have different time spans, then GeoWithinQ returns False.
- Dated[entity,dates] can be used to restrict a time-dependent entity to a given date or interval of dates. GeoVariant[entity,"UnionArea"] can be used to make the computation ignore date information.
- GeoWithinQ accepts lists in both arguments, effectively calling Outer on the input lists.
- GeoWithinQ[reg][loc] is equivalent to GeoWithinQ[reg,loc].
- GeoWithinQ takes the following options:
-
"FullyContained" False whether loc is fully contained within reg TimeConstraint 20 maximum computation time, in seconds - With the option setting "FullyContained"->True, GeoWithinQ[reg,loc] will return True only if loc is completely contained in reg.
Examples
open all close allBasic Examples (2)
New York City is in the United States:
GeoWithinQ[Entity["Country", "UnitedStates"], Entity["City", {"NewYork", "NewYork", "UnitedStates"}]]But it is not in the state of Florida:
GeoWithinQ[Entity["AdministrativeDivision", {"Florida", "UnitedStates"}], Entity["City", {"NewYork", "NewYork", "UnitedStates"}]]Determine if your current location is Champaign, Illinois:
GeoWithinQ[Entity["City", {"Champaign", "Illinois", "UnitedStates"}], Here]Scope (8)
Geographic Data (5)
Test whether France is included in the following polygon:
poly = Polygon[GeoPosition[{{40.42, -3.71}, {48.86, 2.34}, {52.52, 13.38}}]];
GeoWithinQ[poly, Entity["Country", "France"]]Visualize France and the polygon:
GeoGraphics[{Polygon[Entity["Country", "France"]], Red, poly}]Test whether several airports are inside the city of Chicago:
GeoWithinQ[Entity["City", {"Chicago", "Illinois", "UnitedStates"}], {Entity["Airport", "KORD"], Entity["Airport", "KMDW"], Entity["Airport", "KBMI"], Entity["Airport", "KCMI"]}]Test whether a particular location is inside several different regions:
GeoWithinQ[{EntityClass["Country", "NorthAmerica"], EntityClass["Country", "Europe"], Entity["Country", "UnitedStates"], Entity["Country", "France"], Entity["Country", "UnitedKingdom"]}, GeoPosition[{50.08, 14.43}]]GeoGraphics[GeoMarker[{50.08, 14.43}], GeoRange -> "Country"]Test several cities for membership in several regions simultaneously:
GeoWithinQ[{EntityClass["Country", "NorthAmerica"], EntityClass["Country", "Europe"], Entity["Country", "UnitedStates"], Entity["Country", "France"], Entity["Country", "UnitedKingdom"]}, {Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], Entity["City", {"Champaign", "Illinois", "UnitedStates"}], Entity["City", {"Lima", "Lima", "Peru"}], Entity["City", {"Frankfurt", "Hesse", "Germany"}]}]Each row is the result for all locations with respect to a single region:
First[%] === GeoWithinQ[EntityClass["Country", "NorthAmerica"], {Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], Entity["City", {"Champaign", "Illinois", "UnitedStates"}], Entity["City", {"Lima", "Lima", "Peru"}], Entity["City", {"Frankfurt", "Hesse", "Germany"}]}]Use GeoWithinQ as an operator form:
GeoWithinQ[Entity["Country", "UnitedKingdom"]][Entity["City", {"Bath", "BathAndNorthEastSomerset", "UnitedKingdom"}]]Historical Data (3)
The location of the battle of Zama was not yet in the Roman Republic when the battle took place:
GeoWithinQ[Entity["HistoricalCountry", "RomanRepublic"], Entity["MilitaryConflict", "BattleOfZama"]]The location of the battle of Zama was in the Roman Republic later in time:
pos = GeoPosition[Entity["MilitaryConflict", "BattleOfZama"]]GeoWithinQ[Entity["HistoricalCountry", "RomanRepublic"], pos]The location of the city of Paris was not in the Roman Republic in year 250 BC:
GeoWithinQ[Dated[Entity["HistoricalCountry", "RomanRepublic"], -250], Entity["City", {"Paris", "IleDeFrance", "France"}]]It was included in the Roman Republic in year 50 BC:
GeoWithinQ[Dated[Entity["HistoricalCountry", "RomanRepublic"], -50], Entity["City", {"Paris", "IleDeFrance", "France"}]]The Republic of Venice was never in the Roman Empire because they did not overlap in time:
GeoWithinQ[Entity["HistoricalCountry", "RomanEmpire"], Entity["HistoricalCountry", "RepublicVenice"]]GeoVariant[entity,"UnionArea"] represents the union of all polygons of entity at all times in its history, making GeoWithinQ ignore temporal information:
GeoWithinQ[GeoVariant[Entity["HistoricalCountry", "RomanEmpire"], "UnionArea"], Entity["HistoricalCountry", "RepublicVenice"]]Options (2)
"FullyContained" (1)
The United Kingdom is considered to be inside London, since the two entities overlap:
GeoWithinQ[Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}], Entity["Country", "UnitedKingdom"]]The option "FullyContained"->True excludes regions that extend outside the entity:
GeoWithinQ[Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}], Entity["Country", "UnitedKingdom"], "FullyContained" -> True]London is always considered to be inside the United Kingdom:
GeoWithinQ[Entity["Country", "UnitedKingdom"], Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}], "FullyContained" -> True]TimeContraint (1)
Imposing a short time constraint may prevent the function from working:
GeoWithinQ[Entity["Country", "UnitedStates"], Entity["AdministrativeDivision", {"California", "UnitedStates"}], TimeConstraint -> 0.1]The default time constraint allows the computation to give the expected result:
GeoWithinQ[Entity["Country", "UnitedStates"], Entity["AdministrativeDivision", {"California", "UnitedStates"}]]Applications (1)
Determine which of several points are in a group of central states of the United States:
points = {GeoPosition[{40.38, -95.32}], GeoPosition[{35.44, -111.98}], GeoPosition[{37.11, -93.83}], GeoPosition[{45.16, -111.35}], GeoPosition[{44.67, -75.44}]};group = GeoGroup[{Entity["AdministrativeDivision", {"Missouri", "UnitedStates"}], Entity["AdministrativeDivision", {"Illinois", "UnitedStates"}], Entity["AdministrativeDivision", {"Iowa", "UnitedStates"}], Entity["AdministrativeDivision", {"Kansas", "UnitedStates"}]}];GeoWithinQ[group, points]Properties & Relations (2)
GeoWithinQ[list1,list2] is essentially equivalent to Outer[GeoWithinQ,list1,list2]:
GeoWithinQ[{EntityClass["Country", "NorthAmerica"], EntityClass["Country", "Europe"]}, {Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], Entity["City", {"Champaign", "Illinois", "UnitedStates"}], Entity["City", {"Lima", "Lima", "Peru"}]}] === Outer[GeoWithinQ, {EntityClass["Country", "NorthAmerica"], EntityClass["Country", "Europe"]}, {Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], Entity["City", {"Champaign", "Illinois", "UnitedStates"}], Entity["City", {"Lima", "Lima", "Peru"}]}]GeoWithinQ could be implemented using a combination of GeoNearest and MemberQ:
continentalUS = GeoVariant[Entity["Country", "UnitedStates"], "DefaultMapArea"];
point = GeoPosition[{33.92, -118.71}];
GeoWithinQ[continentalUS, point]MemberQ[GeoNearest[{continentalUS}, point, {All, 0}], continentalUS]GeoNearest allows radii to be specified:
MemberQ[GeoNearest[{continentalUS}, point, {All, Quantity[100, "Kilometers"]}], continentalUS]This point is just off the coast of Malibu, California:
GeoGraphics[{PointSize[Large], Point@point}]Possible Issues (2)
With the default option value "FullyContained"False, GeoWithinQ checks for polygon intersection, which may lead to unexpected results:
GeoWithinQ[Entity["GeographicRegion", "Africa"], Entity["Country", "Spain"]]GeoWithinQ uses by default the "PrincipalArea" geo variant of a country, which for Spain contains the Canary islands:
GeoGraphics[{Polygon[Entity["GeographicRegion", "Africa"]], GeoStyling[Red], Polygon[GeoVariant[Entity["Country", "Spain"], "PrincipalArea"]]}, GeoCenter -> Entity["Island", "Lanzarote"], GeoRange -> Quantity[300, "Miles"]]Use "FullyContained"True to check for actual containment:
GeoWithinQ[Entity["GeographicRegion", "Africa"], Entity["Country", "Spain"], "FullyContained" -> True]Or use a geo variant that does not include the overlapping region:
GeoWithinQ[Entity["GeographicRegion", "Africa"], GeoVariant[Entity["Country", "Spain"], "DefaultMapArea"]]GeoWithinQ[entity,loc] uses the polygon available for the given entity, which may not have enough resolution to resolve certain locations correctly, most importantly near the coast:
loc = Interpreter["Location"]["brooklyn bridge"]GeoGraphics[{Polygon[Entity["Country", "UnitedStates"]], GeoMarker[loc]}, GeoCenter -> loc, GeoRange -> Quantity[3, "Miles"]]Therefore this restricted Interpreter call fails:
Interpreter[Restricted["Location", Entity["Country", "UnitedStates"]]]["brooklyn bridge"]The polygon for New York does contain this location:
Interpreter[Restricted["Location", Entity["City", {"NewYork", "NewYork", "UnitedStates"}]]]["brooklyn bridge"]GeoGraphics[{Polygon[Entity["City", {"NewYork", "NewYork", "UnitedStates"}]], GeoMarker[loc]}]See Also
GeoIdentify GeoEntities GeoNearest MemberQ RegionMember GeoBounds GeoBoundingBox GeoVisibleRegion
Entity Types: Country City GeographicRegion
Related Guides
Text
Wolfram Research (2014), GeoWithinQ, Wolfram Language function, https://reference.wolfram.com/language/ref/GeoWithinQ.html (updated 2024).
CMS
Wolfram Language. 2014. "GeoWithinQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/GeoWithinQ.html.
APA
Wolfram Language. (2014). GeoWithinQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GeoWithinQ.html
BibTeX
@misc{reference.wolfram_2026_geowithinq, author="Wolfram Research", title="{GeoWithinQ}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/GeoWithinQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_geowithinq, organization={Wolfram Research}, title={GeoWithinQ}, year={2024}, url={https://reference.wolfram.com/language/ref/GeoWithinQ.html}, note=[Accessed: 13-June-2026]}