Skip to content

Commit afd222d

Browse files
authored
WIP on initializing NE database [#108] (#110)
Replace RegionInfos, CountryInfos and NE index with NaturalEarthDb on init [#108] * NaturalEarthDb cleans up NE duplicates and is queried in-memory by Places layer * move ne zoom adjustment and null-handling into layers * Add QrankDb, but don't use it to rank POIs yet [#29]
1 parent 5401e90 commit afd222d

17 files changed

+614
-3961
lines changed

tiles/src/main/java/com/protomaps/basemap/Basemap.java

+22-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import com.onthegomap.planetiler.ForwardingProfile;
44
import com.onthegomap.planetiler.Planetiler;
55
import com.onthegomap.planetiler.config.Arguments;
6+
import com.onthegomap.planetiler.util.Downloader;
7+
import com.protomaps.basemap.feature.NaturalEarthDb;
8+
import com.protomaps.basemap.feature.QrankDb;
69
import com.protomaps.basemap.layers.Boundaries;
710
import com.protomaps.basemap.layers.Buildings;
811
import com.protomaps.basemap.layers.Earth;
@@ -21,7 +24,7 @@
2124

2225
public class Basemap extends ForwardingProfile {
2326

24-
public Basemap(Envelope earthWaterBounds) {
27+
public Basemap(Envelope earthWaterBounds, NaturalEarthDb naturalEarthDb, QrankDb qrankDb) {
2528

2629
var admin = new Boundaries();
2730
registerHandler(admin);
@@ -49,12 +52,12 @@ public Basemap(Envelope earthWaterBounds) {
4952
registerSourceHandler("osm", physicalPoint);
5053
registerSourceHandler("ne", physicalPoint::processNe);
5154

52-
var place = new Places();
55+
var place = new Places(naturalEarthDb);
5356
registerHandler(place);
5457
registerSourceHandler("osm", place);
5558
registerSourceHandler("ne", place::processNe);
5659

57-
var poi = new Pois();
60+
var poi = new Pois(qrankDb);
5861
registerHandler(poi);
5962
registerSourceHandler("osm", poi);
6063

@@ -116,20 +119,29 @@ static void run(Arguments args) throws Exception {
116119
// and a complete high-zoom tileset without having to tile earth/water outside the bbox.
117120
Envelope earthWaterBounds = args.bounds("osm-earth-water-bounds", "spatial bbox of osm earth+water");
118121

122+
Path nePath = sourcesDir.resolve("natural_earth_vector.sqlite.zip");
123+
String neUrl = "https://naciscdn.org/naturalearth/packages/natural_earth_vector.sqlite.zip";
124+
119125
String area = args.getString("area", "geofabrik area to download", "monaco");
120126

121127
var planetiler = Planetiler.create(args)
122-
.setProfile(new Basemap(earthWaterBounds))
123128
// (nvkelso 20230817) Order of operations matters here so all NE places can be added to RTree indexes
124129
// before OSM uses them for data joins
125-
.addNaturalEarthSource("ne", sourcesDir.resolve("natural_earth_vector.sqlite.zip"),
126-
"https://naciscdn.org/naturalearth/packages/natural_earth_vector.sqlite.zip")
130+
.addNaturalEarthSource("ne", nePath, neUrl)
127131
.addOsmSource("osm", Path.of("data", "sources", area + ".osm.pbf"), "geofabrik:" + area)
128-
.setOutput(Path.of(area + ".pmtiles"));
129-
planetiler.addShapefileSource("osm_water", sourcesDir.resolve("water-polygons-split-3857.zip"),
130-
"https://osmdata.openstreetmap.de/download/water-polygons-split-3857.zip")
132+
.addShapefileSource("osm_water", sourcesDir.resolve("water-polygons-split-3857.zip"),
133+
"https://osmdata.openstreetmap.de/download/water-polygons-split-3857.zip")
131134
.addShapefileSource("osm_land", sourcesDir.resolve("land-polygons-split-3857.zip"),
132-
"https://osmdata.openstreetmap.de/download/land-polygons-split-3857.zip")
135+
"https://osmdata.openstreetmap.de/download/land-polygons-split-3857.zip");
136+
137+
Downloader.create(planetiler.config(), planetiler.stats()).add("ne", neUrl, nePath)
138+
.add("qrank", "https://qrank.wmcloud.org/download/qrank.csv.gz", sourcesDir.resolve("qrank.csv.gz")).run();
139+
140+
var tmpDir = nePath.resolveSibling(nePath.getFileName() + "-unzipped");
141+
var naturalEarthDb = NaturalEarthDb.fromSqlite(nePath, tmpDir);
142+
var qrankDb = QrankDb.fromCsv(sourcesDir.resolve("qrank.csv.gz"));
143+
144+
planetiler.setProfile(new Basemap(earthWaterBounds, naturalEarthDb, qrankDb)).setOutput(Path.of(area + ".pmtiles"))
133145
.run();
134146
}
135147
}

tiles/src/main/java/com/protomaps/basemap/feature/CountryInfos.java

-315
This file was deleted.

0 commit comments

Comments
 (0)