Skip to main content

Chapter 1: The other side of the Earth

Chapter 1: The other side of the Earth

TipAt a glance
  • In this series: Part I, Places. Chapter 0 used one command on one file. From here on, the lines answer questions about places. The first question is: which places lie exactly opposite Indonesia?
  • You will build: A map of the land opposite Indonesia, a list of the towns nearest to the points opposite Indonesian cities, and Indonesia drawn over Europe at its true size
  • You need: Chapter 0, at least its section 1, and an internet connection for a few small downloads
  • Time to run: The commands took less than a minute when tested
  • Level: Beginner

Imagine a straight line from Indonesia through the centre of the Earth to the other side. Which place does it reach? This chapter answers the question with GDAL’s command-line programs only, and uses it to show the parts of a one-line command: the source of the data, the steps, and the file with the result.

The same methods then answer three more questions: which countries lie opposite, which towns are nearest to the points opposite Indonesian cities, and how large Indonesia is when it is drawn over Europe.

NoteLearning objectives

By the end of this chapter you will be able to:

  • read a file inside a zip on a web server, without downloading it yourself;
  • read the same file from your own disk, or from a fork on GitHub;
  • read any GDAL line in three parts: source, steps, destination;
  • write a line once and run it in bash, PowerShell and cmd;
  • use SQL inside a line to move shapes and to measure them;
  • draw a finished map with GDAL alone;
  • check a result against an answer you know in advance.

Before running this chapter, do section 1 of Chapter 0, which installs GDAL. The lines can be pasted into a terminal one by one, or run from this notebook.

1. The working folder

Chapter 0 installs GDAL and explains the form of a command. If you know that already, you only need its section 1.

This chapter uses both groups of programs: the new one called gdal, and the older ones, which start with gdal for rasters and with ogr for vectors. The older ones are called “traditional” in GDAL’s documentation, and classic in this series (ledger L2).

In a terminal: make an empty folder, go there, and copy into it the two colour files from sample-data/ch01. Sections 6 and 8 use them.

In this notebook: the next cell does that for you, and adds the %%line cells of Chapter 0.

import sys
import time
from pathlib import Path

# The repository root, whether the notebook runs from en/, id/ or the root itself
ROOT = Path.cwd() if (Path.cwd() / "tutorial.yml").exists() else Path.cwd().parent
sys.path.insert(0, str(ROOT / "src"))
import oneline

T0 = time.perf_counter()
WORK = oneline.start("01")          # a folder outside the repository; see src/oneline.py to choose it
print("working folder:", WORK.name, "| files copied there:", sorted(f.name for f in (ROOT / "sample-data/ch01").iterdir()))
working folder: ch01 | files copied there: ['antipode.txt', 'truesize.txt']
gdalinfo --version
GDAL 3.12.3 "Chicoutimi", released 2026/03/17

Look before moving on. This chapter was tested with GDAL 3.12.3 on Windows 11 (ledger L1). The gdal pipeline lines of sections 6 and 8 need 3.12 or later (ledger L3). The gdal program is still provisional, and its makers reserve the right to change it (ledger L2), so the lines may need a small correction for a later version.

Warm-up

A few short commands first, in the form of Chapter 0. They need a small map of the world, and the first line reads it from the web. The long address is explained in section 2:

gdal vector convert /vsizip//vsicurl/https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip small.geojson --overwrite

gdal vector rasterize small.geojson small.tif --burn 255 --ot Byte --size 1440,720 --extent -180,-90,180,90 --overwrite

gdal raster edit small.tif --nodata none

gdal raster convert small.tif small.png --overwrite

The land of the world in white on black, in the usual position.

That is a world map in four commands. (The third one keeps the black ground, which would be transparent otherwise. Section 3 of Chapter 0 explains it.) Each point of it has two numbers, x to the east and y to the north. What happens if somebody exchanges them?

gdal vector swap-xy small.geojson swapped.geojson --overwrite

