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 / spatialite-query-gpkg.sh
Created September 1, 2021 08:59
Spatialite queries with ogrinfo on GeoPackage
#/usr/bin/env bash
ogrinfo "data/TOP10NL_45W.gpkg" -sql "select * from Terrein where Intersects(GeomFromGPB(geom), MakePoint(155357,405815))"
ogrinfo points.gpkg -sql "select * from beheer_leiding where Intersects(GeomFromGPB(geometry), MakeLine(MakePoint(80034.6,452005.1,28992), MakePoint(80034.6,453965.8,28992)))"
@arbakker
arbakker / gen-access-constraints.sh
Created August 26, 2021 13:38
Bash script to generate AccessConstraint field for OGC Service Capabilities documents based on service/dataset metadata
#!/usr/bin/env bash
set -eu
PROGRAM_NAME="$0"
if [ $# -ne 1 ]; then
echo "description: generate AccessConstraint field for OGC Service Capabilities documents based on service/dataset metadata"
echo " usage: ${PROGRAM_NAME} <metadata_identifier>"
exit 1
fi
@arbakker
arbakker / gh-editor-width.css
Created August 25, 2021 12:57
CSS snippet to show 80 character width in GitHub code editor
pre.CodeMirror-line {
background: linear-gradient(to right, transparent 80ch,#f7f6e5 80ch) content-box !important;
}
@arbakker
arbakker / minio-fun.sh
Created August 13, 2021 13:57
Bash/Zsh functions to stat and delete files on Minio older than a certain date
# Minio - remove files recursively in path (older than specific date, optional)
function mc-rm-older-than(){
local s3_conn_path="$1"
local date="$2"
local no_dry_run="$3"
if [[ $# -lt 2 ]]; then
fun_name=${FUNCNAME[0]}
if [[ -z $fun_name ]];then
fun_name=${funcstack} # for zsh
@arbakker
arbakker / gpkg-create-empty-ft-table.sh
Created June 29, 2021 10:10
Bash script to create empty feature table in GeoPackage (requires jq and sqlite3)
#!/usr/bin/env bash
# example call
# ./gpkg-empty-ft-table.sh test.gpkg test '{
# "fid":"INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL",
# "geom":"MULTIPOLYGON",
# "gml_id": "TEXT NOT NULL",
# "type": "TEXT",
# "object_id": "TEXT",
# "geometrie_id": "TEXT",
@arbakker
arbakker / serve-cap.py
Last active April 5, 2022 08:36
Python web service for mocking OGC Web Service capabilities requests
#!/usr/bin/env python3
import http.server
import os.path
import argparse
def file_path(string):
if os.path.isfile(string):
return string
else:
raise FileNotFoundError(string)
@arbakker
arbakker / scrape-wfs.sh
Last active March 11, 2022 10:49
Bash script for scraping WFS services in a responsible way
#!/usr/bin/env bash
# Bash script for scraping WFS services in a responsible way. Script divides in area of interest in list of bounding boxes, which are requested sequentially. The HTTP get request is configured to retry, using the default CURL exponential backoff algorithm.
# Only use when no bulk download (like ATOM) service is available.
set -eu
TARGET_GPKG=output.gpkg
WFS_URL="https://service.pdok.nl/prorail/spoorwegen/wfs/v1_0"
FT_NAME=spoorwegen:kilometrering
LAYER_NAME=$(cut -d":" -f2 <<<$FT_NAME)
SLEEP=1
@arbakker
arbakker / add-gml-id.sh
Created May 11, 2021 11:19
Bash/AWK script for adding gml:id atttribute to GML, so ogr2ogr can read GML (reads form stdin)
#!/usr/bin/env bash
set -eu
awk '
{
if ($0 ~ /^\s*<gwsw:beheer_leiding>$/)
{
cmd = "uuidgen"
cmd | getline uuid
print ("<gwsw:beheer_leiding gml:id=\"" uuid "\">")
@arbakker
arbakker / iso-2-dcatap.py
Created April 28, 2021 08:44
Commandline tool to convert ISO(19119 and 19139) metadata to DCAT-AP
#!/usr/bin/env python3
"""
Commandline tool to convert ISO(19119 and 19139) metadata to DCAT-AP based on https://github.com/SEMICeu/iso-19139-to-dcat-ap.
Requires: lxml
Usage: `./iso2dcat.py --help`
"""
from lxml.etree import XML, XSLT, tostring
from urllib.request import urlopen
import argparse
@arbakker
arbakker / validate_schema.py
Created April 24, 2021 08:54
Minimal CLI tool to validate XML (supplied either by file or url) against schema definition
#!/usr/bin/env python3
"""Minimal CLI tool to validate XML (supplied either by file or url) against schema definition
"""
import argparse
from urllib.request import urlopen
from lxml.etree import XMLSchema, XML
def main(xml, xsd):
schema = XMLSchema(file=xsd)