Apache Baremaps is a toolkit and a set of infrastructure components for creating, publishing, and operating online maps. It provides a data pipeline enabling developers to build maps with different data sources with live reload capabilities. It provides other services commonly used in online maps, such as location search and IP to location.

Star Download

Import Natural Earth data into PostGIS

In this tutorial, we’ll learn how to use Baremaps to import Natural Earth data in a PostGIS database.

Notice that the following steps assume that the Apache Baremaps CLI and PostGIS are installed.

Dataset

Natural Earth is a public domain map dataset available at 1:10m, 1:50m, and 1:110 million scales.

The following workflow will download the Natural Earth data, decompress it, and finally import it in the database.

baremaps workflow execute --file examples/naturalearth/workflow.json

Working with shapefiles (Optional)

The NaturalEarth dataset is also distributed in the shapefile format. As demonstrated in the following command, shapefiles can easily be imported in postgis with ogr2ogr. Here, notice that the data is reprojected in WebMercator (EPSG:3857) to improve performance at query time.

ogr2ogr \
  -f "PostgreSQL" "PG:host=localhost user=baremaps dbname=baremaps password=baremaps" \
  "ne_10m_admin_0_countries.shp" \
  -lco GEOMETRY_NAME=geom \
  -lco FID=gid \
  -lco PRECISION=no \
  -nlt PROMOTE_TO_MULTI \
  -nln ne_10m_admin_0_countries \
  -s_srs EPSG:4326 \
  -t_srs EPSG:3857 \
  --config OGR_ENABLE_PARTIAL_REPROJECTION TRUE \
  -overwrite

Conclusion

In this tutorial, we learnt how to import Natural Earth data in PostGIS.

Now that you have inserted the data into the PostGIS database, you can use follow the Serve Vector Tiles from PostGIS example to serve your PostGIS data directly as Vector Tiles in a web application with live reload capabilities.

Improve this page