gdal vector rasterize swapped.geojson swapped.tif --burn 255 --ot Byte --size 360,720 --extent -90,-180,90,180 --overwrite

gdal raster edit swapped.tif --nodata none

gdal raster convert swapped.tif swapped.png --overwrite

The same world, rotated by 90 degrees and mirrored, in a tall picture. North is on the right, and Antarctica is a white strip at the left edge.

Look before moving on. The map is rotated by 90 degrees and mirrored. This is a common error in real data, because some programs write the latitude first. If your points are in a place where they cannot be, try swap-xy.

This also shows the method of this chapter. The shapes on a map are stored as numbers, and a command can calculate with them. In section 6, a calculation of this kind moves every point of Indonesia to the opposite side of the Earth.

2. What is inside a zip on a web server?

Natural Earth is a set of free world map layers in the public domain (ledger L6). Its countries come as a zip. This line lists the layers in it:

ogrinfo -q "/vsizip//vsicurl/https://naciscdn.org/naturalearth/50m/cultural/ne_50m_admin_0_countries.zip"
1: ne_50m_admin_0_countries (Polygon)

ogrinfo describes a vector dataset, and -q keeps it short. The rest is the address, read from right to left:

  • https://naciscdn.org/...zip is an ordinary web address;
  • /vsicurl/ in front of it makes GDAL read from the web as if from a disk;
  • /vsizip/ in front of that makes it read the files inside the zip.

These prefixes are called virtual file systems, and they can be chained like this (ledger L4). They work in almost every place where GDAL expects a file name.

The zip contains one layer, ne_50m_admin_0_countries, made of polygons.

3. The parts of a line

Reading from the web every time is slow, and it causes unnecessary traffic on the server. The next line saves a local copy, with only the columns this chapter needs.

ogr2ogr -overwrite world.gpkg "/vsizip//vsicurl/https://naciscdn.org/naturalearth/50m/cultural/ne_50m_admin_0_countries.zip" -nln land -nlt PROMOTE_TO_MULTI -select "ADMIN,ISO_A3,CONTINENT,POP_EST"

It printed nothing, which means that there was no error. ogr2ogr copies vector data from anything GDAL can read to anything it can write, and can change it at the same time. Its parts:

Part Role Meaning
ogr2ogr program copy and convert
-overwrite option replace the layer if it exists, so the line can be run again
world.gpkg destination a GeoPackage, one file that holds many layers
"/vsizip//vsicurl/...zip" source the zip on the web
-nln land step new layer name
-nlt PROMOTE_TO_MULTI step store every shape as a multipolygon, since some countries are one polygon and others many
-select "..." step keep four columns

ogr2ogr needs the destination before the source. This is the opposite of cp and copy, and of gdal_translate, the program that copies rasters. It is worth checking twice before pressing Enter.

Now look at some of it. The destination /vsistdout/ is the screen:

ogr2ogr -f CSV /vsistdout/ world.gpkg land -where "CONTINENT='South America'"
ADMIN,ISO_A3,CONTINENT,POP_EST
Venezuela,VEN,South America,28515829
Uruguay,URY,South America,3461734
Falkland Islands,FLK,South America,3398
Suriname,SUR,South America,581363
Peru,PER,South America,32510453
Paraguay,PRY,South America,7044636
Guyana,GUY,South America,782766
Ecuador,ECU,South America,17373662
Colombia,COL,South America,50339443
Chile,CHL,South America,18952038
Brazil,BRA,South America,211049527
Bolivia,BOL,South America,11513100
Argentina,ARG,South America,44938712

Look before moving on. Each row is one country, with its population estimate. There is no row for French Guiana. In this layer, overseas regions belong to the country that governs them (ledger L7), and that will show in section 7.

4. One country out of a world file

A line for everyday work: one country, three columns, as a small GeoJSON file for a web page. There are two ways to write it. The first uses ogr2ogr’s own options, -where for the rows and -select for the columns. The second does both in SQL, and also rounds the coordinates to three decimals.

