Following this answer, I tried to check if the coordinate pair (longitude, latitude) = (-3.4066095486248327, 51.38747051763357) represents a location on land. Here is my code:
import fiona
import cartopy.io.shapereader as shpreader
import shapely.geometry as sgeom
from shapely.prepared import prep
geoms = fiona.open(shpreader.natural_earth(resolution='10m', category='physical', name='land'))
land_geom = sgeom.MultiPolygon([sgeom.shape(geom['geometry']) for geom in geoms])
land = prep(land_geom)
x = -3.4066095486248327
y = 51.38747051763357
print(land.contains(sgeom.Point(x, y)))
The result is False
even though the point is on land, which I checked using Google Maps. I also checked if x
and y
should switch places in sgeom.Point(x, y)
, but that didn't work out as the result was still False
.
Can somebody help?