Region#
- class lsst.images.Region(geometry: Polygon | MultiPolygon)#
Bases:
objectA 2-d Euclidean region represented as one or more polygons with optional holes.
Parameters#
- geometry
A polygon or multi-polygon from the Shapely library.
Attributes Summary
The area of the region (
float).The integer-coordinate bounding box of the region (
Box).The 'Well-Known Text' representation of this region (
str).Methods Summary
contains()Test whether the geometry contains the given points or another geometry.
difference(other)Compute the point-set difference of this region with another.
from_wkt(wkt)Construct from a 'Well-Known Text' string.
Compute the intersection of this region with a
Boundsobject.Serialize the region to a Pydantic model.
Convert to a
shapely.Polygonorshapely.MultiPolygonobject.transform(transform)Transform the coordinates of the region, returning a new one.
If the underlying geometry is a rectangle that fully covers integer pixels (i.e. has all vertices at half-integer positions), return the equivalent
Box.If the underlying geometry is a single polygon with no holes, return a
Polygoninstance holding it.union(other)Compute the point-set union of this region with another.
Attributes Documentation
- area#
The area of the region (
float).
- bbox#
The integer-coordinate bounding box of the region (
Box).Because a
Boxlogically contains the entirety of the pixels on its boundary, but the centers of those pixels are the numerical values of its bounds, the region may contain vertices that are up to 0.5 beyond the integer box coordinates in either dimension.
- wkt#
The ‘Well-Known Text’ representation of this region (
str).
Methods Documentation
- contains(point: XY[int | float] | YX[int | float], /) bool#
- contains(point: XY[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]] | YX[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]], /) ndarray
- contains(*, x: int | float, y: int | float) bool
- contains(*, x: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], y: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) ndarray
- contains(other: Polygon, /) bool
Test whether the geometry contains the given points or another geometry.
Parameters#
- other
Another geometry, or an
XYorYXcoordinate pair, to compare to. Mutually exclusive withxandy.- x
One or more X coordinates to test for containment, as a scalar or any array-like. Results are broadcast against
y. Mutually exclusive withother.- y
One or more Y coordinates to test for containment, as a scalar or any array-like. Results are broadcast against
x. Mutually exclusive withother.
- difference(other: Region) Region#
Compute the point-set difference of this region with another.
Parameters#
- other
Region to subtract from this one.
- static from_wkt(wkt: str) Region#
Construct from a ‘Well-Known Text’ string.
Parameters#
- wkt
Well-Known Text representation of the region.
- intersection(other: Region) Region#
- intersection(other: Box) Region | Box
- intersection(other: Bounds) Bounds
Compute the intersection of this region with a
Boundsobject.Notes#
Because
Regionimplements theBoundsinterface, its intersections need to support all otherBoundsobjects. This is not true of otherRegionpoint-set operations likeunionanddifference.Parameters#
- other
Bounds to intersect with this region.
- serialize() RegionSerializationModel#
Serialize the region to a Pydantic model.
Region serialization uses a subset of the GeoJSON specification (IETF RFC 7946).
- to_shapely() Polygon | MultiPolygon#
Convert to a
shapely.Polygonorshapely.MultiPolygonobject.
- transform(transform: Transform[Any, Any]) Region#
Transform the coordinates of the region, returning a new one.
Parameters#
- transform
Coordinate transform to apply (in the forward direction).
Notes#
This applies the transform to all vertices, assuming that the transform is close enough to affine that the topology of the geometry does not change and straight-line edges do not need to be subsampled.
- try_to_box() Region | Box#
If the underlying geometry is a rectangle that fully covers integer pixels (i.e. has all vertices at half-integer positions), return the equivalent
Box.In all other cases
selfis returned.