ogr2ogr -overwrite indonesia_full.geojson world.gpkg land -where "ADMIN='Indonesia'" -select "ADMIN,ISO_A3,POP_EST"

ogr2ogr -overwrite indonesia.geojson world.gpkg -sql "select admin, iso_a3, pop_est, geom from land where admin='Indonesia'" -lco COORDINATE_PRECISION=3
import json

def features(name):
    return json.loads((WORK / name).read_text(encoding="utf-8"))["features"]

for name in ("indonesia_full.geojson", "indonesia.geojson"):
    print(f"{name:24s} {(WORK / name).stat().st_size / 1000:6.1f} kB | columns: {list(features(name)[0]['properties'])}")
indonesia_full.geojson    155.3 kB | columns: ['ADMIN', 'ISO_A3', 'CONTINENT', 'POP_EST']
indonesia.geojson          77.6 kB | columns: ['ADMIN', 'ISO_A3', 'POP_EST']

Look before moving on. Rounding halved the file. -lco passes an option to the format that is being written, here GeoJSON. One thousandth of a degree is about 111 m at the equator (40,075 km divided by 360 and by 1,000), which is enough for a map of a whole country on a screen and too coarse for a street.

Now look at the columns. The first file also has CONTINENT, which the line did not ask for. In GDAL 3.12.3, reading a GeoPackage with -where and -select together ignored -select without a warning (ledger L14). The line in section 3 was not affected, because it had no -where. If a column is confidential, write the columns in SQL as in the second line, and check the result before you send it.

The same line in the new syntax. With gdal, a line can be written as a pipeline. Steps follow one another in the order they happen, separated by ! (ledger L3), and the source comes first:

gdal vector pipeline read world.gpkg --input-layer land ! filter --where "ADMIN='Indonesia'" ! select "ADMIN,ISO_A3,POP_EST,_ogr_geometry_" ! write indonesia_new.geojson --lco COORDINATE_PRECISION=3 --overwrite
print("same features in both files:", features("indonesia.geojson") == features("indonesia_new.geojson"))
same features in both files: True

The select step keeps only what it names, and that includes the shapes: without _ogr_geometry_ in the list, the file has the three columns and no geometry.

This series uses both forms. Existing scripts usually use the classic programs. The pipeline is easier to read when there are many steps, and it can go from vector to raster without a file in between (section 6).

One more source of errors, also tested. A pipeline can hold a step with SQL. These two lines count the features that are left after keeping Indonesia, and they differ only by a step called materialize:

gdal vector pipeline read world.gpkg --input-layer land ! filter --where "ADMIN='Indonesia'" ! sql --dialect SQLite "select count(*) n from land" ! write /vsistdout/ --output-format CSV

gdal vector pipeline read world.gpkg --input-layer land ! filter --where "ADMIN='Indonesia'" ! materialize ! sql --dialect SQLite "select count(*) n from land" ! write /vsistdout/ --output-format CSV
n
242
n
1

Look before moving on. The first line counted every country. In GDAL 3.12.3 the sql step went back to the original layer, ignored the filter, and gave no warning. materialize stores the result so far, and then the count is right. It is safer to put the condition inside the SQL, as the next sections do.

Keep --dialect SQLite in these two lines. On a GeoPackage, read --input-layer followed by sql without it printed its answer and then crashed the program in this version (ledger L13).

5. One line for every shell

A shell is the program that reads what you type: cmd or PowerShell on Windows, bash or zsh on Linux and macOS. Each has its own rules for quotes and special characters. With four rules, a line is the same in all of them. Each reason was tested with a small program that prints the arguments it receives (ledger L9):

Rule What happens otherwise
Double quotes outside, single quotes inside: "ADMIN='Indonesia'" in cmd, 'a b' arrives as two words, because single quotes mean nothing there. PowerShell removes single quotes that are not inside double ones, and SQL needs them
Quote every web address, and anything with a space or one of & ; ( ) { } @ # http://x/?a=1&b=2 arrives as http://x/?a=1 in cmd and Git Bash, and does not run at all in PowerShell
No $, no backtick and no % $HOME is replaced in PowerShell and bash, and %OS% in cmd. A backtick starts an escape in PowerShell and a command in bash
No quotes around a whole pipeline it would need \" inside, and PowerShell 7 and Windows PowerShell each cut such a text at a different place

PowerShell’s rules for quotes are in its documentation (ledger L8).

All lines of this chapter were run unchanged in cmd, Windows PowerShell 5.1, PowerShell 7 and Git Bash, and gave the same output and the same files. bash and zsh on Linux were given the same lines without GDAL, and passed on exactly the same arguments (ledger L10). Nothing has been run on macOS yet.

Git Bash on Windows needs one setting. It turns words that start with / into Windows paths (ledger L11), so /vsizip/ arrives at GDAL as a folder that does not exist. Type this once in each Git Bash window:

export MSYS_NO_PATHCONV=1

6. The other side of Indonesia

The point exactly opposite another one, through the centre of the Earth, is its antipode. The rule is short: change the sign of the latitude, and change the longitude by 180 degrees. Jakarta, near 6.2 S 106.8 E, becomes 6.2 N 73.2 W.

Before using a rule, test it. EPSG:4978 gives a position as x, y and z in metres from the centre of the Earth. Two points opposite each other must have the same three numbers with opposite signs:

gdaltransform -s_srs EPSG:4979 -t_srs EPSG:4978 -coord 106.8 -6.2 0

gdaltransform -s_srs EPSG:4979 -t_srs EPSG:4978 -coord -73.2 6.2 0
-1832773.34659722 6070438.19331649 -684250.07989939
1832773.34659722 -6070438.19331649 684250.07989939

Look before moving on. The numbers agree to the last digit, with the signs reversed. So the rule also holds on the ellipsoid, the slightly flattened globe that GPS uses, and not only on a perfect sphere.

To move a whole country this way, SQL has two functions: shiftcoords adds a number to x and y, and scalecoords multiplies them.

ogr2ogr -update -overwrite world.gpkg world.gpkg -sql "select admin, scalecoords(shiftcoords(geom,-180,0),1,-1) geom from land where admin='Indonesia'" -nln antipode -nlt MULTIPOLYGON

-sql replaces the source layer by the result of a query, and -update adds a layer to the file instead of starting a new one. A GeoPackage is an SQLite database, so the query is SQLite’s SQL with spatial functions added by SpatiaLite. The same functions work on other formats with -dialect SQLite, as long as GDAL was built with SpatiaLite (ledger L5).

Where the antipode touches land, the two shapes overlap. This line keeps the overlap, country by country:

ogr2ogr -update -overwrite world.gpkg world.gpkg -sql "select land.admin, st_intersection(land.geom, antipode.geom) geom from land join antipode on st_intersects(land.geom, antipode.geom)" -nln overlap -nlt PROMOTE_TO_MULTI

Now the map, as one pipeline from shapes to a PNG picture:

gdal pipeline read world.gpkg ! sql "select 1 v, geom from land union all select 2, geom from land where admin='Indonesia' union all select 3, geom from antipode union all select 4, geom from overlap" ! rasterize --attribute-name v --init 0 --ot Byte --size "1800,680" --extent "-180,-58,180,78" ! edit --nodata none ! color-map --color-map antipode.txt ! write antipode.png --overwrite

World map on a dark blue background. Indonesia is yellow. Its antipode lies across northern South America: cream where it falls on land, from Ecuador to the Guianas, and red where it falls in the sea, off Ecuador and in the Atlantic.

Read it step by step:

  1. sql stacks four sets of shapes and gives each a number v: all land 1, Indonesia 2, its antipode 3, the overlap 4.
  2. rasterize writes the number of each shape into the cells inside it. Later shapes replace earlier ones, so the order in the query is important. --init 0 is the sea, and --extent leaves out the polar regions.
  3. edit --nodata none says that 0 is a value like any other. Without it the sea would count as “no data”.
  4. color-map turns numbers into colours, using antipode.txt. Each row there is a number and its red, green and blue.
  5. write chooses the format from the ending .png.

Look before moving on. Yellow is Indonesia, cream is the part of its antipode that is on land, and red is the part that is in the sea. The antipode of Sumatra is in Colombia and Ecuador, that of the Indonesian part of Borneo in northern Brazil, Venezuela and Colombia, and that of Papua in the Atlantic (ledger L15). North and south are swapped but east and west are not, so the antipode of Java lies to the north of that of Borneo.

7. Countries and towns on the other side

Which countries lie opposite, and how much land is that? st_area(geom, 1) measures on the ellipsoid, in square metres, so the layer does not have to be projected first.

ogr2ogr -f CSV /vsistdout/ world.gpkg -sql "select admin, round(st_area(geom,1)/1e6) km2, round(100*st_area(geom,1)/(select st_area(geom,1) from antipode),1) percent_of_indonesia from overlap order by km2 desc"

ogr2ogr -f CSV /vsistdout/ world.gpkg -sql "select round(100*sum(st_area(geom,1))/(select st_area(geom,1) from antipode),1) percent_on_land from overlap"
ADMIN,km2,percent_of_indonesia
Brazil,496165,26.6
Colombia,322602,17.3
Venezuela,212542,11.4
Ecuador,128833,6.9
Guyana,63383,3.4
Suriname,12292,0.7
France,8806,0.5
Peru,2349,0.1
percent_on_land
66.9

Look before moving on. About two thirds of Indonesia has land on the other side, and most of it is in Brazil and Colombia. “France” in South America is French Guiana, as section 3 explained: the town of Cayenne lies inside the polygon named France (ledger L7).

Which town is nearest to each opposite point? For that we need towns. The first line adds Natural Earth’s populated places to the file. The second moves the Indonesian cities above 1.5 million people to the other side, with the same expression as before.

ogr2ogr -update -overwrite world.gpkg "/vsizip//vsicurl/https://naciscdn.org/naturalearth/10m/cultural/ne_10m_populated_places_simple.zip" -nln town -select "name,adm0name,pop_max"

ogr2ogr -update -overwrite world.gpkg world.gpkg -sql "select name city, pop_max, scalecoords(shiftcoords(geom,-180,0),1,-1) geom from town where adm0name='Indonesia' and pop_max>1500000" -nln surfacing
ogr2ogr -f CSV /vsistdout/ world.gpkg -sql "select s.city, round(st_y(s.geom),2) lat, round(st_x(s.geom),2) lon, t.name nearest_town, t.adm0name country, round(min(st_length(makeline(s.geom,t.geom),1))/1000) km from surfacing s join town t on abs(st_x(t.geom)-st_x(s.geom))<2 and abs(st_y(t.geom)-st_y(s.geom))<2 group by s.city order by s.pop_max desc"
city,lat,lon,nearest_town,country,km
Jakarta,6.17,-73.17,Socorro,Colombia,34
Surabaya,7.25,-67.25,San Fernando de Apure,Venezuela,76
Bandung,6.95,-72.43,Pamplona,Colombia,55
Bekasi,6.22,-73.03,Socorro,Colombia,38
Medan,-3.58,-81.35,Tumbes,Peru,99
Palembang,2.98,-75.25,Neiva,Colombia,10

This is the longest query of the chapter. It shows how to find the nearest of many points, which is useful in other projects, too.

  • join ... on abs(...)<2 pairs every opposite point with the towns less than 2 degrees away in both directions. Two degrees is more than 200 km here, so no town nearer than the distances in the table can have been missed.
  • makeline makes a line from the opposite point to the town, and st_length(..., 1) measures it on the ellipsoid.
  • group by s.city with min(...) keeps the shortest. In SQLite, the other columns then come from that same row (ledger L12). This is a rule of SQLite: do not count on it in another database.

