
Build a smart map app with Python and Leaflet. Visualize suburb water use with bubble and bar charts, using Django and Postgres with PostGIS.
Install Python on Windows by downloading the latest 3.9 version, adding Python 3.9 to path, running the installer, and verifying the installation in the command prompt.
Install and configure PostgreSQL and PostGIS on Windows, using Stack Builder to add PostGIS and the ODBC driver, and create a spatial database for smart maps.
Create a spatial database in postgres with pgAdmin, including a new database and a login role with privileges. Install PostGIS extensions to enable spatial data storage.
Create a project folder and set up a Python virtual environment to isolate dependencies for the water watch project. Activate the environment, install packages inside it, and deactivate when finished.
Learn to install and configure GeoDjango and GDAL on Windows, install the required components, and set environment variables to enable a spatial Django project.
Install and configure Django and psycopg2 in a Windows virtual environment. Connect Django to a PostgreSQL database using pip and activating the virtual env.
Install Visual Studio Code on Windows to write the code for the application; download from visualstudio.com, run the Windows installer, accept the license, and create a desktop icon.
Create a Django base application by initializing a Water Watch project and a Water Watch app folder, then verify files and prepare to implement models, views, and controllers.
Verify the Django installation by opening the project in Visual Studio Code, installing the Python extension, activating the virtual environment, and running the development server on port 8000.
Connect a spatial database to a Django app by installing geospatial libraries (Django leaflet and JSON support), updating settings, configuring a Postgres connection, and running migrations.
Create a Django admin user with manage.py createsuperuser, using the same username as the database, then run the server and log into the admin portal to verify users.
Create a geospatial Django model to store data in a Postgres spatial table, defining id, suburb, and a coordinates field, then run migrations to apply the schema.
Download and load the water consumption dataset by suburb. Install Excel reading and data manipulation libraries and analyze monthly kilolitres to identify high-use suburbs for potential alerts or distribution control.
Register the geo admin for a Django model, read Excel data into a pandas DataFrame, convert rows to point geometries, and load them into spatial back-end with Leaflet map verification.
Add the django geo json serializer and leaflet configuration to read json spatial data, set a default center and zoom, and configure base maps like open street map.
Develop the front end by adding static files in a Django project, downloading the base template, and integrating the static folder into the water watch app.
Create a templates folder and an app subfolder to store all html files for the Django app's front end, including a layout.html with a default style and theme.
Create a reusable layout for a Django-based map app by defining the doctype, html, head, and body, and loading static files, stylesheets, Django template tags, and Leaflet scripts.
Learn to create the index page for a Django and Leaflet map app by inheriting from the layout, wiring up leaflet and json scripts, and initializing the main map function.
Create and wire the index view by mapping the root URL to the home view, render the index HTML on request, and load the leaflet map in the browser.
Apply leaflet badges and styling to the index page, add left and right sidebars with toggle buttons, initialize the map, and test styling so the map fills the screen.
Create data endpoints for a map app, exposing two JSON datasets—water consumption and top 10 consumers—serialized from the data model and served via HTTP responses.
Display water consumption data on the map by fetching JSON via Ajax from the water consumption endpoint, render circle markers scaled by kilolitre value, and show suburb popups.
Create a bottom-right legend for the map that defines three circle markers by kilolitre ranges (0–4, 5–10, 11–20), with labels and a title to describe data size.
Create the bar chart legend for the application. Render a horizontal bar chart of the top ten water consumers using a canvas inside a leaflet control.
Create a bar chart of top 10 water consumers in kilolitres by fetching JSON data via ajax, parsing suburb labels and kilolitre values, and rendering with chalkboard js on canvas.
Welcome to the Creating Smart Maps with Python and Leaflet Windows Version course. We'll be building a python GIS application from scratch using a variety of open source technologies. The purpose of this course and many more to follow, is to learn to create geospatial analytics and convert it into a functional application.
In our use case we will be working with residential water consumption data and we will be applying data processing techniques to extract transform and load the data into our spatial database. Once we have processed and cleaned the data, we will use it as a data source for building our GeoDjango Web Map Application.
We will be powering our application with a PostgreSQL and PostGIS database. In the Front-End we'll use Bootstrap, JavaScript, Leaflet and Ajax. On the server side we'll be using Python and Django combined with use of scientific libraries like pandas, for our data transformation and conversion operations. The operating system that we will be working on is Windows 10 and Server 2016.
Some skills that you can expect to derive after completing the course are the following:
You will learn how to build a Spatial Database using Postgresql and PostGIS.
You will learn how to create charts with Chart.js.
You will learn to build Web Maps with Leaflet.js.
You will learn how to build REST API Endpoints.
You will learn some JavaScript programming.
You will learn how to build Web Applications using the Django MVC framework.