%%{init: {"theme": "neutral"}}%%
flowchart TB
S["Public data<br/>from the web or your disk"] -->|Ch 1 to 4| P["Points<br/>cities, stars,<br/>earthquakes"]
S -->|Ch 9 to 13| R["Surfaces<br/>relief, people,<br/>rain, sea"]
S -->|Ch 7| A["Areas<br/>districts<br/>without gaps"]
S -->|Ch 14| I["Old map and<br/>satellite images"]
P -->|Ch 5, 6| L["Paths<br/>storms and buses"]
R -->|Ch 9 to 13| V["Lines, shade,<br/>views, and dates<br/>of the rain"]
A -->|Ch 8| D["Distances and<br/>nearest areas"]
I -->|Ch 14| N["Changes through<br/>the years"]
L --->|Ch 17| Z["A complete<br/>map sheet<br/>for printing"]
P --->|Ch 17| Z
R --->|Ch 17| Z
R -->|Ch 15| W["Walking times<br/>to a safe place"]
D -->|Ch 15| W
W -->|Ch 16| K["One file with<br/>all results,<br/>to share"]
One Line, One Map
One Line, One Map

This tutorial makes maps with GDAL and OGR from the command line, for raster and vector data. Each chapter starts from a question. Which places lie exactly opposite Indonesia? How does the plate below Java look from the side? Who can walk to a safe place before a tsunami arrives? The chapter answers it with one line where GDAL allows it and a few where it does not, and then uses the same method for other questions and other data.
The axes of a map do not have to be longitude and latitude. In these chapters they are also depth, clock time, distance or positions in the night sky. The pictures are drawn by GDAL itself, from the first map to the printed sheet with title and legend in the last chapter.
Who it is for. Beginners, and people who already use GDAL and want to do more with it. You need a computer on which you can install software and open a terminal. No experience with GDAL, SQL or Python is needed: Chapter 0 starts with one command and one file, and ends with a whole map in one line. After that come 166 everyday cases, with rasters, satellite images, netCDF, HDF5, tables, an old map without coordinates, and damaged files. Readers who know GDAL can use these cases as a collection, and begin with Chapter 1.
What this tutorial is, and is not
This is a tutorial about GDAL on the command line. It is not a guide to the science of earthquakes, climate or tsunamis. These subjects give the questions, and the chapters follow them only as far as the commands need it.
- The maps are examples. They are not for navigation, and not for decisions about safety. The walking times in Chapter 15 rest on assumptions, and the chapter shows how much the result changes with 27 combinations of them. If you live in Padang, use the evacuation map and the signs of the city.
- The borders are simplified for drawing. They are not a legal reference.
- One line is not always the best way. Some results need several lines, and the longest queries are in files of their own. Chapter 16 names five common questions for which other programs are better.
- The newer
gdalcommand may still change. Its documentation calls it provisional (ledger L2). The lines were tested with GDAL 3.12.3.
GDAL at the centre, not alone. GDAL works with several other open-source projects, and most of them are installed together with it:
| Software | What it does here |
|---|---|
| GDAL and OGR | read, change, calculate, draw and write all data. The chapters use 69 commands of the newer gdal program and nine of the classic programs, such as ogr2ogr and gdalwarp (ledger L164) |
| SQLite and SpatiaLite | answer the SQL queries inside the lines, with 54 spatial functions (ledger L164) |
| PROJ | calculates the map projections and the coordinate systems |
| GEOS | calculates with shapes, for example buffers, intersections and simplified borders |
| Python and Jupyter | run the lines in the notebooks and check the results at the end of each chapter. In a terminal, you do not need them for the lines |
The workflow
Each box is a kind of data or a result. Each arrow carries the chapters that take this step.
Chapters
Most examples are from Indonesia, and the questions become more difficult from part to part. First where, then when, then whose and how far, then how high and how much. After that come what has changed, what does it mean for people, and how to repeat and share the work. Each chapter continues with a question from the one before, and explains this at its beginning.
Introduction and examples: How do I …?
| Chapter | What it covers | |
|---|---|---|
| 0 | One command, one file | For beginners: an introduction that goes from one command to a map of Lake Toba in one line, and then 166 everyday cases, from tables and satellite images to an old map without coordinates and damaged files |
I. Places: Where?
| Chapter | What it covers | |
|---|---|---|
| 1 | The other side of the Earth | Which places lie exactly opposite Indonesia, and how large Indonesia is compared with Europe; the parts of a one-line command, and its quotes in every shell |
| 2 | Choosing a map projection | How projections change the sizes and shapes on a map of the world, shown with ten projections, and a test of which one fits Indonesia |
| 3 | Maps of the night sky | A star catalogue as a point layer: a map of the sky over any place at any minute, drawn by GDAL |
| 4 | Earthquakes by depth | Earthquake data from the web, with depth, distance or time on the axes, so that the plate below Java becomes visible |
II. Paths: When, and where next?
| Chapter | What it covers | |
|---|---|---|
| 5 | Storm tracks from points | The positions of cyclones joined into tracks, cut at the date line, and counted in a map of passages |
| 6 | Graphs and maps from a bus timetable | The buses of Jakarta in graphs of time and distance, in a map of all positions at one minute, and as trips with time as height |
III. Areas: Whose is it, and how far?
| Chapter | What it covers | |
|---|---|---|
| 7 | Simplifying borders without gaps | The districts of Indonesia: how simplifying makes gaps between them, how to repair the gaps, how to colour neighbours differently, and how to draw lines around the coast |
| 8 | The most inland place | Distances as a raster and nearest areas as polygons: the point of Borneo farthest from the coast, the point of the ocean farthest from land, and the nearest airport for every place |
IV. Surfaces: How high, which way, and how much?
| Chapter | What it covers | |
|---|---|---|
| 9 | Relief drawn with profile lines | A raster as a table: the mountains of Java drawn only with lines, the same drawing for the population, and the slopes of a volcano in a rectangular picture |
| 10 | Contour lines with light and shade | Contour lines with a width and tone that depend on their direction, short lines in the direction of the slope, summits and hollows found from contour lines, and contour lines of population |
| 11 | Terrain commands for other data | The commands for mountains used on other data: the brightness of a batik, the distance to the sea, the distance to airports, rain, and the temperature of the sea south of Java |
| 12 | What is visible from a summit | The area visible from Mount Agung as a map and as a panorama, the shadow of a volcano in the morning, and the smallest number of fires for a signal from Banten to Sumbawa |
| 13 | When the rain peaks | Circular diagrams of the rain through the year for thirteen cities, the mean date of the rain in every place, places with one or two rainy seasons, and the beginning of the rainy season from Java to Timor |
V. Then and now: What has changed?
| Chapter | What it covers | |
|---|---|---|
| 14 | An old map and satellite images compared | An old Army map of Lake Toba gets coordinates and is compared with satellite images: an image without clouds from nine days, the years in which trees were cut, and a canal that was made wider |
VI. Decisions: What does it mean for people?
| Chapter | What it covers | |
|---|---|---|
| 15 | Walking times to safety in a tsunami | Walking times to a safe place in Padang, for a tsunami. The same calculation with 27 combinations of assumptions, the best places for new shelters, and one table with the results |
Before you start
- Software: one conda environment,
environment.yml, with GDAL 3.12 from conda-forge. Chapter 0, section 1 installs it. - Your shell: the lines are written to run unchanged in bash, zsh, PowerShell and cmd. Where that is not possible, as with loops, each shell has its own version. Chapter 1, section 5 explains the rules.
- Tested on: Windows 11 with GDAL 3.12.3, in cmd, Windows PowerShell 5.1, PowerShell 7 and Git Bash. For bash and zsh on Linux, only the text of the lines was tested: it reaches the program unchanged. GDAL itself was not run on Linux or macOS yet, and the environment file has not been used for a new installation yet (ledger L164).
- Data: most chapters read public data directly from the web, without an account. The small files of each chapter, and copies of many of the larger ones, are in the folder
sample-data. The same lines also work with files on your own disk. Chapter 1, section 9 shows how, and lists all downloads for work without a connection. - Space and time: the commands of each chapter took between less than a minute and six minutes on the author’s computer. Chapter 16 downloads about 500 MB, nearly all of it for one section that also has a small copy, Chapter 14 about 150 MB, and every other chapter 53 MB or less. Chapter 17 needs the most space, about 1 GB. Use a folder that is not synchronised with a cloud service.
- The notebooks: each chapter is shown with the outputs of the author’s run. The “View source” link of each page opens it on GitHub, where you can download it and run it yourself. You can also paste the lines into a terminal. Each chapter ends with a checkpoint that stops with an error if its results are not what the chapter expects.
Where the numbers come from
Every number in the chapters comes from a cell output in the same chapter or from a row of the sources page, which says how it was measured or where it was read.
Bahasa Indonesia
The whole series is also available in Bahasa Indonesia.
Repository
Source, issues and history: github.com/osgeoid/gdal-oneliners. Corrections, new chapters and translations are welcome: see how to contribute. Maintainer: Benny Istanto. Part of the tutorials of OSGeo Indonesia.
Licence and citation
Code under the Mozilla Public License 2.0, text and figures under CC BY 4.0, except the star maps of Chapter 3, which are under CC BY-SA 4.0. The data keep their own terms, listed in LICENSE-CONTENT.md and on the sources page. To cite the tutorial, use the citation file of the repository.