Skip to main content

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

NameTypeDescription
aGeometry | Prepared<Geometry>First geometry
bGeometrySecond geometry

Returns

boolean

true if geometry a is within geometry b

Throws

  • GEOSError on unsupported geometry types (curved)

See also

  • contains converse of within
  • coveredBy more inclusive within
  • prepare improves performance of repeated calls against a single geometry

Examples