Spatial & Regions#

fetchez.spatial#

Lightweight spatial utilities for parsing region strings and files into standard bounding boxes. Adaptded from CUDEM.

copyright:
  1. 2012 - 2026 CIRES Coastal DEM Team

license:

MIT, see LICENSE for more details.

fetchez.spatial.region_help_msg()[source]#
class fetchez.spatial.Region(w=None, e=None, s=None, n=None, srs=None)[source]#

Bases: object

A geospatial bounding box object.

Behaves like a tuple (xmin, xmax, ymin, ymax) for backward compatibility, but provides methods for manipulation and format conversion.

__init__(w=None, e=None, s=None, n=None, srs=None)[source]#
property w#
property e#
property s#
property n#
property width#
property height#
valid_p(check_xy=True)[source]#

Check if region is valid.

Parameters:

check_xy (bool, default: True)

Return type:

bool

copy()[source]#
buffer(pct=5, x_bv=None, y_bv=None)[source]#

Buffer the region in place.

Parameters:
center()[source]#

Return center (x, y).

chunk(chunk_size=1.0)[source]#

Split into smaller sub-regions.

Parameters:

chunk_size (float, default: 1.0)

Return type:

List[Region]

to_bbox()[source]#

Export as standard (w, s, e, n) bbox used by many GIS tools.

to_list()[source]#

Export as [w, e, s, n] list.

format(style='gmt')[source]#

String representation.

to_shapely()[source]#
to_wkt()[source]#
to_geojson_geometry()[source]#
classmethod from_list(r_list)[source]#
classmethod from_string(r_str)[source]#
fetchez.spatial.region_from_geojson(fn)[source]#

Parse the bounding box(es) of a GeoJSON file.

Parameters:

fn (str)

Return type:

List[Region] | None

fetchez.spatial.region_from_place(query, centered=True)[source]#

Resolve ‘loc:PlaceName’ to a bounding box.

Parameters:
  • query (str)

  • centered (bool, default: True)

Return type:

Region | None

fetchez.spatial.parse_region(input_r)[source]#

Main function to parse region input into a list of Region objects.

Parameters:

input_r (str | List)

Return type:

List[Region]

fetchez.spatial.fix_argparse_region(raw_argv)[source]#

Argument Pre-processing for negative coordinates.

fetchez.spatial.region_valid_p(region, check_xy=True)[source]#

Legacy wrapper for validity check.

fetchez.spatial.region_center(region)[source]#

Calculate the center of a region.

Parameters:

region (Tuple[float, float, float, float])

fetchez.spatial.region_to_shapely(region)[source]#

Convert a fetchez region (xmin, xmax, ymin, ymax) to a shapely box.

fetchez regions are like GMT: (west, east, south, north) while shapely regions are not: (minx, miny, maxx, maxy)

Parameters:

region (Tuple[float, float, float, float])

fetchez.spatial.region_to_wkt(region)[source]#

Convert a fetchez region (xmin, xmax, ymin, ymax) to WKT (via shapely)

Parameters:

region (Tuple[float, float, float, float])

fetchez.spatial.region_to_bbox(region)[source]#

Convert a fetchez region to a bbox

Parameters:

region (Tuple[float, float, float, float])

fetchez.spatial.region_to_geojson_geom(region)[source]#
Parameters:

region (Tuple[float, float, float, float])

fetchez.spatial.region_from_list(r_list)#
fetchez.spatial.region_from_string(r_str)#
fetchez.spatial.chunk_region(r, s=1.0)[source]#
fetchez.spatial.buffer_region(r, p=5)[source]#