Geospatial data can be interesting. One interactive geospatial visualization provides a lot of information about the data and the area and more. Python has so many libraries. It is hard to know which one to use. For a geospatial visualization, I will use Folium. It is very easy to use and it has several styles as well to match your choice and requirement. Let’s start.
地理空间数据可能很有趣。 一种交互式地理空间可视化提供了大量有关数据和区域的信息以及更多信息。 Python有很多库。 很难知道要使用哪个。 对于地理空间可视化,我将使用Folium 。 它非常易于使用,并且有多种样式可以满足您的选择和要求。 开始吧。
I used a Jupyter Notebook environment for this. If you are using a Jupyter Notebook, you need to install folium using the anaconda prompt using the following command:
我为此使用了Jupyter Notebook环境。 如果您使用的是Jupyter Notebook,则需要使用以下命令在anaconda提示符下安装大叶草:
conda install -c conda-forge folium=0.5.0 — yes
conda install -c conda-forge folium = 0.5.0 —是
Now we can import folium in the notebook. Folium has the world map built-in.
现在我们可以在笔记本中导入叶了。 Folium具有内置的世界地图。
import folium
folium.Map()
Here is the world map. As you can see, you can zoom in, zoom out, and navigate around. You may want the map of a certain country, state, or city. Latitude and longitude of that specific place can be provided as a parameter to get the map of that particular place. I want to print the map of Florida.
这是世界地图。 如您所见,您可以放大,缩小和浏览。 您可能需要特定国家,州或城市的地图。 可以将特定地点的纬度和经度作为参数来获取该特定地点的地图。 我想打印佛罗里达州的地图。
folium.Map(location = [27.664827, -81.516], zoom_start = 4)
Here you can see the state of Florida. I put the zoom_start as 4. In your notebook, you can zoom in or zoom out and navigate to a certain part. But you can also start with a, increased zoom.
在这里您可以看到佛罗里达州。 我将zoom_start设置为4。在您的笔记本中,您可以放大或缩小并导航到特定部分。 但您也可以从增加缩放开始。
florida = folium.Map(location = [27.664827, -81.516], zoom_start = 7)
Let’s see some different styles. Make a high contrast black and white map. You can achieve it by using parameter tiles. For a high contrast black and white map, tiles will be ‘Stamen Toner’.
让我们看看一些不同的样式。 制作高对比度的黑白地图。 您可以使用参数图块来实现。 对于高对比度的黑白地图,图块将为“雄蕊碳粉”。
folium.Map(location= [27.665, -81.516], zoom_start = 8, tiles = 'Stamen Toner')
Isn’t it nice! This type of map is perfect for the coastal zone. Also good for data mashup.
不好吗! 此类地图非常适合沿海地区。 同样适用于数据混搭。
In my next example, I will use the Stamen Terrain map. This will show the natural vegetation and hills shading.
在下一个示例中,我将使用“雄蕊地形”地图。 这将显示自然植被和山丘阴影。
folium.Map(location= [27.665, -81.516], zoom_start = 4, tiles = 'Stamen Terrain')
I am sure you are interested to see if we can plot events or incidents on the map. We certainly can. To demonstrate that I am going to use a dataset that will show the incidents in Florida. Please feel free to download the dataset from here:
我确定您有兴趣了解我们是否可以在地图上绘制事件或事件。 我们当然可以。 为了演示我将使用一个数据集,它将显示佛罗里达州的事件。 请随时从此处下载数据集:
I downloaded the spreadsheet from this site. Import the dataset to the notebook.
我从该站点下载了电子表格。 将数据集导入笔记本。
import pandas as pd
florida_incidents = pd.read_csv('Florida_Subsidence_Incident_Reports.csv')
The dataset is too big. So I am not showing the screenshot here. But the dataset has an X and Y column which are latitudes and longitudes of different Florida locations. We can place these locations on the map creating a features group. We will include the positions and styles of the points. For the clarity f the image I will only put 100 data points.
数据集太大。 所以我没有在这里显示屏幕截图。 但是数据集具有X和Y列,分别是佛罗里达州不同位置的经度和纬度。 我们可以将这些位置放置在地图上以创建要素组。 我们将包括这些点的位置和样式。 为了清晰起见,我只放置100个数据点。
florida_incidents = florida_incidents.iloc[0:100, :]florida = folium.Map(location= [27.665, -81.516], zoom_start = 7)incidents = folium.map.FeatureGroup()for lat, lng, in zip(florida_incidents.Y, florida_incidents.X):
incidents.add_child(
folium.features.CircleMarker(
[lat, lng],
radius=5,
color='yellow',
fill=True,
fill_color='blue',
fill_opacity=0.6))florida.add_child(incidents)
We can go further and add the markers on those points.
我们可以走得更远,并在这些点上添加标记。
latitudes = list(florida_incidents.Y)
longitudes = list(florida_incidents.X)for lat, lng in zip(latitudes, longitudes):
folium.Marker([lat, lng]).add_to(florida)
florida.add_child(incidents)
Feel free to zoom in and navigate to see the incidents by a specific county or city.
随意放大并导航以查看特定县或市的事件。
(Conclusion)
I tried to show how to generate an interactive map, present some incidents or events on it with markers, and style it. This type of interactive map is always helpful in a dashboard, in a presentation, or any other information presented. I hope this was helpful.
我试图展示如何生成交互式地图,如何用标记显示事件或事件并设置样式。 这种类型的交互式地图在仪表板,演示文稿或任何其他提供的信息中始终很有帮助。 我希望这可以帮到你。
Recommended Reading: