#!/bin/bash
## first two lines and last line prevent whitspace problems in filenames (see: https://unix.stackexchange.com/questions/9496/looping-through-files-with-spaces-in-the-names
## then loop over all files with gpkg extension an convert to gpx format preserving the old filename!
## the script would throw an error and discard attribute fields for all fieldnames that do not match the GPX XML definition (name, cmt, etc…).
## if you dont put the GPX_USE_EXTENSION=YES paramter..
## with <-t_srs epsg:4326=""> the target CRS, to which the input coordinates will be transformed, is given..
OIFS="$IFS"
IFS=$'\n'
for f in *.gpkg
do ogr2ogr -f GPX -dsco GPX_USE_EXTENSIONS=YES -t_srs EPSG:4326 -overwrite ${f%.*}.gpx $f
done
IFS="$OIFS"
read -p "Hit [Enter] to exit..."
7 Jul 2022
GDAL: Bash Script for Converting All GPKG-Files From Directory To GPX-Format
Since lately QGIS (QGIS 3.12) comes equipped with a nice tool ("Split Vector Layers"), that will split your layers based on an attribute and ame your files accordingly. Th only drawback is, that you can not choose different output format - so you'll need to go with the only possibility, namely the GPKG-format. Now, I rather needed GPX files and had to find a way of converting the gpkg-files in batch mode. This I achieved by writing a small bash script looping over the files with GDAL's ogr2ogr command, and convert each file to GPX.
2 May 2013
Rasterize CORINE Landcover 2006 Seamless Vector Data with OGR-rasterize
Following up my latest postings (HERE & HERE) on Corine Landcover I'll share how to rasterize this data at a desired resolution with OGR rasterize:
cd D:/GIS_DataBase/CorineLC/shps_app_and_extr/
# grab extracted and appended / merged file, created previously:
myfile=extr_and_app.dbf
name=${myfile%.dbf}
# rasterize y- and x-resolution = 50 map units:
gdal_rasterize -a code_06 -tr 50 50 -l $name $myfile D:/GIS_DataBase/CorineLC/shps_app_and_extr/clc_tirol_raster_50.tif
Processing CORINE Land Cover 2006 Seamless Vector Data with OGR/GDAL's ogr2ogr and BASH
Lately I posted about using R to programmatically download all (43 zip-files) seamless 2006 vector data of CORINE Land Cover (see here). In this follow-up I share two bash-scripts with OGR/GDAL's ogr2ogr which I used to extract features by extent (Austria/Tyrol) and to combine all seperate shp-files into one by appending the dbfs. The style I used for the map is also available with german labels HERE.
##################################################
# name: extr_by_extent.sh
# Author: Kay Cichini
# Date: 30-04-2013
# Purpose: Extract shp-file features in {infolder} by input extent
# and save new shp-files to {outfolder} that is created on the fly
# Extent Tirol in EPSG:3035 - ETRS89 / ETRS-LAEA
# from D:\GIS_DataBase\GIS_Tirol\Tirol_Extent_LEAE-ETRS.shp
# xMin,yMin 4328054.73,2617730.23 : xMax,yMax 4547691.32,2739524.35
infolder=D:/GIS_DataBase/CorineLC/shps
outfolder=D:/GIS_DataBase/CorineLC/shps_extracted
ext='4328054.73 2617730.23 4547691.32 2739524.35'
ogr2ogr -overwrite $outfolder -spat $ext $infolder
##################################################
##################################################
# name: app_shps.sh
# Author: Kay Cichini
# Date: 30-04-2013
# Purpose: Append shp-files to newly created file
# working directory with shp-files to be appended into one file
mydir=D:/GIS_DataBase/CorineLC/shps_extracted
cd $mydir
# directory where final shp-file will be saved
mydir_final=D:/GIS_DataBase/CorineLC/shps_app_and_extr
mkdir $mydir_final
# get dbfs, which are the actual files to which append the data to
declare -a dbfs=(*.dbf)
# loop through dbfs in dir and append each to the dbf of
# 'extr_and_app.shp' that will be created by ogr2ogr on the fly
# and saved to {mydir_final}
for dbf in ${dbfs[@]}; do
echo appending $dbf to $mydir_final/extr_and_app.dbf
ogr2ogr -append $mydir_final/extr_and_app.dbf $dbf
done
##################################################
Subscribe to:
Posts
(
Atom
)