Welcome back, young geospatial explorer! You have come a very long way. In Module 1, you learned what spatial data is. In Module 2, you learned how to install PostGIS and create spatial databases. In Module 3, you learned about spatial relationships and measurements. In Module 4, you learned about spatial indexes and performance.
In this module, we are going to learn about advanced geospatial analysis. This means we will learn how to do more powerful things with spatial data. We will learn about buffering. Buffering creates a zone around a shape. We will learn about unions. Unions combine shapes. We will learn about intersections. Intersections find where shapes overlap. We will learn about differences. Differences subtract one shape from another. We will learn about raster data. Raster data is data stored in a grid. We will learn about geocoding. Geocoding turns addresses into coordinates. We will also learn how to work with real-world datasets.
Do not worry if some words sound big. We will explain everything in simple language. We will use stories, examples from Nigeria, examples from school, and examples from home. We will use pictures made from keyboard characters (ASCII art) to help you see what we mean. By the end of this module, you will know:
This module is long because it is a complete chapter, not just short notes. Take your time. Read one lesson at a time. Do the exercises. Ask questions. Practice on your computer. Are you ready? Let us begin!
After finishing this module, you should be able to:
Amina was a 13-year-old girl who lived in Benue State, Nigeria. Her village was near a big river. Every year, the river flooded. The flood destroyed farms and houses.
One day, Amina's father came home looking worried. "The river is rising," he said. "We need to warn people. But we do not know which houses will be affected."
Amina remembered her PostGIS lessons. "We can use buffering!" she said. "We can create a buffer around the river. The buffer shows which areas will flood."
Amina opened her spatial database. She had a table with the river as a line. She created a buffer of 500 metres around the river. Then she checked which houses were inside the buffer.
She found 50 houses that would be affected. She gave the list to her father. The village chief warned the families. They moved to higher ground before the flood came.
The flood came. It destroyed farms and roads. But no one was hurt. The village was saved because of Amina's spatial analysis.
Moral of the story: Advanced geospatial analysis can save lives. Buffering, intersections, and unions help us solve real problems.
Geospatial analysis is the process of studying spatial data to answer questions. It means using location to solve problems. It means finding patterns, relationships, and trends in spatial data.
Geospatial analysis helps us make better decisions. It helps us plan cities, respond to disasters, and protect the environment.
Imagine you have a map of your town. You want to know where to build a new school. Geospatial analysis helps you find the best location.
A city uses geospatial analysis to plan new roads and reduce traffic.
A school uses geospatial analysis to find the best place for a new playground.
At home, you use geospatial analysis to find the best place for a garden.
In Lagos, the government uses geospatial analysis to plan flood control.
GEOSPATIAL ANALYSIS:
[ SPATIAL DATA ]
|
V
[ ASK QUESTIONS ]
|
V
[ FIND PATTERNS ]
|
V
[ MAKE DECISIONS ]
|
V
[ SOLVE PROBLEMS ]
Geospatial analysis is the process of studying spatial data to answer questions. It helps us make better decisions.
You learned what geospatial analysis is. You saw examples from home, school, and Nigeria. Now you know that geospatial analysis solves real problems.
Buffering is the process of creating a zone around a shape. The zone is a certain distance from the shape. You can buffer points, lines, and polygons.
Buffering helps you find all places within a certain distance of a shape. It is used for planning, safety, and analysis.
Imagine you drop a stone in water. Ripples spread out in a circle. Buffering creates a circle around a point.
A city creates a buffer around a school to create a safe zone.
A school creates a buffer around the playground to find nearby houses.
At home, you create a buffer around your house to find nearby shops.
In Benue State, a village creates a buffer around a river to find flood zones.
-- Buffer a point by 1000 metres
SELECT ST_Buffer(
ST_GeomFromText('POINT(6.5774 3.3212)', 4326),
0.01
) AS buffer;
-- Buffer a river line by 500 metres
SELECT ST_Buffer(
ST_GeomFromText('LINESTRING(6.5774 3.3212, 6.5780 3.3220)', 4326),
0.005
) AS river_buffer;
BUFFERING:
+-------+
/ \
| โข | <-- buffer around point
\ /
+-------+
BUFFERING A LINE:
+-------------------+
| =============== | <-- buffer around line
+-------------------+
Buffering creates a zone around a shape. It helps you find all places within a certain distance.
You learned what buffering is. You saw examples from home, school, and Nigeria. Now you can create buffers around shapes.
There are different types of buffers. You can create a buffer around a point, a line, or a polygon. You can also create a buffer with different shapes, like a circle or a square.
Different problems need different buffers. Knowing the types helps you choose the right one.
Imagine you have a pencil. You can draw a circle, a square, or a star. Buffers can also be different shapes.
A city creates a circular buffer around a fire station.
A school creates a square buffer around a new building.
At home, you create a circular buffer around your house.
In Abuja, a hospital creates a circular buffer around its location.
| Type | Shape | Use Case |
|---|---|---|
| Point buffer | Circle | Find places near a point |
| Line buffer | Corridor | Find places near a road |
| Polygon buffer | Larger polygon | Find places near an area |
| Square buffer | Square | Simple analysis |
| Circular buffer | Circle | Distance-based analysis |
POINT BUFFER: LINE BUFFER:
+-------+ +-------------------+
/ \ | =============== |
| โข | +-------------------+
\ /
+-------+
POLYGON BUFFER:
+-------------------+
| +-----+ |
| | | |
| +-----+ |
+-------------------+
There are different types of buffers: point, line, polygon, square, and circular. Different problems need different buffers.
You learned about types of buffers. You saw a table of types. Now you can choose the right buffer for your problem.
A union is the process of combining two or more shapes into one shape. The new shape includes all the area from the original shapes.
Unions help you combine areas. They help you simplify complex shapes. They are used for planning and analysis.
Imagine you have two pieces of paper. You glue them together. The new piece is the union of the two pieces.
A city combines two districts into one.
A school combines two playgrounds into one big playground.
At home, you combine two gardens into one big garden.
In Nigeria, the government combines two local government areas into one.
SELECT ST_AsText(ST_Union(
ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))', 4326),
ST_GeomFromText('POLYGON((2 2, 6 2, 6 6, 2 6, 2 2))', 4326)
)) AS union_result;
UNION:
+-------+-------+
| | |
| + |
| | |
| + |
| | |
+-------+-------+
|
V
[ COMBINED AREA ]
A union combines two or more shapes into one shape. The new shape includes all the area from the original shapes.
You learned about unions. You saw examples from home, school, and Nigeria. Now you can combine shapes with unions.
An intersection is the area where two or more shapes overlap. It is the common part of the shapes.
Intersections help you find where shapes share space. They help you solve problems about overlapping areas.
Imagine you have two circles that overlap. The overlapping part is the intersection.
A city finds where two flood zones overlap.
A school finds where two bus routes overlap.
At home, you find where two garden plots overlap.
In Nigeria, the government finds where two states overlap.
SELECT ST_AsText(ST_Intersection(
ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))', 4326),
ST_GeomFromText('POLYGON((2 2, 6 2, 6 6, 2 6, 2 2))', 4326)
)) AS intersection_result;
INTERSECTION:
+-------+-------+
| | |
| +---+---+ |
| | | | |
| +---+---+ |
| | |
+-------+-------+
|
V
[ OVERLAPPING AREA ]
An intersection is the area where two or more shapes overlap. It is the common part of the shapes.
You learned about intersections. You saw examples from home, school, and Nigeria. Now you can find intersections between shapes.
A difference is the part of one shape that is not in another shape. It subtracts one shape from another.
Differences help you find areas that are not covered by another shape. They help you solve problems about exclusion.
Imagine you have a big circle and a small circle inside it. The difference is the big circle minus the small circle.
A city finds the area that is not covered by a flood zone.
A school finds the area of the playground that is not covered by a new building.
At home, you find the area of your garden that is not covered by a shed.
In Nigeria, the government finds the area of a state that is not covered by a forest.
SELECT ST_AsText(ST_Difference(
ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))', 4326),
ST_GeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))', 4326)
)) AS difference_result;
DIFFERENCE:
+-------------------+
| +-----+ |
| | | |
| | | |
| +-----+ |
+-------------------+
|
V
[ AREA NOT COVERED ]
A difference is the part of one shape that is not in another shape. It subtracts one shape from another.
You learned about differences. You saw examples from home, school, and Nigeria. Now you can subtract shapes with differences.
Raster data is spatial data stored in a grid. Each cell in the grid has a value. Raster data is used for images, elevation, and temperature.
Raster data helps us understand the world in a different way. It shows patterns across large areas.
Imagine a big grid of squares. Each square has a colour or a number. Raster data is like that grid.
A weather company uses raster data to show rainfall across a country.
A school uses raster data to show the height of land in the school compound.
At home, you use raster data when you look at a satellite image.
In Nigeria, the government uses raster data to map rainfall and vegetation.
RASTER DATA: +---+---+---+---+ | 1 | 2 | 3 | 4 | +---+---+---+---+ | 5 | 6 | 7 | 8 | +---+---+---+---+ | 9 | 10| 11| 12| +---+---+---+---+ (each cell has a value)
Raster data is spatial data stored in a grid. Each cell in the grid has a value.
You learned about raster data. You saw examples from home, school, and Nigeria. Now you know that raster data shows patterns in a grid.
Vector data uses points, lines, and polygons. Raster data uses a grid of cells. Both are used in geospatial analysis.
Knowing the difference helps you choose the right type of data. Some problems are better with vector data. Some are better with raster data.
Imagine you want to draw a map. You can draw lines and shapes (vector). Or you can use a grid of colours (raster).
A city uses vector data for roads and raster data for satellite images.
A school uses vector data for classrooms and raster data for the school field.
At home, you use vector data for your house and raster data for a photo.
In Nigeria, the government uses vector data for roads and raster data for rainfall.
| Feature | Vector Data | Raster Data |
|---|---|---|
| Storage | Points, lines, polygons | Grid of cells |
| Precision | Exact | Approximate |
| File size | Smaller | Larger |
| Best for | Roads, boundaries | Images, elevation |
| Example | Shapefile | Satellite image |
VECTOR: RASTER: +-----------+ +---+---+---+---+ | โข----โข | | 1 | 2 | 3 | 4 | | | | | +---+---+---+---+ | โข----โข | | 5 | 6 | 7 | 8 | +-----------+ +---+---+---+---+
Vector data uses points, lines, and polygons. Raster data uses a grid of cells.
You learned about vector and raster data. You saw a comparison table. Now you know the difference between the two types.
Geocoding is the process of turning an address into coordinates. For example, "10 Main Street, Lagos" becomes (6.5774, 3.3212).
Geocoding helps you put addresses on a map. It helps you find the location of customers, stores, and services.
Imagine you have a list of addresses. You want to put them on a map. Geocoding turns each address into a point on the map.
A delivery company geocodes customer addresses to find the fastest route.
A school geocodes student addresses to plan bus routes.
At home, you geocode your friends' addresses to find the nearest one.
In Lagos, a taxi company geocodes customer addresses to send a driver.
GEOCODING:
[ ADDRESS: "10 MAIN STREET, LAGOS" ]
|
V
[ GEOCODING SERVICE ]
|
V
[ COORDINATES: (6.5774, 3.3212) ]
|
V
[ POINT ON MAP ]
Geocoding turns an address into coordinates. It helps you put addresses on a map.
You learned what geocoding is. You saw examples from home, school, and Nigeria. Now you know how to turn addresses into coordinates.
Reverse geocoding is the opposite of geocoding. It turns coordinates into an address. For example, (6.5774, 3.3212) becomes "10 Main Street, Lagos".
Reverse geocoding helps you find the address of a location. It helps you understand where a point is.
Imagine you have a point on a map. You want to know the address. Reverse geocoding tells you the address.
A delivery company uses reverse geocoding to confirm a customer's address.
A school uses reverse geocoding to find the address of a new building.
At home, you use reverse geocoding to find the address of a shop.
In Abuja, a taxi company uses reverse geocoding to tell the driver the pickup address.
REVERSE GEOCODING:
[ COORDINATES: (6.5774, 3.3212) ]
|
V
[ REVERSE GEOCODING SERVICE ]
|
V
[ ADDRESS: "10 MAIN STREET, LAGOS" ]
|
V
[ ADDRESS ON MAP ]
Reverse geocoding turns coordinates into an address. It helps you find the address of a location.
You learned about reverse geocoding. You saw examples from home, school, and Nigeria. Now you can find addresses from coordinates.
Real-world datasets are collections of spatial data about the real world. They include roads, rivers, boundaries, and buildings.
Real-world datasets help you solve real problems. They give you the data you need for analysis.
Imagine you want to build a map of Nigeria. You need data about roads, rivers, and states. Real-world datasets give you this data.
A city uses a real-world dataset of roads to plan new bus routes.
A school uses a real-world dataset of buildings to plan a new classroom.
At home, you use a real-world dataset of shops to find the nearest one.
In Nigeria, the government uses real-world datasets of roads and rivers for planning.
| Dataset | What It Contains | Source |
|---|---|---|
| OpenStreetMap | Roads, buildings, rivers | OpenStreetMap.org |
| Natural Earth | Countries, states, cities | NaturalEarthData.com |
| GRID3 | Population, settlements | GRID3.org |
| SRTM | Elevation data | USGS |
| Nigerian Boundary | States and local governments | OSM Nigeria |
REAL-WORLD DATASETS:
[ ROADS ] [ RIVERS ] [ BOUNDARIES ] [ BUILDINGS ]
| | | |
V V V V
[ USE FOR ANALYSIS AND PLANNING ]
Real-world datasets are collections of spatial data about the real world. They help you solve real problems.
You learned about real-world datasets. You saw a table of common datasets. Now you can use real-world data for your projects.
A geospatial application is a program that uses spatial data. It helps users find places, measure distances, and analyze locations.
Geospatial applications solve real problems for people. They make spatial data useful.
Imagine you want to build an app that finds the nearest hospital. A geospatial application does that.
A delivery company builds an app that shows drivers the nearest customer.
A school builds an app that shows new students where classrooms are.
At home, you build an app that shows your family's favourite places.
In Lagos, a startup builds an app that helps people find the nearest bus stop.
BUILD A GEOSPATIAL APP:
[ DEFINE PROBLEM ]
|
V
[ COLLECT DATA ]
|
V
[ CREATE DATABASE ]
|
V
[ LOAD DATA ]
|
V
[ WRITE QUERIES ]
|
V
[ BUILD INTERFACE ]
|
V
[ TEST AND IMPROVE ]
|
V
[ SHARE WITH THE WORLD! ๐ ]
A geospatial application is a program that uses spatial data. It helps users solve location problems.
You learned how to build a geospatial application. You saw a list of steps. Now you can build your own application.
An error is a mistake. PostGIS tells you when you make a mistake. You can fix the mistake and try again.
Everyone makes mistakes. Learning to fix errors makes you a better expert.
Imagine you are writing a letter. You spell a word wrong. You erase it and write it correctly. Fixing errors in PostGIS is like that.
A bank worker uses the wrong SRID. PostGIS shows an error. The worker corrects the SRID and tries again.
A student uses the wrong function name. PostGIS shows an error. The student corrects the name and tries again.
At home, you use the wrong coordinate. PostGIS shows an error. You correct the coordinate and tries again.
In a Nigerian market, a trader uses the wrong polygon. PostGIS shows an error. The trader corrects the polygon and tries again.
| Error | What It Means | How to Fix It |
|---|---|---|
| function does not exist | PostGIS is not installed | Run CREATE EXTENSION postgis; |
| geometry has wrong SRID | The SRIDs do not match | Use ST_Transform to change the SRID |
| invalid geometry | The shape is not valid | Use ST_MakeValid to fix the shape |
| syntax error | You typed a command incorrectly | Check your spelling and punctuation |
| relation does not exist | The table does not exist | Create the table first |
| buffer distance too large | The buffer is too big | Reduce the buffer distance |
ERROR:
[ TYPE: SELECT ST_Buffer('POINT(0 0)', 10); ]
|
V
[ ERROR: function st_buffer(unknown, integer) does not exist ]
|
V
[ FIX: USE ST_GeomFromText ]
|
V
[ TRY AGAIN ]
Errors are mistakes. PostGIS tells you when you make a mistake. You can fix the mistake and try again.
You learned about common errors and how to fix them. You saw a table of errors. Now you can fix mistakes in PostGIS.
Best practices are the best ways to do things. They help you write clean, efficient, and correct spatial analysis.
Following best practices makes your analysis faster. It prevents problems later.
Imagine you are cleaning your room. You put things in the right place. Best practices for spatial analysis are like putting things in the right place.
A city follows best practices. Its spatial analysis is accurate and fast.
A school follows best practices. Its spatial analysis is accurate and fast.
At home, you follow best practices. Your spatial analysis is accurate and fast.
In Lagos, a taxi company follows best practices. Its spatial analysis is accurate and fast.
BEST PRACTICES:
[ USE SRID ] --> [ USE SPATIAL INDEXES ]
| |
V V
[ USE ST_DWITHIN ] --> [ VALIDATE GEOMETRIES ]
| |
V V
[ USE ST_TRANSFORM ] --> [ TEST QUERIES ]
| |
V V
[ KEEP DATA CLEAN ] --> [ USE REAL DATA ]
| |
V V
[ DOCUMENT ANALYSIS ] --> [ TEACH OTHERS ]
| |
V V
[ ACCURATE, FAST SPATIAL ANALYSIS ]
Best practices help you write clean, efficient, and correct spatial analysis.
You learned best practices for advanced analysis. You saw a list. Now you can do better spatial analysis.
Putting it all together means using all your advanced geospatial skills. It means building powerful applications and solving real problems.
A complete geospatial expert uses many skills together. Putting it all together makes you a valuable professional.
Imagine you are building a house. You need bricks, cement, and wood. Putting it all together means building the house. In the same way, you build a powerful geospatial application with advanced analysis.
A city puts it all together. It uses buffering, unions, intersections, and raster data.
A school puts it all together. It uses buffering, geocoding, and real-world datasets.
At home, you put it all together. You use buffering, intersections, and geocoding.
In Lagos, a startup puts it all together. It builds an app that uses buffering, geocoding, and real-world datasets.
PUTTING IT ALL TOGETHER:
[ BUFFERING ]
|
V
[ UNIONS ]
|
V
[ INTERSECTIONS ]
|
V
[ DIFFERENCES ]
|
V
[ RASTER DATA ]
|
V
[ GEOCODING ]
|
V
[ REAL-WORLD DATASETS ]
|
V
[ GEOSPATIAL APPLICATION! ๐ ]
Putting it all together means using all your advanced geospatial skills. It makes you a valuable professional.
You learned how to put everything together. You saw examples from home, school, and Nigeria. Now you can build powerful geospatial applications.
| Word | Simple Definition |
|---|---|
| Geospatial analysis | Studying spatial data to answer questions. |
| Buffering | Creating a zone around a shape. |
| Union | Combining two or more shapes into one. |
| Intersection | The area where two or more shapes overlap. |
| Difference | The part of one shape not in another shape. |
| Raster data | Spatial data stored in a grid. |
| Vector data | Spatial data using points, lines, and polygons. |
| Geocoding | Turning an address into coordinates. |
| Reverse geocoding | Turning coordinates into an address. |
| Real-world dataset | A collection of spatial data about the real world. |
| Geospatial application | A program that uses spatial data. |
ADVANCED GEOSPATIAL ANALYSIS
|
+---- BUFFERING
|
+---- UNIONS
|
+---- INTERSECTIONS
|
+---- DIFFERENCES
|
+---- RASTER DATA
|
+---- GEOCODING
|
+---- REAL-WORLD DATASETS
Step 1: Learn what geospatial analysis is. Step 2: Learn what buffering is. Step 3: Learn types of buffers. Step 4: Learn what a union is. Step 5: Learn what an intersection is. Step 6: Learn what a difference is. Step 7: Learn what raster data is. Step 8: Learn vector vs raster data. Step 9: Learn what geocoding is. Step 10: Learn reverse geocoding. Step 11: Learn about real-world datasets. Step 12: Learn to build a geospatial application. Step 13: Fix common errors. Step 14: Learn best practices. Step 15: Put it all together.
BUFFER: UNION: INTERSECTION: DIFFERENCE:
+-------+ +-------+-------+ +-------+-------+ +---------------+
/ \ | | | | | | | +-----+ |
| โข | | + | | +---+---+ | | | | |
\ / | | | | | | | | | | | |
+-------+ +-------+-------+ +-------+-------+ +---------------+
| Function | What It Does | Example Use |
|---|---|---|
| ST_Buffer | Creates a zone around a shape | Find flood zones |
| ST_Union | Combines shapes into one | Combine districts |
| ST_Intersection | Finds overlapping area | Find shared service areas |
| ST_Difference | Subtracts one shape from another | Find uncovered areas |
| ST_AsRaster | Converts vector to raster | Create elevation maps |
| ST_Geocode | Turns address into coordinates | Map customer addresses |
| Feature | Vector Data | Raster Data |
|---|---|---|
| Storage | Points, lines, polygons | Grid of cells |
| Precision | Exact | Approximate |
| File size | Smaller | Larger |
| Best for | Roads, boundaries | Images, elevation |
| Example | Shapefile | Satellite image |
In this module, you learned about advanced geospatial analysis. You learned what geospatial analysis is. You learned about buffering. You learned how to create buffers around points, lines, and polygons. You learned about types of buffers.
You learned about unions. You learned how to combine shapes with ST_Union. You learned about intersections. You learned how to find where shapes overlap with ST_Intersection. You learned about differences. You learned how to subtract shapes with ST_Difference.
You learned about raster data. You learned that raster data is stored in a grid. You learned the difference between vector and raster data. You learned about geocoding. You learned how to turn addresses into coordinates. You learned about reverse geocoding. You learned how to turn coordinates into addresses.
You learned about real-world datasets. You learned how to work with roads, rivers, and boundaries. You learned how to build a geospatial application. You learned about common errors and how to fix them. You learned best practices for advanced analysis. You learned how to put it all together.
Congratulations! You have finished the entire Certified PostGIS User course. You have learned so much. You are ready to build powerful geospatial applications and solve real problems. But remember: learning never stops. Keep practicing. Keep learning. Keep teaching others. You are now a Certified PostGIS User!
Match the word in Column A with the correct definition in Column B.
| Column A | Column B |
|---|---|
| 1. Geospatial analysis | A. Creating a zone around a shape |
| 2. Buffering | B. Combining two or more shapes into one |
| 3. Union | C. Studying spatial data to answer questions |
| 4. Intersection | D. Spatial data stored in a grid |
| 5. Difference | E. The area where two or more shapes overlap |
| 6. Raster data | F. The part of one shape not in another shape |
| 7. Geocoding | G. Turning an address into coordinates |
| 8. Geospatial application | H. A program that uses spatial data |
Answers: 1-C, 2-A, 3-B, 4-E, 5-F, 6-D, 7-G, 8-H
Title: Flood Zone Analysis
Instructions: In groups of 3 or 4, create a spatial database with a river and houses.
Create a buffer of 500 metres around the river. Find all houses inside the buffer.
Present your results to the class.
Example:
Table: river (line), houses (points)
Query: SELECT h.name FROM houses h WHERE ST_DWithin(h.geom, r.geom, 500);
Result: List of houses in the flood zone.
Title: My Geospatial Analysis
Instructions: Create a spatial database for your neighbourhood.
Add at least 5 places as points. Create a buffer of 200 metres around one place.
Find all places inside the buffer. Write down what you did.
Example:
Database: myneighbourhood
Table: places (id, name, geom)
Query: SELECT name FROM places WHERE ST_DWithin(geom, ST_GeomFromText('POINT(6.5774 3.3212)', 4326), 200);
Title: Build a Geospatial Analysis Database
Materials: Computer with PostgreSQL and PostGIS installed.
Steps:
Assignment: For one week, practice advanced geospatial analysis. Keep a diary. Each day, write down:
At the end of the week, write a short report. Share it with your teacher or parent.
Congratulations! You have finished all five modules of the Certified PostGIS User course. You have learned so much:
You are now a Certified PostGIS User. You can design, build, and maintain spatial databases. You can create maps, measure distances, find relationships, and analyze locations. You can build geospatial applications. You can solve real problems.
But remember: learning never stops. Technology is always changing. Keep practicing. Keep learning. Keep teaching others. Stay curious. Stay kind. Stay safe.
You are now a Certified PostGIS User. Congratulations! ๐
End of Module 5. End of Course.