我们可以使用 folium 地图来获取某种站点类型或站点描述吗?
Can we use folium maps to get some kind of site type or site description?
我正在使用一些代码来循环遍历具有经度和纬度坐标的记录,并获得某种站点类型或站点分类,或任何您想调用的内容。下面的示例代码无法运行,但我认为它有点接近。
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
基本上我想获取像 'Red Bull Arena'、'Upstate University Hospital'、'San Francisco International Airport' 等这样的名称。那么,是否有可能获得网站的描述,基于在纬度和经度坐标上,使用 folium 地图?也许它被称为工具提示或弹出窗口,不确定。谢谢
您可以使用 OpenStreetMap、Google 或 Esri 提供的反向地理编码 service/provider 来检索有关位置的信息。
(有一个概述 here of all providers supported by the Python's geocoder
包。)
下面是使用 geocoder
package and 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": "Whosebug 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 or GeoPy. Here is an example using the geopy
包也使用 OpenStreetMap (Nominatim) 作为提供者:
# 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="Whosebug 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)
注意:确保您阅读了您将要使用的服务的使用条款。 Nominatim 的使用政策可在此处找到:https://operations.osmfoundation.org/policies/nominatim
我正在使用一些代码来循环遍历具有经度和纬度坐标的记录,并获得某种站点类型或站点分类,或任何您想调用的内容。下面的示例代码无法运行,但我认为它有点接近。
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
基本上我想获取像 'Red Bull Arena'、'Upstate University Hospital'、'San Francisco International Airport' 等这样的名称。那么,是否有可能获得网站的描述,基于在纬度和经度坐标上,使用 folium 地图?也许它被称为工具提示或弹出窗口,不确定。谢谢
您可以使用 OpenStreetMap、Google 或 Esri 提供的反向地理编码 service/provider 来检索有关位置的信息。
(有一个概述 here of all providers supported by the Python's geocoder
包。)
下面是使用 geocoder
package and 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": "Whosebug 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 or GeoPy. Here is an example using the geopy
包也使用 OpenStreetMap (Nominatim) 作为提供者:
# 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="Whosebug 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)
注意:确保您阅读了您将要使用的服务的使用条款。 Nominatim 的使用政策可在此处找到:https://operations.osmfoundation.org/policies/nominatim