In this series: Part IV, Surfaces. A relief also shows which places can be seen from a mountain. This chapter calculates it
You will build: The view from Agung as a map and as a panorama; a map of the places without a view of the summit; the shadow of a volcano at seven in the morning; and a chain of six summits with a view of each other from Banten to Sumbawa
You need: Chapter 0, for the environment, and section 5 of Chapter 1, for lines that work in every shell. Chapter 9 explains a raster as a table
Time to run: The commands took about three minutes when tested, including 13 MB of downloads, or none with the copies in the folder. About 600 MB of free space
Level: Intermediate; the first commands are short, and sections 4 and 7 have longer queries
From a mountain, a place is visible if a straight line leads to it with nothing in the way. Every place that is not visible has something in front of it: a ridge, the edge of a crater, or the curve of the Earth itself.
A relief is enough to calculate this, for all cells of a map at once. GDAL has a command for it, viewshed. This chapter uses it for the highest mountain of Bali. How far is the horizon? Which places have no view of the summit? What does the view look like?
The same calculation also works in the other direction. If one place is visible from another, the reverse is true as well. A place with a free line to the sun is in the light. And if each summit has a view of the next one, a message can be passed on with fires. How far does such a chain reach?
NoteLearning objectives
By the end of this chapter you will be able to:
calculate what can be seen from a place, over land and sea;
test a command on an artificial map for which you know the answer;
find the highest cell near a point, and explain why you need it;
calculate how high something has to be, so that it can be seen;
draw a panorama, with one projection and one window function;
calculate the shadows of mountains, with the sun as the observer;
find the places that are visible from most others;
join summits with a view of each other, and find the shortest chain.
Before running this chapter, do section 1 of Chapter 0 and section 5 of Chapter 1. In a terminal, make a new empty folder and copy into it the files of sample-data/ch12. In this notebook, the next cell does that.
import sysimport timefrom pathlib import Path# The repository root, whether the notebook runs from en/, id/ or the root itselfROOT = Path.cwd() if (Path.cwd() /"tutorial.yml").exists() else Path.cwd().parentsys.path.insert(0, str(ROOT /"src"))import onelineT0 = time.perf_counter()WORK = oneline.start("12")print("working folder:", WORK.name, "| files copied there:", sorted(f.name for f in (ROOT /"sample-data/ch12").iterdir()))
A few short commands first. The folder has a relief of Bali, in metres. The observer stands on the beach of Sanur, in the south-east. What is visible from there?
That is all. --pos has three numbers: east, north, and the height of the eyes above the ground, here 2 m. The result is a raster with 255 where the ground is visible, and 0 where it is not. Put it on top of the relief:
Look before moving on. The land behind the observer is hidden: the first trees and houses are enough. In front lies a half disc of sea, and it ends only five kilometres away. But the slopes of the volcanoes are white again, up to the summit of Agung, 46 km away. And of Nusa Penida, the high parts are visible and the shore is not.
So two things decide what is visible: what stands in the way, and how high the place is. But why does the visible sea end?
1. A test with a known answer
Before you trust a command, test it where you can check the result. Here is the simplest landscape: an empty sea, 500 km wide, with height 0 everywhere. In its middle, the observer is 3,000 m above the water:
Even on an empty sea, not everything is visible. The Earth is round, and at some distance the water lies below the line of sight. This is the horizon. GDAL includes it without an option.
The expected number comes from geometry. The distance to the horizon is the square root of 2 * R * h, with the radius of the Earth R and the height h of the observer. The air bends light a little, in the direction of the curve of the Earth, so the horizon is farther away than that. GDAL reduces the curve by one seventh for it (ledger L121). Together, this gives a useful rule (ledger L122):
distance in km = 3.86 * square root of your height in metres
The two numbers agree within the size of a cell here, which is half a kilometre. Now use the rule for other heights:
ogr2ogr-f CSV /vsistdout/ summits.csv -dialect SQLite -sql"select value height_of_the_eye_m, round(3.86*sqrt(value),1) horizon_km from json_each(json_array(2,10,100,1000,3000))"
On the beach, the horizon is five and a half kilometres away. This was the half disc of the warm-up. From a roof at 10 m, it is twice as far. And from the height of Agung, it is more than 200 km.
2. The view from Agung
Such a view needs a large map. Take two reliefs, one for the far view and one for the near one:
Java, Bali, Lombok and the larger part of Sumbawa, in cells of about 460 m (ledger L123). This file has the bottom of the sea, too. reclassify sets everything below 0 to 0, because the surface of the water is needed here
2
Bali alone, in cells of 80 m, from the Copernicus model (ledger L80)
3
both together, for everything that can be visible from Agung, in metres. viewshed measures distances, so it needs a projection in metres. Where two files overlap, the last one is used, so the summit comes from the finer file
Without a connection, use offline_relief.tif as relief.tif, and offline_bali.tif as bali.tif.
Where is the summit? summits.csv has a position for Agung, from a gazetteer. Read the height of the relief there. Then find the highest cell within 3 km:
gdallocationinfo-valonly-l_srs EPSG:4326 bali.tif 115.505 -8.3425ogr2ogr-overwrite agung.gpkg summits.csv -dialect SQLite -sql"select name, st_buffer(st_transform(makepoint(cast(lon as real),cast(lat as real),4326),32750),3000) geom from summits where name='Agung'"-nln agung -nlt POLYGON -a_srs EPSG:32750gdal raster zonal-stats bali.tif /vsistdout/ --zones agung.gpkg --stat max --stat max_center_x --stat max_center_y --output-format CSV
At the position of the gazetteer, the height is 2,669 m, more than 300 m too low, and the top is 800 m away. The position is not wrong. It marks the volcano, and Agung has a crater with steep walls, with the highest point on its western edge (ledger L129). From the marked point, only a wall of rock and the sky are visible.
This is the most common mistake with lines of sight: the point is right on the map, and it is beside the summit in the relief. Always take the position from the relief itself.
Now calculate the view, from 2 m above the highest cell. One raster shows what is visible, a second one what is land and what is sea, and zonal-stats counts. (The second number is 9077800 here, and not 9077720, because wide.tif has larger cells. This is the middle of its highest one.)
gdal raster viewshed wide.tif seen.tif --pos 334600,9077800,2 --overwritegdal raster calc -i C=wide.tif -o island.tif --calc"(C>0.5) ? 1 : 2"--ot Byte --overwritegdal raster zonal-stats seen.tif share.csv --zones island.tif --stat count --stat mean --overwriteogr2ogr-f CSV /vsistdout/ share.csv -dialect SQLite -oo AUTODETECT_TYPE=YES -sql"select case value when 1 then 'land' else 'sea' end what, cast(count*0.16 as integer) km2_on_the_map, cast(count*0.16*mean/255 as integer) km2_seen, cast(round(mean/2.55) as integer) percent from share"
From one point, about 100,000 km2 of sea are visible, and about 9,000 km2 of land. The number for the land is less reliable. This relief has no small ridges, so it hides too little. With cells of 200 m, from a finer model, the visible land is only 7,400 km2, and the sea hardly changes (ledger L127).
Look before moving on. The bright places are visible from the summit. The round edge is the horizon of section 1. Behind every high mountain lies a dark area, and it gets wider with the distance. Rinjani, on Lombok, hides a good part of Sumbawa.
At the left edge, in Java, there is visible land beyond the horizon. The sea beside it is already below the line of sight, but the tops of the mountains are still above it. The small golden spot at the very edge is Semeru, the highest mountain of Java, 285 km away.
On the north coast of Bali, the dark part begins less than 30 km from the summit. Mountains hide more of the land than the curve of the Earth does.
3. Which places have no view of the summit?
In Bali, the mountain is also a direction. Kaja is towards the mountain, and kelod is towards the sea. So kaja is north for people in the south of the island, and south for people in the north (ledger L124). But can they see the mountain from where they live?
A number is more useful here than yes or no. If the summit of Agung is not visible from a place, how many metres above the ground does it become visible? This is also the height that a kite at this place needs to be visible from the summit. --mode ground calculates it for every cell:
(The materialize inside the brackets is optional. Without it, GDAL 3.12 leaves a small file in your folder that has the text in the brackets as its name.)
Look before moving on. Where there is no violet, the summit is visible. The violet shows the air below the last line of sight, which just touches the ridge in front of the place. A darker colour means a larger height. High ridges reach above this line and have no colour.
Now calculate the number for real places. The towns are points, and zonal-stats needs areas, so give each one a circle of 300 m:
ogr2ogr-overwrite towns.gpkg towns.csv -dialect SQLite -sql"select name, st_buffer(st_transform(makepoint(cast(lon as real),cast(lat as real),4326),32750),300) geom from towns"-nln towns -nlt POLYGON -a_srs EPSG:32750gdal raster zonal-stats kite.tif hidden.csv --zones towns.gpkg --include-field name --stat mean --overwriteogr2ogr-f CSV /vsistdout/ hidden.csv -dialect SQLite -oo AUTODETECT_TYPE=YES -sql"select name, cast(round(mean) as integer) climb_m from hidden order by mean, name"
Denpasar, Ubud and the other towns of the south have a view of the summit, if no house stands in the way. (The relief has houses and trees in it, but blurred, in cells of 80 m.)
Singaraja, on the north coast, has no view of it. The summit becomes visible only 177 m above the town. Toyabungkah lies at the lake in the crater of Batur, only 15 km from the summit, and there the number is 576 m.
The largest number, more than 2,000 m, belongs to Amed. It lies at the foot of the mountain, on the eastern side, 16 km from the top. The reason is the position of the observer, on the western edge of the crater. The eastern edge is in the way. From a summit, the land directly below is often not visible.
4. A panorama from the summit
The map shows which places are visible, but not what the view looks like. This section draws the view in all directions, as a person on the summit sees it.
For this, the land must be in another order: not by east and north, but by direction and distance. A globe has this order already. Around the North Pole, the meridians are directions, and the parallels are rings of equal distance. So choose a special projection, as in Chapter 2, and move the North Pole to Agung:
Look before moving on. This is the land around Agung, strongly distorted. The white edge at the top is the summit itself. Bali is at the left, and below it Java. At the right are Lombok and Sumbawa. South is in the middle, so west should be on the right: the picture is a mirror image, and the drawing step below reverses it.
Part
Meaning
+proj=ob_tran +o_proj=longlat
longitude and latitude, but on a globe that has been rotated
+o_lat_p=-8.3407 +lon_0=-64.502
the new pole is at the latitude of Agung, and at its longitude (115.498) minus 180
+o_lon_p=180
south is in the middle of the picture
-te -180 87.3 180 90
all directions, and 2.7 degrees of distance from the pole, which is 300 km
Each column is now a line of sight. It starts at the top, on the summit, and the distance grows downwards. No other preparation is needed.
Go down one column, and give each cell its angle: how far above or below the horizontal direction it appears. Keep the highest angle so far. If the next cell lies higher than that, it is visible, and the visible part is exactly the strip between the two angles. If not, it is hidden. “The highest so far” is a window function:
gdal raster as-features both.tif cells.gpkg --output-layer cell --geometry-type none --include-row-col--overwriteogr2ogr-overwrite view.gpkg cells.gpkg -dialect SQLite -sql"select case when h<=0 then 10+min(39,cast(km/6 as integer)) else 50+12*min(14,max(0,cast(sqrt(km)-1.5 as integer)))+min(11,max(0,cast((light-90)/13 as integer))) end v, buildmbr(2400-col, coalesce(hide,-90), 2399-col, a) geom from (select *, max(a) over (partition by col order by row rows between unbounded preceding and 1 preceding) hide from (select col, row, band_1 h, band_2 light, (row+0.5)*0.3002 km, degrees(atan((band_1-2999-0.0673*(row+0.5)*(row+0.5)*0.0901)/((row+0.5)*300.2))) a from cell)) where a>-12 and (a>hide or hide is null)"-nln view -nlt POLYGON
Part
Meaning
band_1-2999
the height of the cell, compared with the eyes of the observer
0.0673*...*0.0901
0.0673*km*km: how many metres lower the land appears at this distance because of the curve of the Earth, with the bending of light. At 100 km, it is 673 m
max(a) over (partition by col order by row ...)
the highest angle before this cell, in the same direction
buildmbr(...)
a box, one direction wide, and as high as the visible strip
v
the colour: 40 steps of blue for the sea; for the land, 15 steps of haze with 12 steps of light
Draw the boxes, with the direction to the right and the angle upwards:
Look before moving on. North is at both ends, and south is in the middle. Rinjani on Lombok stands high above the horizon, and behind it, pale, is Sumbawa. Nusa Penida is there with its two small neighbours. The south of Bali ends in a narrow strip of land. On the right is the crater of Batur, seen from above.
Nothing here is drawn by hand, and no 3D program was used. The picture needs one gdalwarp and one query.
The picture has 360 degrees in its width and only 12 in its height, so all mountains look nine times too steep. A smaller part, to the west, is less distorted. Only the numbers for the window and the size change:
The pointed peak at the left is Batukaru, 45 km away, and the group beside it stands around the lakes of Bedugul. Behind them, on the other side of the strait, is Java: Raung, and to the right of it the Merapi of Ijen. The small pale peak to the left of Raung is Semeru. It is also the last golden spot in the map of section 2.
Is it right? The map came from viewshed, and this picture from a window function. These are two ways to the same answer, so we compared them. Within 200 km, they agree for 99 % of the sea and for 95 % of the land (ledger L127). A full agreement is hardly possible, because the two work with cells of different shapes.
5. Shadows in the morning
A place with a free line to the sun is in the light. If something is in the way, the place is in the shadow. So a map of shadows is a map of visibility, with the sun as the observer.
On 21 June 2026, at nine minutes to seven in the morning, the sun stands 4 degrees above the horizon of Agung, in the direction of 66 degrees, between north-east and east (ledger L125). Its real distance is too large for a map. But 10,000 km in this direction are far enough to make its rays nearly parallel:
x,y,height
9470054,13145086,699268
Warning 1: NOTE: The observer location falls outside of the DEM area
The warning of GDAL is correct: the observer is outside of the map. Here this is intended. --curvature-coefficient 0 makes the Earth flat, because the height of the sun was already calculated for this place.
Look before moving on. The shadow of Agung is a triangle with a sharp end. This end lies 36 km from the summit, beyond the middle of the island. A quarter of an hour later, the sun is higher, and the shadow is already much shorter.
Two thirds of this dark land do not face away from the sun (ledger L127). They are dark because a mountain stands in front of them, up to 36 km away. hillshade does not calculate this. It only compares neighbouring cells, as Chapter 11 shows.
6. Places that are visible from most others
Until now, there was one observer. Now put observers everywhere, and count. --mode cumulative puts an observer on every tenth cell in both directions, and adds up all their views:
Look before moving on. This map contains no light and no height. A bright place is visible from many other places. The side of Agung that faces south-west is visible from a large part of the island. The crater of Batur is visible from very few places, except for the top of the young volcano in its middle, which is higher than the crater wall.
Which points are visible from most others? Take the best cell of each block of 20 km, and then the best four blocks:
gdal raster as-features crowd_land.tif crowd.gpkg --output-layer crowd --geometry-type none --include-xy--overwriteogr2ogr-f CSV /vsistdout/ crowd.gpkg -dialect SQLite -sql"select max(band_1) score, center_x x, center_y y from crowd group by cast(center_x/20000 as integer), cast(center_y/20000 as integer) order by score desc limit 4"
The score is not a number of people. The place that is visible from most others gets 255, and all other numbers are relative to it. First comes the summit of Agung, and just behind it Batukaru, at the other end of the mountains. Then follow Abang, on the edge of the crater of Batur, and Patas in the west.
There is one limitation. The observers also stand on the water, and the map ends near the coast. There are no observers on Lombok. A place at the edge of the map is visible from more places than its colour shows.
7. A chain of six summits
Summits with a view of each other are useful for measurements. In the 19th century, surveyors measured the whole of Java with a net of 114 points, most of them on mountains, because each point needed a view of its neighbours. They finished it in 1880 (ledger L126).
This section uses such a net to pass on a message. It has to go from Gunung Karang in Banten, near the western end of Java, to Tambora on Sumbawa, about 1,300 km away. On each summit there is a person with a fire, who lights it when the fire before becomes visible. What is the smallest number of fires?
First the summits. The relief becomes a table of cells, and a summit is a cell of at least 1,400 m with no higher one within 32 cells, about 15 km:
gdal raster as-features relief.tif land.gpkg --output-layer cell --geometry-type none --include-row-col--overwriteogr2ogr-overwrite fires.gpkg land.gpkg -sql"select row, col, band_1 z from cell where band_1>0"-nln landogrinfo-q fires.gpkg -sql"create unique index place on land (row, col)"ogr2ogr-update-overwrite fires.gpkg summits.csv -oo AUTODETECT_TYPE=YES -nln nameogr2ogr-update-overwrite fires.gpkg fires.gpkg -sql"with top as materialized (select row, col, max(z) z, 105+(col+0.5)/240 x, -5.4-(row+0.5)/240 y from land where z>=1400 group by row/8, col/8) select row_number() over (order by col) id, (select name from name n order by pow(n.lon-x,2)+pow(n.lat-y,2) limit 1) name, z, makepoint(x,y) geom from top a where not exists (select 1 from top b where b.z>a.z and pow(b.row-a.row,2)+pow(b.col-a.col,2)<=32*32)"-nln peak -nlt POINT -a_srs EPSG:4326ogr2ogr-f CSV /vsistdout/ fires.gpkg -sql"select count(*) summits, count(distinct name) names, max(z) highest_m from peak"
summits,names,highest_m
38,38,3577
The relief has 38 summits, and summits.csv gives each one the name of the nearest mountain in a gazetteer.
Now check the view between each pair of summits. Follow the straight line between the two, in 400 steps. At each step, compare the land with the line of sight between the two summits. The smallest difference is the gap. If it is above zero, the two summits have a view of each other:
ogr2ogr-update-overwrite fires.gpkg fires.gpkg -sql"with recursive n(i) as (select 1 union all select i+1 from n where i<399), p as materialized (select a.id a, b.id b, a.z+2 h1, b.z+2 h2, st_x(a.geom) x1, st_y(a.geom) y1, st_x(b.geom) x2, st_y(b.geom) y2, 111.195*sqrt(pow(st_y(b.geom)-st_y(a.geom),2)+pow((st_x(b.geom)-st_x(a.geom))*cos(radians((st_y(a.geom)+st_y(b.geom))/2)),2)) km from peak a join peak b on b.id>a.id) select a, b, km, min(h1+(h2-h1)*i/400.0-0.0673*km*km*i*(400-i)/160000.0-l.z) gap, makeline(makepoint(x1,y1),makepoint(x2,y2)) geom from p join n on i*km/400 between 1.5 and km-1.5 join land l on l.row=cast((-5.4-y1-(y2-y1)*i/400.0)*240 as integer) and l.col=cast((x1+(x2-x1)*i/400.0-105)*240 as integer) where km<450 group by a, b having gap>0"-nln sight -nlt LINESTRING -a_srs EPSG:4326ogr2ogr-f CSV /vsistdout/ fires.gpkg -sql"select count(*) pairs, cast(round(avg(km)) as integer) mean_km, cast(round(max(km)) as integer) longest_km from sight"
pairs,mean_km,longest_km
189,123,408
Part
Meaning
h1+(h2-h1)*i/400
the straight line from eye to eye
0.0673*km*km*i*(400-i)/160000
how far the curve of the Earth rises towards this line, most of all in the middle. For 285 km, this is 1,367 m
between 1.5 and km-1.5
leaves out the summits themselves
join land
finds the cell at each step. Over water, it finds none. The sea is in the way of no pair, as long as the land is not
The result is a net: 38 summits and the lines between them. A chain is a path in this net, always to the east, and a recursive query tries all of them, up to six fires. If several chains are equally short, it takes the one whose longest line is the shortest:
ogr2ogr-update-overwrite fires.gpkg fires.gpkg -sql"with recursive w(id,n,leap,way) as (select id, 1, 0.0, ','||id||',' from peak where name='Karang' union all select s.b, n+1, max(leap,km), way||s.b||',' from w join sight s on s.a=w.id where n<6), best as (select way, n from w join peak p on p.id=w.id where p.name='Tambora' order by n, leap limit 1) select n, a, b, km, gap, geom from best, sight where instr(way, ','||a||','||b||',')>0 order by a"-nln chain -nlt LINESTRING -a_srs EPSG:4326ogr2ogr-f CSV /vsistdout/ fires.gpkg -sql"select p.name from_summit, q.name to_summit, cast(round(km) as integer) km, cast(round(gap) as integer) m_above_the_land from chain join peak p on p.id=a join peak q on q.id=b order by a"
Karang, Ciremai, Muria, Semeru, Agung, Tambora. Six fires are enough for a message over all of Java, Bali, Lombok and half of Sumbawa. Draw the net, and the chain in it:
gdal raster pipeline calc -i A=far.tif -i C=relief.tif --calc"(C>0) ? 2+A*0.2 : 1"--ot Byte --nodata none ! clip --bbox 105,-9.4,119,-5.4 ! resize --size 5600,1600 ! write night.tif --overwriteogr2ogr-update-overwrite fires.gpkg fires.gpkg -sql"select 60 v, st_buffer(geom,0.0024,1) geom from sight union all select 64, st_buffer(geom,0.011) from chain union all select 61, st_buffer(geom,0.006) from chain union all select 62, st_buffer(geom,0.016) from peak union all select 64, st_buffer(geom,0.085) from peak where id in (select a from chain union select b from chain) union all select 61, st_buffer(geom,0.055) from peak where id in (select a from chain union select b from chain) union all select 63, st_buffer(geom,0.03) from peak where id in (select a from chain union select b from chain)"-nln ink -nlt POLYGONgdal_rasterize-q-a v -l ink fires.gpkg night.tifgdal raster pipeline read night.tif ! color-map --color-map night.txt ! materialize ! resize --size 1680,480 -r average ! write fires.png --overwrite
Look before moving on. The golden line makes a bend to the north. Muria is the lowest of the six, less than half as high as its two neighbours, and it stands alone by the sea. This is why it is in the chain. The large volcanoes of central Java hide each other, and the lines to and from the small one at the coast pass beside them.
Is it possible? This relief is coarse, and it makes summits lower than they are. The same five lines over the finer Copernicus model, with cells of 90 m, stay more than 100 m above the land (ledger L127). So the mountains do not prevent it.
(The window of this chapter ends at 10.3 degrees south for a reason. In the first version it was larger, and from a summit in the sea south of Java, half of the island was visible. It was Christmas Island. In this file it has 1,633 m, and in the Copernicus model 366 m (ledger L123). A wrong height is hard to find on a map. In a net of lines of sight, it is easy to find.)
The air is another condition. Is it possible to see over 285 km at all? Yes, on a day with very clear air: the longest line of sight in a photograph has 493 km, from Türkiye to the Caucasus, in December 2024 (ledger L128). But such days are rare. So calculate again, with a limit for the visibility. How many fires are needed, if the visibility is limited to a given number of kilometres?
ogr2ogr-f CSV /vsistdout/ fires.gpkg -sql"with recursive e as materialized (select a, b, km from sight union all select b, a, km from sight), w(eye,id,n) as (select j.value, p.id, 1 from peak p, json_each(json_array(100,120,150,200,250,300)) j where p.name='Karang' union select eye, e.b, n+1 from w join e on e.a=w.id and e.km<=eye where n<20) select cast(eye as integer) sees_km, coalesce(cast(min(case when name='Tambora' then n end) as text),'never enough') fires from w join peak p on p.id=w.id group by eye"
With a visibility of 200 km, ten fires are enough. With 120 km, seventeen are needed. And with 100 km, no number of fires is enough: somewhere on the way, the next summit is always farther than that. Where is it? Draw the net with where km<=100, and look for the gap.
Try it yourself
Evening. On the same day, the sun goes down in the north-west, in the direction of 294 degrees. Where does the shadow of Agung fall then?
Another summit. Use Batukaru, or Rinjani. Find the highest cell first.
From the beach. Put the pole of section 4 at Sanur (115.2635, -8.6915), replace 2999 by 3, and use the angles from -0.5 to 4.
A tower. In section 2, replace the 2 m by 60 m. How much more is visible? Why so little?
Without Muria. Leave it out of the chain: write and s.b<>21 after s.a=w.id. With n<6 there is no result, because six fires are not enough any more. Raise the limit to n<8. How many are needed now?
Your own chain. From Pangrango to Agung, or from Tambora back to Karang with other mountains.
Checkpoint
The cell below stops with an error if the results are not what this chapter expects.
import csvimport iodef rows(sql, dataset="fires.gpkg"):"""The rows of a query, as dictionaries."""returnlist(csv.DictReader(io.StringIO(oneline.run(f'ogr2ogr -f CSV /vsistdout/ {dataset} -dialect SQLite -sql "{sql}"'))))# The horizon on an empty sea must be where geometry puts itr =float(rows("select sqrt(sum(st_area(geom))/3.14159265)/1000 r from round where seen=255", "round.gpkg")[0]["r"])assertabs(r -3.86*3000**0.5) <1, "the horizon is in the wrong place"withopen("share.csv") as f: share = {x["value"]: float(x["mean"]) /2.55for x in csv.DictReader(f)}assert18< share["1"] <25and44< share["2"] <54, "Agung should see about a fifth of the land and half of the sea"withopen("hidden.csv") as f: hidden = {x["name"]: float(x["mean"]) for x in csv.DictReader(f)}assert hidden["Denpasar"] <20and hidden["Singaraja"] >100, "Denpasar should see the summit, and Singaraja should not"legs = rows("select a, b, km, gap from chain order by a")assertlen(legs) ==5andall(x["b"] == y["a"] for x, y inzip(legs, legs[1:])), "the chain should have five jumps without a break"assertmin(float(x["gap"]) for x in legs) >50, "each line of sight should pass well above the land"pictures = ("seen.png", "kite.png", "turn.png", "west.png", "sun.png", "crowd.png", "fires.png")assertall((WORK / f).stat().st_size >10_000for f in pictures)print(f"checkpoint passed: horizon at {r:.1f} km; Agung sees {share['1']:.0f} % of the land on the map; {len(legs) +1} fires over {sum(float(x['km']) for x in legs):,.0f} km")print(f"time since the first cell: {time.perf_counter() - T0:.0f} s")
checkpoint passed: horizon at 211.6 km; Agung sees 23 % of the land on the map; 6 fires over 1,380 km
time since the first cell: 177 s
Troubleshooting
Symptom
Cause
Fix
Nearly everything is hidden
The observer is beside the summit, or in a crater
Find the highest cell, as in section 2
Far too much is visible
--curvature-coefficient 0
Leave it out. Only the sun of section 5 needs it
The result is wrong, and very small
The raster is in degrees, and its heights are in metres
Reproject it to metres first
Much less is visible than in reality
The relief is a surface with trees and houses, and the observer stands between them
A larger third number in --pos
The visible sea has holes
The bottom of the sea is in the relief
Set everything below 0 to 0, as in line 1 of section 2
The panorama is a mirror image
Directions run the other way round the pole
2400-col and 2399-col, not col
What comes next
Chapter 11 compared a place with its neighbours, and this chapter with places up to the horizon. Both are about space. Chapter 13: When the rain peaks compares a place with itself through the year: 36 maps of rain become one map that shows when the rain is strongest, how much it is and how long the season lasts.