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
评论列表
文章目录