Look before moving on. The point opposite Jakarta is 34 km from Socorro, in Colombia. Only towns in Natural Earth’s list count, so there may well be a smaller place that is closer. The point opposite Medan is in the sea: 3.58 S 81.35 W is west of the coast at Tumbes, in Peru.

8. The true size of Indonesia

The Mercator projection, also in the form web maps use, stretches what is far from the equator. At 50 N it draws distances 1.56 times as long as at the equator (ledger L16), so Europe looks larger beside Indonesia than it is. To compare them, move the shape of Indonesia to Europe without changing its size. This takes two lines.

The first line projects Indonesia with an equal-area projection centred on the country itself, at 2.5 S 118 E, in the sea between Balikpapan on Borneo and Majene on Sulawesi (ledger L15). Every point is now so many metres east and north of that centre.

ogr2ogr -update -overwrite world.gpkg world.gpkg land -where "ADMIN='Indonesia'" -t_srs "+proj=laea +lat_0=-2.5 +lon_0=118" -nln indonesia_flat

The second line gives these metres a different centre. -a_srs does not change any coordinate: it only declares which coordinate system they belong to. Here the declared system is deliberately not the true one. Its centre is at 50 N 15 E, between Prague and Pardubice in Czechia (ledger L15). The metres stay the same, and the shape of Indonesia is now in Europe.

ogr2ogr -overwrite europe.gpkg world.gpkg indonesia_flat -a_srs "+proj=laea +lat_0=50 +lon_0=15" -nln moved

ogr2ogr -update -overwrite europe.gpkg world.gpkg land -clipsrc -45 5 100 80 -t_srs "+proj=laea +lat_0=50 +lon_0=15" -nln land -nlt PROMOTE_TO_MULTI

gdal pipeline read europe.gpkg ! sql "select 1 v, geom from land union all select 2, geom from moved" ! rasterize --attribute-name v --init 0 --ot Byte --size "1500,800" --extent "-3000000,-1400000,3000000,1800000" ! edit --nodata none ! color-map --color-map truesize.txt ! write truesize.png --overwrite

Map of Europe in grey with Indonesia in red laid over it at the same scale. Sumatra runs from west of Ireland to the Bay of Biscay, Borneo covers the Low Countries and Germany, Java lies across southern France and the Alps, and Papua reaches the Caucasus and the Caspian Sea.

Look before moving on. Drawn over Europe, Indonesia reaches from the Atlantic west of Ireland to the Caspian Sea. Both shapes are drawn in the same equal-area projection, so their areas can be compared by eye.

Did the move change the size? Convert the moved shape to longitude and latitude, measure it there on the ellipsoid, and compare with the original. The two must agree.

ogr2ogr -overwrite back.gpkg europe.gpkg moved -t_srs EPSG:4326 -nln moved

ogr2ogr -f CSV /vsistdout/ world.gpkg -sql "select 'in place' where_, round(st_area(geom,1)/1e6) km2 from land where admin='Indonesia'"

ogr2ogr -f CSV /vsistdout/ back.gpkg -sql "select 'over Europe' where_, round(st_area(geom,1)/1e6) km2 from moved"
where_,km2
in place,1863915
where_,km2
over Europe,1863915

Remember the difference between the two options, because mixing them up is an easy way to put data in the wrong place:

Option What it does Use it when
-t_srs computes new coordinates the file has a correct CRS, and you need another
-a_srs attaches a label and changes no coordinate the label is missing or wrong. Section 8 is an exception: there it moves a shape

9. The same line with your own copy

The lines so far read from the web. That is handy, and it needs a connection each time. With a file on your own disk, only the beginning of the address changes, and the rest of the line stays as it is. GDAL can make the copy, too:

gdal vsi copy "/vsicurl/https://naciscdn.org/naturalearth/50m/cultural/ne_50m_admin_0_countries.zip" countries.zip

