Skip to content

Commit

Permalink
Add imput method for tgeo.BoundingBox + add domain + add center_point…
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
ThomasRieutord committed Sep 20, 2023
1 parent 948f726 commit 9610d7f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mmt/utils/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ def __init__(self, coords, fmt = "llmm", crs = None):
self.extract_boundingbox_(points)
elif fmt=="points":
self.extract_boundingbox_(coords)
elif fmt=="tgbox":
assert isinstance(coords, TgeoBoundingBox), "With fmt='tgbox', the coords arg must be a torchgeo.BoundingBox"
self.min_longitude = coords.minx
self.max_longitude = coords.maxx
self.min_latitude = coords.miny
self.max_latitude = coords.maxy
elif fmt=="epsg":
if crs is None:
raise ValueError("Please provide in 'crs' the rasterio.crs.CRS of your coordinates when using fmt='epsg'")
Expand Down Expand Up @@ -281,6 +287,9 @@ def to_str(self, collate_char = "_", n_digits = 6):
def enlarge(self, factor):
return enlarge_domain(self, factor)

def central_point(self):
return get_central_point(self)

def __str__(self):
return ", ".join(
[
Expand Down Expand Up @@ -351,6 +360,12 @@ def bbox_from_bboxs(bboxs):

return GeoRectangle(pts, fmt="points")

def get_central_point(domain):
"""Return the coordinates of the points at the center of the rectangle"""
x = (domain.min_longitude + domain.max_longitude)/2
y = (domain.min_latitude + domain.max_latitude)/2
return x, y

def enlarge_domain(domain, factor = 1):
"""Create a larger domain than the one provided. Suitable only for small domains.
Expand Down Expand Up @@ -414,3 +429,8 @@ def enlarge_domain(domain, factor = 1):
reunion_crops = GeoRectangle([55.6638, 55.7004, -21.0505, -21.0150])
# Small island
savage_canary_island = GeoRectangle([-15.8935, -15.8517, 30.1319, 30.1677])
# Another small island
iso_kihdinluoto = GeoRectangle(TgeoBoundingBox(
minx=21.122670101126037, maxx=21.239336767792704, miny=60.483903274933496, maxy=60.60056994160016, mint=0.0, maxt=1000000000000.0
), fmt="tgbox")

0 comments on commit 9610d7f

Please sign in to comment.