Box Objects
A Box represents an axis-aligned bounding box.
geodesk.Box(coords)
Constructs a Box from the given coordinates.
WGS-84 (longitude & latitude
minlon/minlat/maxlon/maxlatwest/south/east/northw/s/e/n
Mercator-projected
minx/miny/maxx/maxyleft/bottom/right/top
paris = Box(west=2.2, south=48.8, east=2.5, north=48.9)
geodesk.Box(geom)
Constructs the smallest Box that fully encloses the given Geometry, Feature, Coordinate or Box.
bounds = Box(feature) # same as feature.bounds
bounds2 = Box(polygon) # i.e. the envelope of the Polygon
Properties
Box.minlon
The minimum X coordinate (WGS-84). Alias: west, w
Box.minlat
The minimum Y coordinate (WGS-84). Alias: south, s
Box.maxlon
The maximum X coordinate (WGS-84). Alias: east, e
Box.maxlat
The maximum Y coordinate (WGS-84). Alias: north, n
Box.minx
The minimum X coordinate (Mercator-projected). Alias: left
Box.miny
The minimum Y coordinate (Mercator-projected). Alias: bottom
Box.maxx
The maximum X coordinate (Mercator-projected). Alias: right
Box.maxy
The maximum Y coordinate (Mercator-projected). Alias: top
Box.area
The area (in square meters).
Since 2.2
Box.centroid
The center Coordinate.
Box.shape
The box as a Polygon.
Operators
in checks if a Box contains the given Coordinate (or another Box).
>>> Coordinate(50,100) in Box(10,20,300,200)
True
>>> Box(-20,30,100,50) in Box(10,20,300,200)
False
+ expands a Box so it contains a given Coordinate (or another Box).
>>> b = Box(10,20,300,200)
>>> b + Coordinate(400,300)
Box(10, 20, 400, 300)
| does the same:
>>> Box(10,20,300,200) | Box(50,70,400,500)
Box(10,20,400,500)
& returns the intersection of two Box objects (or an empty box if they don’t intersect).
>>> a = Box(10,20,300,200)
>>> b = Box(50,70,400,500)
>>> a & b
Box(50, 70, 300, 200)
Since an empty Box is falsy, you can use & to check if two boxes intersect:
if a & b:
print("The bounding boxes intersect.")
Methods
Box.buffer(units=*distance*)
Expands this box in all directions by the given distance. Negative values shrink it (which may result in an empty box).