
Note: Use sudo apt-get install postgresql-15
This version matches with the postgis version we use in this course.
Postgresql is constantly been updated. Make sure you specify the specific version you wish to install, and check for the correct version of postgis that is compatible with your version of postgresql.
Update your system with sudo apt-get update and install the gdal libraries to enable geospatial data handling for gis applications. Then create the geospatial database for your application.
Create the spatial database for the application using PostgreSQL in admin mode, creating the CPT Water database and a waterwatch user, then enable PostGIS and PostGIS topology extensions.
Activate the virtual environment, navigate to project folder, install Django with pip, and install Psycopg2 to connect to PostgreSQL and read from and write to it in a Django app.
Install Visual Studio Code on Linux by downloading the Debian package from code.visualstudio.com and installing it. Verify that Visual Studio Code has been installed.
Create a Django base application by creating a Waterwatch project and a Waterwatch app, using manage.py to start the app and verify its files before writing the server-side code.
Test the Django installation by running the server from the virtual environment, opening the project in Visual Studio Code, and verifying the page at port 8000.
Install django-leaflet, django-geojson, and geojson, then update settings.py by adding the Django GIS and Waterwatch apps. Configure a PostGIS connection to localhost and run manage.py migrate to establish PostgreSQL access.
Create a Django admin user using manage.py createsuperuser, then run the server and log in at /admin to verify the user in the admin portal.
Create the model class for a geospatial Django app in models.py, defining id, suburb, and a point geometry, then run migrations to form the PostgreSQL table.
Download the waterwatch dataset from GitHub, install openpyxl and pandas to read the Excel file, and analyze monthly suburb water consumption in kilolitres to identify high-use areas for alerts.
Develop a Django admin workflow that reads an Excel dataset into a pandas dataframe, converts coordinates to a point, and stores them in a spatial table with Leaflet geo admin.
Add the Django Geojson serializer and leaflet configuration in settings.py, set a default map with three base maps (OpenStreetMap, terrain, data) and Esri/CartoDB tiles with attributions.
Create a templates folder in the waterwatch app, add an app subfolder, and build layout.html as the base html with a shared default style for all pages.
Build a responsive layout.html for a Django Leaflet map app, wiring HTML5 structure, head and body, static assets, and a modular sidebar with Leaflet, GeoJSON, and charts integration.
Create the Django project to inherit layout.html, include Leaflet and GeoJSON, set up a main map init function, and prepare views.py to render the index page.
Create the index view in Django using views.py to render index.html, handle requests with HttpRequest and HttpResponse, serialize data to json, and wire URLs to load the Leaflet map.
Add Leaflet.js code and CSS styling to our index.html, implement left and right sidebars with toggle buttons, and ensure the map scales to fill the full screen.
Create geojson datasets from a water consumption model and expose two endpoints for a map app: water consumption data and top ten consumers.
Display data on the map by calling the water consumption endpoint with Ajax, parsing GeoJSON features, and rendering blue circle markers with scaled radii and suburb popups in Leaflet.
Create a legend for a map by adding a bottom-right Leaflet control that displays three circle marker sizes representing 0–4 kilolitres, 5–10 kilolitres, and 11–20 kilolitres.
Create a bar chart legend on a Leaflet map, using Chart.js to display a horizontal bar chart of the top ten water consumers, with a styled info control and canvas.
Create a horizontal bar chart with Chart.js showing the top ten water consumers in kiloliters, by fetching and parsing JSON data via Ajax and extracting suburb labels and kiloliter values.
Welcome to the Creating Smart Maps with Python and Leaflet Linux 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 Ubuntu Linux LTS.
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.