Commit 8c7f8105 authored by Anthony Schrapffer's avatar Anthony Schrapffer
Browse files

Update WMOreg: case island + coastal stations

parent 00bc9b0b
......@@ -36,7 +36,7 @@ class WMOREG:
# Point is (x,y)-(lon,lat)
p1 = Point(lon, lat)
out = np.array([p1.within(poly) for poly in self.polygonWMO])
out = np.array([poly.contains(p1) for poly in self.polygonWMO])
try :
index = np.where(out)[0][0]
stReg, stSubreg = self.attributesPolygonWMO[index]
......@@ -46,5 +46,19 @@ class WMOREG:
return [stReg, stSubreg]
print("lon: {0}; lat: {1}".format(lon,lat))
print("No valid WMO region has been found, verify the lon lat")
print("Inexact location : finding the closest subregion.")
out = np.array([self.get_distance(poly,p1) for poly in self.polygonWMO])
index = np.argmin(out)
stReg, stSubreg = self.attributesPolygonWMO[index]
if output=="num":
return stReg*100+stSubreg
elif output == "list":
return [stReg, stSubreg]
def get_distance(self, poly,p1):
d = poly.exterior.distance(p1)
d = np.min([p.exterior.distance(p1) for p in poly])
return d
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