Collecting field data

For decades, collecting field observation data from the field into a GIS required hours of manual data entry or, at best, loading data after the trip. Smartphones and laptops with cellular connections have revolutionzed this process. In this recipe, we'll use a simple but interesting geojson-based framework to enter information and a map location from any Internet-connected device with a web browser and update a map in QGIS.

Getting ready

There is no preparation required for this recipe.

How to do it...

We will load a world boundaries layer and the field data layer onto a QGIS map, go to the field data mobile website and create an entry, and then refresh the QGIS map to see the update. To do this, we need to perform the following steps:

  1. In the QGIS Python Console, add the following geojson layers:
    wb = "https://raw.githubusercontent.com/johan/ world.geo.json/master/countries.geo.json"
    basemap = QgsVectorLayer(wb, "Countries", "ogr")
    observations = 
    QgsVectorLayer("http://bit.ly/QGISFieldApp", 
    "Field Observations", "ogr")
    QgsMapLayerRegistry.instance().addMapLayers( [basemap, observations])
    
  2. Now, in a browser on your computer, or preferably on a mobile device with a data connection, go to http://geospatialpython.github.io/qgis/fieldwork.html. The application will ask you for permission to use your location, which you should temporarily allow for the program to work.
  3. Enter information in the form and click on the Send button.
  4. Verify that you can see the geojson data, including your submission, at https://api.myjson.com/bins/3ztvz.
  5. Finally, update the map in QGIS by zooming or panning and locate your record.

How it works...

The simple mobile-friendly web page uses the Leaflet.js library for mapping and HTML5 for the form submission. The data is stored as a snippet on the MyJSON.com service. This approach serves our examples and demonstrates the client-server model. However, it is not very robust because users working concurrently can easily overwrite each other's data. So, if you don't see your update, try it again once or twice and it will probably work. Sample observations are reset from time to time in order to keep the site lightweight. Note that it's important to refresh the map either manually or programmatically to force QGIS to refresh the network link. You can get the source code for the mobile page on GitHub.com (https://github.com/GeospatialPython/qgis).

The following image shows the mobile field application on an iPhone:

How it works...

This image shows how the corresponding data looks in QGIS:

How it works...
..................Content has been hidden....................

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