Skip to content

add psma download script #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
downloads
45 changes: 45 additions & 0 deletions scripts/psma.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
set -euo pipefail
. "$(dirname "$0")/utils.sh"

# source: https://data.gov.au/dataset/ds-dga-bdcf5b09-89bc-47ec-9281-6b8e9ee147aa/details?q=psma%20localities
PSMA_ZIP_URL='https://data.gov.au/data/dataset/bdcf5b09-89bc-47ec-9281-6b8e9ee147aa/resource/53c24b8e-4f55-4eed-a189-2fc0dcca6381/download/aug20_adminbounds_esrishapefileordbffile.zip'
PSMA_ZIP_FILENAME="${PSMA_ZIP_URL##*/}"
PSMA_ZIP_LOCAL_PATH="${DOWNLOADS_DIR}/${PSMA_ZIP_FILENAME}"

# download file
if [ -f "${PSMA_ZIP_LOCAL_PATH}" ]; then
echo "file exists, skip downloading: ${PSMA_ZIP_FILENAME}"
else
curl "${PSMA_ZIP_URL}" > "${PSMA_ZIP_LOCAL_PATH}"
fi

# decompress file
if [ -d "${DOWNLOADS_DIR}/psma" ]; then
echo "dir exists, skip extracting: ${PSMA_ZIP_FILENAME}"
else
mkdir -p "${DOWNLOADS_DIR}/psma"
unzip "${PSMA_ZIP_LOCAL_PATH}" -d "${DOWNLOADS_DIR}/psma"
fi

# skip geojson for now
exit 0

# convert to geojson
IFS=$'\n'
for SHP_PATH in $(find "${DOWNLOADS_DIR}/psma" -type f -name '*.shp');
do
PSMA_GEOJSON_GZ_FILENAME_LOCAL_PATH="${SHP_PATH%.*}.geojsonl.gz"
if [ -f "${PSMA_GEOJSON_GZ_FILENAME_LOCAL_PATH}" ]; then
echo "file exists, skip generating: ${PSMA_GEOJSON_GZ_FILENAME}"
else
ogr2ogr \
-f 'GeoJSON' \
-t_srs 'crs:84' \
'/vsistdout/' \
"${SHP_PATH}" \
| pigz --best \
> "${PSMA_GEOJSON_GZ_FILENAME_LOCAL_PATH}"
fi
done
unset IFS
21 changes: 21 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -euo pipefail

# OSX comes bundled with versions of readlink, sed, parallel etc which are not
# compatible with the linux tools. Force OSX users to install the GNU
# compatible versions (prefixed with 'g', such as 'greadlink', 'gsed' etc.).
export CMD_READLINK='readlink'
if [[ "$OSTYPE" == "darwin"* ]]; then
if [ -x "$(command -v greadlink)" ]; then
CMD_READLINK='greadlink';
else
2>&1 echo 'OSX: you must install the gnu standard tooling using:'
2>&1 echo 'brew install coreutils'
fi
fi

# resolve paths
export SCRIPTS_DIR=$( dirname $( ${CMD_READLINK} -f "${BASH_SOURCE[0]}" ) )
export DOWNLOADS_DIR="${SCRIPTS_DIR}/../downloads"
export CONCORDANCES_DIR="${SCRIPTS_DIR}/../concordances"
export DATA_DIR="${SCRIPTS_DIR}/../data"