Skip to content

Instantly share code, notes, and snippets.

View arbakker's full-sized avatar

Anton Bakker arbakker

  • Kadaster
  • Apeldoorn
View GitHub Profile
@arbakker
arbakker / script.user.js
Last active March 8, 2023 16:07
Tampermonkey Script for Syntax Highlight OWS Capabilities Documents #js #tampermonkey #userscript #ogc
// ==UserScript==
// @name Syntax Highlight for PDOK OWS Capabilities Documents
// @description Adds dark theme syntax highlighting to OWS capabilities documents and adds some convenience hyperlinks
// @version 1.1.1
// @updateUrl https://gist.github.com/arbakker/f715db856ab134f2f292e3ccba339a8b/raw/script.user.js
// @supportURL https://gist.github.com/arbakker/f715db856ab134f2f292e3ccba339a8b
// @include /^https?://(service.pdok.nl|geodata.nationaalgeoregister.nl).*/(wms|wfs|wmts|wcs)(/v[0-9]+_[0-9]+)?\?.*(request=GetCapabilities)
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/languages/xml.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/languages/css.min.js
@arbakker
arbakker / script.js
Created May 31, 2022 10:16
NGR - improved xml metadata view - greasemonkey userscript #greasemonkey #js #userscript #NGR #geonetwork
// ==UserScript==
// @name NGR - improved xml metadata view
// @version 1.0.4
// @grant GM.info
// @require https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js
// @match https://nationaalgeoregister.nl/geonetwork/srv/dut/catalog.search*
// @match https://ngr.acceptatie.nationaalgeoregister.nl/geonetwork/srv/dut/catalog.search*
// @run-at document-end
// ==/UserScript==
// run in your browser with https://www.tampermonkey.net/
@arbakker
arbakker / README.md
Last active May 18, 2022 11:44
Minimal self-contained docker-compose WFS example with lighttpd and pdok/mapserver docker containers #mapserver #pdok #docker-compose #minimal

README

Minimal self-contained WFS docker-compose example with lighttpd and pdok/mapserver docker containers containing all data and config required to spin up OGC WFS services.

Example exposes following accespoints:

Spin up with:

@arbakker
arbakker / script.sh
Created May 10, 2022 13:22
remap json keys with jq #jq #json
// remap json keys with following mapping table and remove null and empty string values
// {
// "name": "n",
// "title": "t",
// "abstract": "a",
// "tilematrixsets": "tms",
// "imgformats": "if",
// "dataset_md_id": "dmi",
// "service_title": "sti",
// "service_url": "su",
@arbakker
arbakker / README.md
Last active April 5, 2022 08:52
QGIS issue legendgraphic WMS not showing in layer toc with multiple styles

README

WMS legendgraphic's do not seem to show if the WMS layer has multiple styles defined in the capabilities document of the service. See the below example to reproduce the issue:

Step 1

wget https://gist.githubusercontent.com/arbakker/aeb75d887a5851df17d4598765a6141b/raw/e200b2c43fe794618de76b4e7853d231ae91729e/serve-cap.py
python3 serve-cap.py capabilities_works.xml 8000
python3 serve-cap.py capabilities_fails.xml 9000 # create WMS connection in QGIS with http://localhost:9000/
@arbakker
arbakker / trigger.sql
Created April 1, 2022 23:08
PostgreSQL trigger to add field to jsonb on insert #postgres #postgis #jsonb #json
drop function if exists add_puuid_fuuid_fields;
CREATE FUNCTION add_puuid_fuuid_fields()
RETURNS trigger AS $$
BEGIN
IF NEW.json -> 'properties' ->> 'puuid' IS NULL OR NEW.json -> 'properties' ->> 'puuid' = '' THEN
NEW.json = jsonb_insert(NEW.json, '{properties,puuid}', ('"'|| (md5(random()::text || clock_timestamp()::text)::uuid) || '"' :: text)::jsonb);
NEW.json = jsonb_insert(NEW.json, '{properties,fuuid}', ('"' || 'bgtterugmeldingen.' || (new.json -> 'properties' ->> 'puuid') || '"' :: text)::jsonb);
END IF;
RETURN NEW;
@arbakker
arbakker / README.md
Last active December 15, 2021 16:23
Minimal nginx config to reverse proxy a INSPIRE Atom service #nginx #ngrok #atom

Reverse Proxy a INSPIRE Atom service with NGINX

Minimal NGINX config to reverse proxy a INSPIRE Atom service and manipulate the response body as well as response headers. Intented for debugging purposes.

Start the NGINX reverse proxy:

docker run --name mynginx1 -p 8282:80 -d -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf anroe/nginx-headers-more
@arbakker
arbakker / README.md
Last active December 1, 2021 15:12
Generate random number of centroid point for each input geometry #GPKG #sqlite #ogr2ogr #python

Generate Random Number of Centroid Points For Each Geometry

Execute the following to generate a GeoPackage with multiple centroids per input geometry:

mkdir -p data
wget https://service.pdok.nl/cbs/pc4/atom/v1_0/downloads/cbs_pc4_2020.gpkg.zip -O data/cbs_pc4_2020.gpkg.zip
unzip data/cbs_pc4_2020.gpkg.zip -d data/
ogr2ogr -f GPKG data/temp.gpkg data/cbs_pc4_2020.gpkg -sql "select ST_Centroid(geom) as geom,postcode from cbs_pc4_2020" -nln cbs_pc4_2020
./generate_random_nr_centroids.py data/temp.gpkg data/output.gpkg cbs_pc4_2020 geom postcode
@arbakker
arbakker / resolve-opensearch-atom.sh
Created November 25, 2021 08:42
Bash for resolving OpenSearch template URLS for INSPIRE Atom services
#!/usr/bin/env bash
set -euo pipefail
PROGRAM_NAME="$0"
function get-query-params() {
file="$1"
params=$(
xmlstarlet sel -T \
-N os="http://a9.com/-/spec/opensearch/1.1/" \
-t -m "//os:OpenSearchDescription/os:Query/@*" \
@arbakker
arbakker / script.sh
Last active October 21, 2021 15:56
Generate GeoJSON file with all download URLS for the AHN3 #jq #ahn #pdok #wfs #elevation #DEM #GIS
#!/usr/bin/env bash
ogr2ogr -f GeoJSON /vsistdout/ WFS:https://geodata.nationaalgeoregister.nl/ahn3/wfs ahn3:ahn3_bladindex | \
jq -c ".features[].properties |=
if(.has_data_05m_dsm == true) then
.+{url_05m_dsm: ( \"https://download.pdok.nl/rws/ahn3/v1_0/05m_dsm/R_\" + (.bladnr | ascii_upcase ) + \".ZIP\")}
else . end" | \
jq -c ".features[].properties |=
if(.has_data_05m_dtm == true) then
.+{url_05m_dtm: ( \"https://download.pdok.nl/rws/ahn3/v1_0/05m_dtm/M_\" + (.bladnr | ascii_upcase ) + \".ZIP\")}