9 Sept 2022

QGIS REGEX Expression to Find Last Vaue of an XML/Html Image Source of the Description Field of a KML File

regexp_substr(description, 'img src="!?.*img src="(.*)"') = '',
regexp_substr(description, 'img src="(.*)"'), 
regexp_substr(description, 'img src="!?.*img src="(.*)"') 

7 Jul 2022

GDAL: Bash Script for Converting All GPKG-Files From Directory To GPX-Format

Sinve lately QGIS (I use QGIS 3.12) comes equipped with a nice tool ("Split Vector Layers"), that will split your layers based on an attribute an name your files accordingly. THe only drawback is, that you can not choose different output formats, but need to go with the one and only GPKG-format. Now, I needed GPX in my case and had to find a way of converting the gpkg-files in batch mode. This a achieved by writing a small bash script looping over the files with GDAL's ogr2ogr command, and convert each file to GPX.

#!/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 will throw an error and discard attribute fields for all fieldnames that do not match the GPX XML definition (name, cmt, etc…). #with <-t_srs epsg:4326=""> the target CRS, to which the input coordinates need to be transformed, is given.. OIFS="$IFS" IFS=$'\n' for f in *.gpkg do ogr2ogr -t_srs EPSG:4326 -overwrite ${f%.*}.gpx $f done IFS="$OIFS" read -p "Hit [Enter] to exit..."

9 Jun 2022

QGIS 3: Symbology with Geometry Generator - Draw One Convex Hull For All Features With Same Attribute

I have a layer name "Trails" with an attribute "Trail ID", which contains uniquie, consecutive Feature/Trail IDs, and an attribute "Schwierigkeit" (trail difficulty). For all features with the value "black" for the attribute "Schwierigkeit" I want to render one convex hull. The below code will select the last element in of all the features in the layer and apply the code for drawing the polygon only once. The first
in the code will create an array of all features (series generated from 1 to feature count number), over this array, the second array_foreach() will apply the geometry finction on each element which meets the condition of the
function. The
function finally puts all those single geometries within the resulting array into one multiline geometry, for which I then draw the hull.

if($id = maximum($id),
generate_series(1,  layer_property( 'trails', 'feature_count'), 1),
get_feature('trails', 'Trail ID', @element)
array_filter(@my_arr, attribute(@element, 'Schwierigkeit')='black') , geometry(@element)))))