【问题标题】:Why is checking if a geopoint is on land failing in cartopy?为什么检查地理点是否在土地上失败?
【发布时间】:2019-02-11 12:22:26
【问题描述】:

this answer 之后,我尝试检查坐标对(经度、纬度)= (-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 进行了检查。我还检查了xy 是否应该在sgeom.Point(x, y) 中交换位置,但这并没有成功,因为结果仍然是False

有人可以帮忙吗?

【问题讨论】:

    标签: cartopy


    【解决方案1】:

    那个点非常靠近海岸。您已经使用 1:10 百万比例的海岸线作为关于海岸线位置的“真相”,但在这个比例下,该点确实不在陆地上,它就在海岸附近:

    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()
    

    如果您想在这样的比例尺上做到这一点,那么您将需要使用更准确的海岸线表示。

    【讨论】:

    • 感谢您的回答。如何找到更准确的海岸线表示?
    • 嗯,这部分取决于您和您的应用程序的需求。对于这种方法,您需要一个更准确的 shapefile。您可以尝试ngdc.noaa.gov/mgg/shorelines/gshhs.html 看看是否适合,但适合您的方法取决于您希望能够进行此测试的地区。
    • 谢谢。我是新手,所以我很感激所有的建议和提示。
    猜你喜欢
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多