Skip to content

[WIP] Use WorldAdministrativeBoundaries #10

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

Merged
merged 5 commits into from
May 2, 2025
Merged
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: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.venv
./extracted_files
2 changes: 0 additions & 2 deletions .env.sample

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ cython_debug/
.pypirc

# Exclude custom dirs
extracted_files/
geodata/
49 changes: 13 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,23 @@
This server is a FastAPI implementation of the Geocoder as a service. It exposes couple of endpoints which return the Geojson geometry.
This server loads a file from the following source url:

> Source URL: https://files.emdat.be/data/gaul_gpkg_and_license.zip
## Getting started

## Endpoints
```bash
# Prepare data for the geocoder
cd geodata-prep
docker compose build
docker compose up

Following are the endpoints exposed:
# Run geocoder
cd ..
docker compose build
docker compose up
```

- GET /by_admin_units?admin_units=location_name
## API documentation

This GET request takes in a query parameter `admin_units` and returns the Geojson geometry polygon if available else an empty dict.

- GET /by_country_name?country_name=country_name

This GET request takes in a query parameter `country_name` and returns the Geojson geometry polygon if available else an empty dict.


## Scheduled job

Apart from the endpoint implementation, this server also runs a scheduled task that pulls the Zip file from the above source in a monthly (first day) basis.
This ensures we are using a latest file for this service.

## Setting up the environment

There are two environment variables that needs to be setup before the deployment. Check the file `.env.sample` for reference.
* **SERVICE_PORT**: The port on which this server runs
* **GPKG_DIR_BASE_PATH**: The path of the directory where the download file(above) resides.


## Local Deployment

### Build the image

$ docker compose build

### Run the container

$ docker compose up -d

### To view the logs

$ docker compose logs -f geocoding
The documentaiton is available at `/docs`

## Production Deployment

Expand Down
20 changes: 20 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import logging

from pydantic_settings import BaseSettings


class Settings(BaseSettings):
# World Administrative Boundaries
WAB_FILE_PATH: str = "./geodata-prep/geodata/wab.fgb"
WAB_DOWNLOAD_URL: str = "https://github.com/IFRCGo/geocoding-service/releases/download/v1.0.0/wab.fgb"
# EMDAT GAUL
GAUL_FILE_PATH: str = "./geodata-prep/geodata/gaul.gpkg"
GAUL_DOWNLOAD_URL: str = "https://github.com/IFRCGo/geocoding-service/releases/download/v1.0.0/gaul.gpkg"


settings = Settings()


# Setup logging
# FIXME: Use hook to setup logging
logging.basicConfig(level=logging.INFO)
12 changes: 5 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ services:
geocoding:
build: .
ports:
- "${SERVICE_PORT}:${SERVICE_PORT}"
- "${SERVICE_PORT}:8001"
volumes:
- .:/code
- data:${GPKG_DIR_BASE_PATH}
- ./geodata-prep/geodata:/geodata
environment:
GPKG_DIR_BASE_PATH: ${GPKG_DIR_BASE_PATH}
command: /bin/sh -c "uvicorn service:app --host 0.0.0.0 --port ${SERVICE_PORT} --workers 1"

volumes:
data:
WAB_FILE_PATH: /geodata/simple.wab.fgb
GAUL_FILE_PATH: /geodata/simple.gaul.gpkg
command: /bin/sh -c "uvicorn service:app --host 0.0.0.0 --port 8001 --reload --workers 1"
68 changes: 0 additions & 68 deletions download.py

This file was deleted.

Loading
Loading