within
Returns true if geometry a lies in geometry b and their interiors intersect.
Geometry a is within geometry b if all points of a are in the interior
or at the boundary of b and the interiors of a and b have at least one
point in common.
note
According to the definition above, a geometry does not contain its boundary, so for example, a LineString that is completely contained in the boundary of a Polygon is not considered to be within that Polygon.
In most cases coveredBy should be used, as it has a simpler
definition and allows for additional optimizations.
within is the converse of contains: within(a, b) === contains(b, a).
warning
Do not use this function with invalid geometries. You will get unexpected results.
Parameters
| Name | Type | Description |
|---|---|---|
a | Geometry | Prepared<Geometry> | First geometry |
b | Geometry | Second geometry |
Returns
boolean
true if geometry a is within geometry b
Throws
GEOSErroron unsupported geometry types (curved)
See also
containsconverse ofwithincoveredBymore inclusivewithinprepareimproves performance of repeated calls against a single geometry