utils.py 文件源码

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

项目:faampy 作者: ncasuk 项目源码 文件源码
def is_point_on_land(coords, shape_file=None):
    """Checks if a coords are over land or over water. This is done useing
    a shape file of world boundaries and looping over all Polygons to see
    if the point is in any of it.

    """

    import fiona
    from shapely.geometry import Point, shape

    if not shape_file:
        shape_file='/home/data/mapdata/other/tm_world/TM_WORLD_BORDERS-0.3.shp'

    lon, lat=coords
    pt=Point(lon, lat)
    try:
        fc=fiona.open(shape_file)
    except:
        pass
    result=False
    for feature in fc:
        if shape(feature['geometry']).contains(pt):
          result=True
    fc.close()
    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号