Example how to generate a .mbtiles
file from .shp
file with Planetiler. This uses data from Swiss natural protected areas call "Aulav" which are given in the countries EPSG:2056
coordinate system.
Set up the java environment according to the Planetiler contributing guidelines.
Create AulavOverlay.java
and put the following code into it:
// Content of AulavOverlay.java
package com.onthegomap.planetiler.examples;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.Planetiler;
import com.onthegomap.planetiler.Profile;
import com.onthegomap.planetiler.config.Arguments;
import com.onthegomap.planetiler.reader.SourceFeature;
import java.nio.file.Path;
public class AulavOverlay implements Profile {
public static final String AULAV_SOURCE = "aulav";
@Override
public void processFeature(SourceFeature sourceFeature, FeatureCollector features) {
features.polygon("aulav")
.setBufferPixels(4)
.setMinZoom(6)
.setAttr("name", sourceFeature.getTag("Name"));
}
@Override
public String name() {
return "Aulav Overlay";
}
@Override
public String description() {
return "An example overlay showing Aulav";
}
@Override
public boolean isOverlay() {
return true;
}
@Override
public String attribution() {
return """
<a href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\">© OpenStreetMap contributors</a>
""".trim();
}
public static void main(String[] args) throws Exception {
run(Arguments.fromArgsOrConfigFile(args));
}
static void run(Arguments args) throws Exception {
//String area = args.getString("area", "geofabrik area to download", "monaco");
Path dataDir = Path.of("data");
Path sourcesDir = dataDir.resolve("sources");
Planetiler.create(args)
.setProfile(new AulavOverlay())
//.addOsmSource("osm", Path.of("data", "sources", area + ".osm.pbf"), "geofabrik:" + area)
.addShapefileSource("EPSG:2056", AULAV_SOURCE,
sourcesDir.resolve("aulav/AuLaV_Jagdbanngebiete_LV95/AuLaVJagdbanngebiete20171101_1.shp"),
"")
.overwriteOutput("mbtiles", Path.of("data", "Aulav.mbtiles"))
.run();
}
}
Download the planetiler jar file:
wget https://github.com/onthegomap/planetiler/releases/latest/download/planetiler.jar
Make a data folder and download the shapefile:
mkdir -p data/sources/aulav
cd data/sources/aulav
wget https://data.geo.admin.ch/ch.bafu.schutzgebiete-aulav_jagdbanngebiete/data.zip
unzip data.zip
cd ../../../
Run planetiler:
java -cp planetiler.jar AulavOverlay.java
ls data/
# Aulav.mbtiles sources tmp
Inspect the generated .mbtiles
file with:
sudo docker run --rm -it -v "$(pwd)/data":/data -p 8080:8080 maptiler/tileserver-gl -p 8080
Open a web browser and go to http://[::]:8080/data/Aulav/#8.6/46.7229/8.7673