From d101e6587adad7f9c070ee8f4ddbdade94a37443 Mon Sep 17 00:00:00 2001 From: MarkCalvert <37602611+MarkCalvert@users.noreply.github.com> Date: Mon, 26 Feb 2024 17:03:08 +1300 Subject: [PATCH] [BIO-6525] Add DBCA spatial autocomplete feature (#10) * [BIO-6525] Add spatial_data directory and load spatial data for dbca plugin * Update devcontainer and .gitignore files, and add spatial_data directory with README.md --- .devcontainer/devcontainer.json | 3 +-- .gitignore | 6 ++++- ckan/docker-entrypoint.d/02_setup_dbca.sh | 5 ++++ docker-compose.dev.yml | 1 + spatial_data/README.MD | 28 +++++++++++++++++++++++ 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 spatial_data/README.MD diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8e366f62..3a780382 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -36,12 +36,11 @@ ], // Set *default* container specific settings.json values on container create. "settings": { - "terminal.integrated.defaultProfile.linux": "bash", "python.defaultInterpreterPath": "python", "python.languageServer": "Pylance", "python.linting.enabled": true, "python.analysis.extraPaths": [ - "/srv/app/src" + "./app/src/ckan" ], "[python]": { "editor.defaultFormatter": "ms-python.autopep8" diff --git a/.gitignore b/.gitignore index b21eec73..7f3e9f9e 100755 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,8 @@ _solr/schema.xml _src/* local/* .env -dbca/ \ No newline at end of file + +# DBCA +src/ +dbca/ +spatial_data/*.geojson \ No newline at end of file diff --git a/ckan/docker-entrypoint.d/02_setup_dbca.sh b/ckan/docker-entrypoint.d/02_setup_dbca.sh index 7b2196dd..76166c99 100644 --- a/ckan/docker-entrypoint.d/02_setup_dbca.sh +++ b/ckan/docker-entrypoint.d/02_setup_dbca.sh @@ -39,6 +39,11 @@ if [[ $CKAN__PLUGINS == *"doi"* ]]; then ckan -c $CKAN_INI doi initdb fi +if [[ $CKAN__PLUGINS == *"dbca"* ]]; then + ckan -c $CKAN_INI db upgrade -p dbca + ckan -c $CKAN_INI dbca load_spatial_data +fi + # if [[ $CKAN__PLUGINS == *"harvest"* ]]; then # ckan -c $CKAN_INI db upgrade -p harvest # fi \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 86be507b..559e0a47 100755 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -34,6 +34,7 @@ services: - ./src:/srv/app/src_extensions - ./ckan/config:/srv/app/config - ckan_logs:/srv/app/logs + - ./spatial_data:/srv/app/spatial_data restart: unless-stopped healthcheck: test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:5000"] diff --git a/spatial_data/README.MD b/spatial_data/README.MD new file mode 100644 index 00000000..ed982eb8 --- /dev/null +++ b/spatial_data/README.MD @@ -0,0 +1,28 @@ +# Spatial Data + +This directory is used to store GeoJSON files that will be loaded from docker entrypoint file `02_setup_dbca.sh` using the CLI command `ckan -c $CKAN_INI dbca load_spatial_data` if the mapping exists in `ckanext.dbca.spatial_data_mapping`. + +## Usage + +To add a new GeoJSON file, simply place it in this directory. The container will automatically load the file if there is a corresponding mapping defined in `ckanext.dbca.spatial_data_mapping`. + +Please ensure that the GeoJSON file follows the correct format and contains valid spatial data. + +## Mapping + +The mapping between the GeoJSON files and the data fields in the CKAN database is defined in the `ckanext.dbca.spatial_data_mapping` configuration. Make sure to update the mapping accordingly if you add or modify any GeoJSON files. + +Each mapping consists of a filename, layer field, a code field, and a name field. + +The mappings are defined as a dictionary where the key is the filename of the GeoJSON file and the value is another dictionary containing the layer, code, and name fields. + +Example: +``` +{ + "ibra.geojson": {"layer": "IBRA Regions", "code":"IWA_REG_CODE_7", "name":"IWA_REG_NAME_7"}, + "ibra-sub.geojson": {"layer": "IBRA Subregions)", "code":"IWA_SUB_CODE_7", "name":"IWA_SUB_NAME_7"}, + "imcra.geojson": {"layer": "IMCRA Regions", "code": "MESO_ABBR", "name":"MESO_NAME"}, + "lga-wa.geojson": {"layer": " Local Government Areas", "code":"LGA_TYPE", "name":"LGA_LGA_NAME"}, + "tenure.geojson": {"layer": "DBCA Managed Tenure", "code":"LEG_TENURE", "name":"LEG_NAME"} +} +```