gdal vsi copy -r /vsizip/countries.zip unpacked

The first line downloads the zip, as a browser would. The second one unpacks it into a folder. Now run the same query three times: with the file on the web, with the zip on the disk, and with the unpacked file:

ogr2ogr -f CSV /vsistdout/ /vsizip//vsicurl/https://naciscdn.org/naturalearth/50m/cultural/ne_50m_admin_0_countries.zip -sql "select count(*) countries from ne_50m_admin_0_countries"

ogr2ogr -f CSV /vsistdout/ /vsizip/countries.zip -sql "select count(*) countries from ne_50m_admin_0_countries"

ogr2ogr -f CSV /vsistdout/ unpacked/ne_50m_admin_0_countries.shp -sql "select count(*) countries from ne_50m_admin_0_countries"
countries
242
countries
242
countries
242

The results are the same. These are all the beginnings that you need:

Where the file is What to write
a zip on a web server "/vsizip//vsicurl/https://server/file.zip"
a zip in the folder where you are /vsizip/file.zip
a zip somewhere else on your disk "/vsizip/C:/data/file.zip" on Windows, /vsizip//home/me/data/file.zip on Linux and macOS. Windows also accepts / between folders
a folder that you unpacked "C:/data/countries/ne_50m_admin_0_countries.shp"
a GeoPackage in a zip, such as usgs.gpkg.zip the name alone is enough, because GDAL recognises this ending
a file that is not a zip, on a web server "/vsicurl/https://server/file.tif"

From a clone or a fork of this tutorial. The repository has the small files of each chapter in sample-data, and for some chapters also a copy of the data. If you cloned it, they are on your disk. Type this in the folder of the repository:

ogrinfo sample-data/ch04/usgs.gpkg.zip

Without a clone, GDAL reads them from GitHub. Put the name of your own account in place of YOUR-NAME if you made a fork, or osgeoid for the original:

ogrinfo "/vsizip//vsicurl/https://raw.githubusercontent.com/YOUR-NAME/gdal-oneliners/main/sample-data/ch04/usgs.gpkg.zip"

The address must begin with raw.githubusercontent.com. The address in your browser, with github.com and blob in it, leads to a web page about the file, and not to the file (ledger L64).

To work without a connection, download these files first, into a folder data in the repository. Git ignores a folder with this name, so nothing large ends up in your fork by accident.

Chapter Files Size Without a connection
0 none all data is in sample-data/ch00
1 countries, small countries for the warm-up, places 1.5 MB /vsizip/ and the name of the zip
2 none all data is in sample-data/ch02
3 stars, constellations 14 MB CSV:/vsigzip/ and the name for the stars, and the name alone for the constellations
4 earthquakes from a request to the USGS, land 0.5 MB, and up to 10 MB for the earthquakes a copy of the earthquakes is in sample-data/ch04
5 storms, land, countries 21 MB /vsizip/ and the name of the zip
6 timetable 2.5 MB GTFS: and the name of the zip
7 districts 3 MB nothing to download: the file is in sample-data/ch07
8 land, small islands, places as in Chapter 1 4 MB /vsizip/ and the name of the zip. Airports and the land of Indonesia are in sample-data/ch08
9 parts of ETOPO 2022 and of the Copernicus relief, mountains 23 MB copies of everything except the mountains are in sample-data/ch09
10 a part of the Copernicus relief (Bali) 9 MB a copy is in sample-data/ch10
11 parts of the CHIRPS3 rain of 2023 and of ESA WorldCover 2 MB copies are in sample-data/ch11
12 parts of ETOPO 2022 and of the Copernicus relief (Bali) 13 MB copies are in sample-data/ch12
13 none all data is in sample-data/ch13
14 a part of the Copernicus relief (Lake Toba), parts of about 100 Sentinel-2 images 150 MB copies for everything except the sheet of section 3 and the film of section 6 are in sample-data/ch14
15 parts of the Copernicus relief and of DeltaDTM (Padang) 10 MB copies are in sample-data/ch15
16 earthquakes of a month, the list of volcanoes, and reliefs of 101 volcanoes 500 MB copies are in sample-data/ch16 (2 MB for the picture with all volcanoes)
17 a part of ETOPO 2022, storms, earthquakes, land 53 MB copies of everything except the globe are in sample-data/ch17

