Last active
September 30, 2021 12:27
-
-
Save arbakker/80ea1dd5a085fb9b536043a1e19e6415 to your computer and use it in GitHub Desktop.
Bash script for transforming metadata records from NGR with query-a-cat (qac) and iso19139-nl-reader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| proces_record_b64() { | |
| # convert base64 encoded record to: | |
| # {"md_identifier":"XXX","service_url":"XXX"} | |
| # records that are not of type WMS or WMTS will be converted to null | |
| base64 --decode <<<"$1" | | |
| jq -r '.md_record' | | |
| base64 --decode | # decodes the .md_record field which is also base64 encoded | |
| read-iso read | # converts iso19119 md from XML to JSON | |
| # select only md_identifier and service_url | |
| jq "if (.ogc_service_type == \"WMS\" or .ogc_service_type == \"WMTS\") then {\"md_identifier\":.md_identifier, \"service_url\": (.service_capabilities_url | split(\"?\")[0])} else null end" | |
| } | |
| get_records_b64() { | |
| # retrieves records and returns them as base64 encoded array | |
| jq -r '.[] | @base64' <<<"$( | |
| qac csw "https://www.nationaalgeoregister.nl/geonetwork/srv/dut/csw" "type='service' AND organisationName='Beheer PDOK'" --result-type full --limit 2 | |
| )" | |
| } | |
| services=$( | |
| for b64 in $(get_records_b64); do | |
| proces_record_b64 "$b64" | |
| done | grep -ve "^null$" # select only non-null values from the result of the while loop | |
| ) | |
| echo "$services" | jq -s "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment