usgs_regions.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:pyrsss 作者: butala 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号