For example, with the zip of Chapter 5 in the folder data, the long address in its first line becomes /vsizip/../data/IBTrACS.since1980.list.v04r01.points.zip, if you work in a folder next to data.

Try it yourself

  • Another country. Change Indonesia in the first two lines of section 6. For a country with western longitudes, such as Brazil, write 180 in place of -180 so that the result stays between -180 and 180.
  • Another comparison. In section 8, centre the second projection on your own choice of place and change the window of -clipsrc (west, south, east, north).
  • Other colours. Edit antipode.txt and run the pipeline of section 6 again.

Checkpoint

The cell below stops with an error if the results are not what this chapter expects.

def value(dataset, sql):
    """One number from a query."""
    return float(oneline.run(f'ogr2ogr -f CSV /vsistdout/ {dataset} -sql "{sql}"').splitlines()[1].strip('"'))

here = value("world.gpkg", "select st_area(geom,1)/1e6 a from land where admin='Indonesia'")
there = value("world.gpkg", "select st_area(geom,1)/1e6 a from antipode")
moved = value("back.gpkg", "select st_area(geom,1)/1e6 a from moved")
on_land = value("world.gpkg", "select sum(st_area(geom,1))/1e6 a from overlap")

assert abs(there - here) < 1, "the antipode should be as large as Indonesia"
assert abs(moved - here) < 1, "Indonesia should keep its size over Europe"
assert 0.5 < on_land / here < 0.8, "about two thirds of the antipode should fall on land"
assert features("indonesia.geojson") == features("indonesia_new.geojson")
assert all((WORK / f).stat().st_size > 10_000 for f in ("antipode.png", "truesize.png"))
print(f"checkpoint passed: Indonesia {here:,.0f} km2, its antipode {there:,.0f} km2, over Europe {moved:,.0f} km2")
print(f"time since the first cell: {time.perf_counter() - T0:.0f} s")
checkpoint passed: Indonesia 1,863,915 km2, its antipode 1,863,915 km2, over Europe 1,863,915 km2
time since the first cell: 44 s

Troubleshooting

Symptom Cause Fix
gdalinfo is not recognized, or command not found The environment is not active in this terminal conda activate gdal-oneliners
gdal is not recognized, but gdalinfo works GDAL is older than 3.11 Create the environment of Chapter 0, section 1
Git Bash: an address with /vsizip/ or /vsistdout/ is not found Git Bash changed it into a Windows path export MSYS_NO_PATHCONV=1 (section 5)
The output has columns that -select left out -where and -select together on a GeoPackage, in GDAL 3.12.3 (ledger L14) Name the columns in -sql (section 4)
A file from a pipeline has columns but no shapes The select step dropped the geometry Add _ogr_geometry_ to its list
no such function: shiftcoords This GDAL was built without SpatiaLite Use the conda-forge build of Chapter 0, section 1
The sea is white or transparent in the picture 0 is still declared as “no data” Keep the step edit --nodata none
A pipeline with --input-layer and sql crashes after printing its result A fault in GDAL 3.12.3 (ledger L13) Add --dialect SQLite to the step, or leave out --input-layer
A count or a sum is too large after filter ! sql The sql step read the unfiltered layer Put the condition in the SQL, or add materialize (section 4)

What comes next

In section 8, Indonesia was wider than most of Europe. On the maps in many classrooms it does not look so wide, although both maps are made from the same coordinates. Chapter 2: Choosing a map projection explains why every flat map changes sizes or shapes, and how to choose a projection with small errors for your purpose.

Made with Natural Earth.