Commit d7d316f1 authored by Clément Haëck's avatar Clément Haëck
Browse files

Add center property to box

add corner_(ll|ur) properties

shape is made using shapely.geometry.box
simpler
parent 86521a31
......@@ -5,6 +5,8 @@ longitude.
"""
from os import path
from shapely.geometry import box
from matplotlib.patches import Rectangle
import lib
......@@ -49,6 +51,31 @@ class Box:
def lat_bounds(self, value):
self.lat_min, self.lat_max = value
@property
def corner_ll(self):
"""Lower left corner."""
return [self.lon_min, self.lat_min]
@corner_ll.setter
def corner_ll(self, value):
self.lon_min, self.lat_min = value
@property
def corner_ur(self):
"""Upper right corner."""
return [self.lon_max, self.lat_max]
@corner_ur.setter
def corner_ur(self, value):
self.lon_max, self.lat_max = value
@property
def center(self):
"""Center point as tuple."""
cx = (self.lon_min+self.lon_max)/2.
cy = (self.lat_min+self.lat_max)/2.
return (cx, cy)
def __str__(self):
s = '{:.2f} - {:.2f} ; {:.2f} - {:.2f}'.format(
self.lon_min, self.lon_max, self.lat_min, self.lat_max)
......@@ -57,6 +84,11 @@ class Box:
def __repr__(self):
return super().__repr__() + '\n' + self.__str__()
def get_shape(self):
"""Get shapely Polygon object."""
sh = box(*self.corner_ll, *self.corner_ur)
return sh
def extract(self, ds, enlarge=False):
"""Return dataset (or array) inside box.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment