确定一个地方(给定的坐标)是在陆地上还是在海洋上

2024-05-16 05:54:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些来自国际空间站的坐标,我想知道当坐标被记录下来时,国际空间站是在陆地上还是海洋上,我应该离线进行,但我不知道该用什么方法。 作为python标准库的一部分,我仅限于使用以下库:

numpy
scipy
tensorflow
pandas
opencv-python
opencv-contrib-python
evdev
matplotlib
logzero
pyephem
scikit-image
scikit-learn
reverse-geocoder

不过,如果你知道如何使用其他库来实现这一点,那就更好了。在

通过这段代码,我得到坐标并将其写入文件:

^{pr2}$

你们知道吗? 提前谢谢。在


Tags: 方法numpypandas标准matplotlibtensorflowscipyscikit
2条回答

最后,我只能使用这些库来解决我的问题。 我用这个网站geoplaner得到了海洋形状的大致轮廓(它真的很粗糙,因为我是手工制作的,但它对我的目的来说很好,我认为网上应该有一些更精确的多边形,但我不知道如何使用它们)。在

我对每个海洋都这样做了,得到了这个(注意,我使用的坐标并没有完全覆盖海洋,例如,我避开了南大洋):

    atlanticOcean = [(-24.6,68.5), (25.3,69.8), (5.7,61.4), (4.6,52.2), (-6.3,48.4),
            (-9.45,43.5), (-9.63,37.6), (-6.3,35.5), (-10.5,31.1), (-10.5,28.4),
            (-16.1,24.5), (-17.2,14.7), (-8.2,4.1), (6.3,3.6), (9.9,3.4),
            (9,-1.7), (13.8,-12.6), (11.7,-16.5), (14.5,-22.3), (16.1,-28.67),
            (18.9,-34.5), (18.9,-55.7), (-66,-55.7), (-68.5,-50.4), (-58.6,-39.3), (-48.1,-28.2),
            (-48.1,-25.7), (-41.6,-22.7), (-38.7,-17.4), (-39.5,-13.7), (-36.9,-12.5),
            (-34.9,-10.4), (-35.0,-5.5), (-50,-0.1), (-53,5.5), (-57.2,6.1),
            (-62.8,10.9), (-67.8,10.9), (-74.2,10.8), (-76.9,8.5), (-81.6,9.4),
            (-82.7,14), (-87.4,16.1), (-86.3,21.6), (-90.2,21.7), (-91.2,19.2),
            (-95.7,18.8), (-97.1,25.5), (-91.0,28.9), (-84,29.7), (-82.9,27.3),
            (-80.9,24.9), (-79.3,26.7), (-81.1,31.3), (-75.4,35.2), (-73.8,40.3),
            (-69.6,41.4), (-65.1,43.5), (-60,45.8), (-52.2,47.1), (-54.9,52.9),
            (-44.5,60.1), (-38.8,65.1)]

indianOcean =  [(21.40,-34.15), (27.37,-33.71), (40.03,-15.61), (39.68,-3.50), (51.80,10.16), 
                (58.84,22.26), (65.69,25.18), (71.32,19.83), (77.47,6.86), (80.24,12.53),
                (80.90,15.85), (89.05,22.12), (91.38,22.08), (94.54,17.74), (94.02,16.02),
                (97.00,16.82), (98.19,8.33), (100.78,3.18), (94.98,6.29), (105.0,-6.52),
                (118.16,-9.26), (123.52,-11.25), (129.93,-11.08), (128.62,-14.51), (125.89,-3.57),
                 (118.51,-20.37), (113.06,-22.18), (115.26,-34.44), (123.52,-34.88), (130.99,-32.09),
                (137.23,-36.59), (137.50,-66.47), (102.26,-65.79), (85.65,-66.22), (75.01,-69.50),
                (69.04,-67.67), (54.18,-65.76), (37.48,-68.65)]

现在,太平洋更加复杂,因为它延伸到地图的两边,你可以有两个连续的点,经度分别是-179和179,这导致这个多边形在xy平面上的表现很糟糕。我把它一分为二,所以我得到了:

^{pr2}$

据我所知,使用matplotlib,您可以使用path从顶点(坐标列表)创建多边形,然后您可以使用contains_point()函数来检查点是否在其中一个多边形中(因此它在“海洋”中)还是不在(“land”中):

    p1 = path.Path(atlanticOcean)
    p2 = path.Path(indianOcean)
    p3 = path.Path(pacificEast)
    p4 = path.Path(pacificWest)

    target = [(lon, lat)]

    result1 = p1.contains_points(target)
    result2 = p2.contains_points(target)
    result3 = p3.contains_points(target)
    result4 = p4.contains_points(target)

    # if target is in one of the polygons, it is in ocean
    if result1==True or result2==True or result3==True or result4==True: 
        print("In Ocean")     
    else:
        print("Land")

lon和lat变量,我用程序计算出的ISS变量。在

mpl_toolkits.basemap可能会有所帮助。在

from mpl_toolkits.basemap import Basemap
bm = Basemap()   # default: projection='cyl'
print(bm.is_land(99.0, 13.0))  #True
print(bm.is_land(0.0, 0.0)) # False

文件:here及以下相关方法:

is_land(xpt, ypt) Returns True if the given x,y point (in projection coordinates) is over land, False otherwise. The definition of land is based upon the GSHHS coastline polygons associated with the class instance. Points over lakes inside land regions are not counted as land points.

注意:您可能需要小心使用Basemap对象的投影。在

相关问题 更多 >