代码之家  ›  专栏  ›  技术社区  ›  ASH

我们可以使用folium地图来获取某种站点类型或站点描述吗?

  •  0
  • ASH  · 技术社区  · 4 年前

    我正在使用一些代码来循环使用经度和纬度坐标的记录,并获得某种类型的站点类型,或站点分类,或任何您想要调用的内容。下面的示例代码不起作用,但我认为有点接近。

    import folium
    import requests
    from xml.etree import ElementTree
    from folium import plugins
    
    
    m = folium.Map(location=[40.7368436,-74.1524242], zoom_start=10)
    for lat,lon in zip(df_cellgroups['latitude'], df_cellgroups['latitude']):
       marker = folium.Marker(location=[lat,lon], tooltip = tip, popup = name)
       marker.add_to(m)
    m
    

    基本上,我想获取诸如“红牛竞技场”、“北州立大学医院”、“旧金山国际机场”等名称。那么,是否有可能使用folium地图,根据纬度和经度坐标获得场地描述?也许它被称为工具提示或弹出窗口,不确定。谢谢

    enter image description here

    enter image description here

    enter image description here

    0 回复  |  直到 4 年前
        1
  •  1
  •   Thomas    4 年前

    您可以使用反向地理编码服务/提供商(如OpenStreetMap、Google或Esri提供的服务/提供商)检索有关位置的信息。

    (有一个概述 here Python的 geocoder 软件包。)


    下面是使用 地理编码 包装和 OpenStreetMap (Nominatim) 作为提供者:

    # pip install geocoder requests
    
    import time
    import requests
    import geocoder
    
    locations = (
        (40.7368436, -74.1524242),
        (44.6371650, -63.5917312),
        (47.2233913, 8.817269106),
    )
    
    with requests.Session() as session:
    
        for location in locations:
    
            g = geocoder.osm(
                location=location,
                method="reverse",
                lang_code="en",
                session=session,
                headers={
                    "User-Agent": "Stackoverflow Question 69578280"
                },
            )
    
            print(g.osm)  # or print(g.json)
    
            # slow down loop in order to comply with the Nominatim's Usage Policy:
            # https://operations.osmfoundation.org/policies/nominatim
            time.sleep(1)
    

    或者,还有其他Python库,例如 ArcGIS for Python API GeoPy 。下面是一个使用 geopy 同时使用OpenStreetMap(Nagnitm)作为提供程序的软件包:

    # pip install geopy
    
    from geopy.geocoders import Nominatim
    from geopy.extra.rate_limiter import RateLimiter
    
    locations = (
        (40.7368436, -74.1524242),
        (44.6371650, -63.5917312),
        (47.2233913, 8.817269106),
    )
    
    locator = Nominatim(user_agent="Stackoverflow Question 69578280")
    
    # using RateLimiter to comply with Nominatim's Usage Policy
    reverse = RateLimiter(locator.reverse, min_delay_seconds=1)
    
    for location in locations:
        result = reverse(location, language="en")
        print(result.raw)
    

    注: 确保您阅读了您将要使用的服务的使用条款。诺曼蒂姆的使用政策如下: https://operations.osmfoundation.org/policies/nominatim