def get_region(lat, lon, region_path=REGION_PATH):
"""
Return the 2 character, 1 number code (e.g., IP-3) associated with
the physiographic region that encloses the point specified by
*lat* and *lon*. Return `None` if the point is not interior to any
region. Look for the required files at *region_path*.
"""
try:
regions = shpreader.Reader(os.path.join(region_path, 'ConductivityRegions'))
except:
initialize()
regions = shpreader.Reader(os.path.join(region_path, 'ConductivityRegions'))
geos = regions.geometries()
names = [x.attributes['Name'] for x in regions.records()]
point = Point(convert_lon(lon),
lat)
encloses = [name for name, geo in zip(names, geos) if geo.contains(point)]
if encloses:
assert len(encloses) == 1
return encloses[0]
else:
return None
评论列表
文章目录