Skip to content

Instantly share code, notes, and snippets.

@timlinux
Last active June 18, 2022 00:50
Show Gist options
  • Save timlinux/adb4d0b443d9f0294ec940f6bae26490 to your computer and use it in GitHub Desktop.
Save timlinux/adb4d0b443d9f0294ec940f6bae26490 to your computer and use it in GitHub Desktop.
QGIS Metabase Base Map - Do Not Delete
# Overview
This is a basemap for Metabase to be used on https://analytics.qgis.org.
It shows the QGIS project view of national borders of the world.
Based on world countries layer from Natural Earth.
Herewisth the provenance notes as stored in https://github.com/qgis/QGIS/tree/master/resources/data
# README World Map GeoPackage
The `world_map.gpkg` contains the following layers:
- countries
These layers were processed from source data. The purpose of this readme is to explain briefly the data sources and the processing steps.
### Data source
Natural Earth 1:10m detail level Cultural vectors: https://www.naturalearthdata.com/downloads/10m-cultural-vectors/
The specific layers used for input are:
[1]: Admin 0 – Countries v4.1.0
### Processing
The layer-specific processing steps are described below.
##### _countries_ and _states_provinces_
These two layers are derived from data source [0].
In order to keep the size small, the geometry was simplified with GRASS `v.generalize`, then dissolved
on state/province level and on country level respectively. These above steps were done with a QGIS model `world_map_generalize.model3` that is included in this folder.
For the **countries** layer, the attribute table of data source [1] was joined in manually and the country attribute fields were copied.
*Side notes to the QGIS model:*
- *Input data are in WGS84 (EPSG:4326); re-projection to a meter-based CRS was necessary
in order to set meaningful thresholds in `v.generalize`.
I chose Robinson (EPSG:54030) for that purpose. I think it is an OK
compromise for a global projected CRS in this case.*
- *The model also creates a safe extent polygon for WGS84 coordinate space
and clips the simplified layers to that extent before re-projecting them back to WGS84. This was necessary in order to avoid polygons
crossing the 180˚ meridian. Those would be rendered as large invalid polygons crossing the entire world.*
##### Manual clean-up of attribute tables (all layers)
In the GeoPackage the less meaningful fields in the attribute tables were dropped.
And finally Crimea and Sevastopol were restored to belong to the Ukraine using
```sql
update states_provinces set iso_a2='UA',sov_a3='UA',adm0_a3='UA',admin='Ukraine',gu_a3='UKR' where name IN ('Crimea','Sevastopol');
update countries set geom=st_union(geom, (select st_union(geom) from states_provinces where name IN ('Crimea','Sevastopol'))) where name='Ukraine';
update countries set geom=st_difference(geom, (select st_union(geom) from states_provinces where name IN ('Crimea','Sevastopol'))) where name='Russia';
```
## Additional notes
From Tim here: I removed extra columns for WB and other codes leaving only the ISO country codes.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment