Skip to content

Instantly share code, notes, and snippets.

Created September 17, 2021 00:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ThomasG77/37d680b8e49134f16f4b4e65e5692f93 to your computer and use it in GitHub Desktop.

VRT to merge vector data


Adopte le VRT, cela changera ta vie. Exemple: les IRIS par territoire. Je veux une sortie WGS 84. Avec le VRT, je ne crée pas de fichier immédiatement


Retrieve data and uncompress


for i in $(cat<< EOF
do wget $i;


for i in *.7z;
  do 7z x $i;

Manipulate with GDAL utilities

Merge with VRT

SHAPE_ENCODING=ISO-8859-1 \ -single -o iris_ge_france_entiere_wgs84.vrt IRIS-GE_2-0__SHP_*/*/1_*/*/IRIS_GE.SHP -overwrite_ds -t_srs "EPSG:4326" -f VRT -nln iris_ge_france_entiere_wgs84

Convert to GPKG

ogr2ogr -f GPKG iris_ge_france_entiere_wgs84.gpkg iris_ge_france_entiere_wgs84.vrt -nln iris_ge_wgs84 -nlt PROMOTE_TO_MULTI

Export to PostGIS table

Set variable

export PGHOST=localhost
export PGPORT=5432
export PGDATABASE=my_database
export PGUSER=my_password
export PGPASSWORD=my_user

Create schema

psql -c "CREATE SCHEMA IF NOT EXISTS administratif"

Load to database in the "right schema"

ogr2ogr -f "PostGreSQL" \
        PG:"host="$PGHOST" port="$PGPORT" dbname="$PGDATABASE" user="$PGUSER" password="$PGPASSWORD"" \
        iris_ge_france_entiere_wgs84.vrt iris_ge_france_entiere_wgs84 \
        -lco OVERWRITE=yes \
        -lco SCHEMA=administratif \
        -lco SPATIAL_INDEX=GIST \
        -lco GEOMETRY_NAME=the_geom \
        --config PG_USE_COPY YES \
        -nlt PROMOTE_TO_MULTI \
        -nln iris_ge_wgs84 \
        -lco FID=fid \
        -a_srs "EPSG:4326"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment