为什么在 cartopy 中检查一个地理点是否在陆地上失败?
Why is checking if a geopoint is on land failing in cartopy?
在 之后,我尝试检查坐标对 (longitude, latitude) = (-3.4066095486248327, 51.38747051763357) 是否代表陆地上的位置。这是我的代码:
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)))
结果是 False
,即使该点在陆地上,我使用 Google Maps 检查了这一点。我还检查了 x
和 y
是否应该在 sgeom.Point(x, y)
中交换位置,但是没有成功,因为结果仍然是 False
.
有人可以帮忙吗?
那个点离海岸很近。你用1:10百万比例尺的海岸线作为"truth"海岸线的位置,但在这个比例尺下,那个点确实不在陆地上,它就在海岸外:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
x = -3.4066095486248327
y = 51.38747051763357
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines(resolution="10m")
ax.scatter([x], [y], transform=ccrs.PlateCarree())
# Land is top half, sea is bottom half of the domain
ax.set_extent([x-.1, x+.1, y-.1, y+.1], crs=ccrs.PlateCarree())
plt.show()
如果你想在这样的尺度上做到这一点,那么你将需要使用更准确的海岸线表示。
在
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)))
结果是 False
,即使该点在陆地上,我使用 Google Maps 检查了这一点。我还检查了 x
和 y
是否应该在 sgeom.Point(x, y)
中交换位置,但是没有成功,因为结果仍然是 False
.
有人可以帮忙吗?
那个点离海岸很近。你用1:10百万比例尺的海岸线作为"truth"海岸线的位置,但在这个比例尺下,那个点确实不在陆地上,它就在海岸外:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
x = -3.4066095486248327
y = 51.38747051763357
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines(resolution="10m")
ax.scatter([x], [y], transform=ccrs.PlateCarree())
# Land is top half, sea is bottom half of the domain
ax.set_extent([x-.1, x+.1, y-.1, y+.1], crs=ccrs.PlateCarree())
plt.show()
如果你想在这样的尺度上做到这一点,那么你将需要使用更准确的海岸线表示。