Reports from the field

In our final example in this chapter, we'll get off the bus and out into the field. Modern smart phones, tablets, and laptops allow us to update a GIS and view these updates from everywhere. We'll use HTML, GeoJSON, Leaflet JavaScript Library, and a pure Python library named Folium to create a client-server application that allows us to post geospatial information to a server, and then create an interactive web map to view these data updates.

First, we need the web form that shows your current location and updates the server when you submit the form with comments about your location. You can find the form at http://geospatialpython.github.io/Learn/fieldwork.html.

The following screenshot shows you the form:

Reports from the field

You can view the source of this form to see how it works. The mapping is done using the Leaflet library and posts GeoJSON to a unique URL on myjson.com. You can use this page on mobile devices, you can move it to any web server, or even use it on your local hard drive.

The form posts to the following URL publicly on myjson.com: https://api.myjson.com/bins/467pm.

You can visit this URL in a browser to see the raw GeoJSON. Next, you need to install the Folium library from PyPI. Folium provides you with a simple Python API to create Leaflet web maps. You can find more information about Folium at https://github.com/python-visualization/folium.

Folium makes producing a Leaflet map extremely simple. This script is just a few lines and will output a web page named map.html. We pass the GeoJSON URL to the map object, which will plot the locations on the map:

import folium

m = folium.Map()
m.geo_json(geo_path="https://api.myjson.com/bins/467pm")
m.create_map(path="map.html")

The resulting interactive map will display the points as markers. When you click on a marker, the information from the form is displayed. You can just open the HTML file in any browser:

Reports from the field
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset