within_polygon(...)
Returns the rows that have locations within the specified box, defined by latitude, longitude corners
Works with the following datatypes:
This function works with 2.1 endpoint(s). What does this mean? »
The within_polygon(...)
function is used in the $where
parameter filter for Point
, Line
, and Polygon
values within a polygon defined by a sequence points. It accepts two parameters:
Well-Known Text is a standard way of encoding geospatial data in a textual manner, and is more compact than GeoJSON:
MULTIPOLYGON ((-87.637714 41.887275, -87.613681 41.886892, -87.625526 41.871555, -87.637714 41.887275))
Heads up! Contrary to the normal convention of "latitude, longitude" ordering in the coordinates
property, Well-known text orders the coordinates as "longitude, latitude" (X coordinate, Y coordinate), as other GIS coordinate systems are encoded.
For example, to query for all of the Chicago 311 service requests for vacant and abandoned buildings within that polygon:
Cool Tool! Formatting shapes as WKT for testing is tedious and error-prone - I don't recommend it. Instead, use a library that can generate them for you, or a tool like Wicket to draw them in your browser.