Skip to content

sparkgeo/SAR-BC-feature-extract

 
 

Repository files navigation

BC SAR Feature Extract API

API to extract individual feature data from BC SAR data stores.

Provides an interface to count and extract features within a given bounding box, clipped to that bounding box, from a specified dataset.

Tests

Development

Assumes Python >= 3.8, virtual environment recommended. Requires:

  • Docker
  • jq
  • GDAL

Conda Virtual Environment example conda create -y --name bcsar-ext python=3.8 gdal jq && conda activate bcsar-ext

Execute scripts/local.sh to install python dependencies and configure pre-commit hooks.

Data Requirements

This project cannot be run without first satisfying its data requirements.

BC Digital Road Atlas

The BC Digital Road Atlas is required by this project, and is the source of the TRANSPORT_LINE layer. Download via FTP using the information here and unzip.

Local Features

This project assumes the developer maintains or has access to a GeoPackage containing Trails and Shelters layers, that will be made available via the API. A template (empty) GeoPackage is available here. Before making changes to this GeoPackage copy it elsewhere so that changes are not committed.

Conversion

Execute scripts/conversion.sh and follow the prompts to generate data, in the correct formats, required to run locally. This is only required once per data update and may take over an hour, depending on the development environment.

Environment

The following environment variables are mandatory:

  • creds_hash: hash of a valid username / password. Execute scripts/creds.sh --user <username> --pass <password> to generate a hash for a new user.

The following environment variables are optional:

  • out_data_dir: identifies the directory used to store generated datasets, defaults to local tmp location.

Testing

Execute scripts/test.sh

Debugging

Sample .vscode/launch.json

Execute docker compose build && docker compose up http-tile-server before attempting to debug the API in vscode as a local HTTP tile server is required. While debugging navigate to http://localhost:8123/

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "api",
            "type": "python",
            "request": "launch",
            "module": "uvicorn",
            "args": [
                "feature_extract_api.app:app",
                "--host", "0.0.0.0",
                "--port", "8123",
                "--reload"
            ],
            "env": {
                "creds_hash": "...",    # replace with hash generated by scripts/creds.sh
                "fgb_access_prefix": "${workspaceFolder}/feature_extract/data/fgb-data",
                "mvt_bucket_name": "tiles",
                "s3_endpoint": "localhost:8987"
            },
            "console": "integratedTerminal",
            "justMyCode": false
        }, {
            "name": "pytest-lib",
            "type": "python",
            "request": "launch",
            "module": "pytest",
            "console": "integratedTerminal",
            "justMyCode": false,
            "args": [
                "${workspaceFolder}/feature_extract/tests"
            ],
            "env": {
                "fgb_access_prefix": "${workspaceFolder}/feature_extract/tests/data",
                "mvt_bucket_name": "required-but-not-used"
            }
        }, {
            "name": "pytest-api",
            "type": "python",
            "request": "launch",
            "module": "pytest",
            "console": "integratedTerminal",
            "justMyCode": false,
            "args": [
                "${workspaceFolder}/feature_extract_api/tests"
            ],
            "env": {
                "fgb_access_prefix": "required-but-not-used",
                "mvt_bucket_name": "required-but-not-used"
            }
        }
    ]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 55.2%
  • JavaScript 28.9%
  • Shell 8.0%
  • TypeScript 5.7%
  • Dockerfile 1.6%
  • HTML 0.5%
  • CSS 0.1%