Skip to content

Facilities Proximity Module

Primary sources:

Overview

The facilities proximity workflow publishes a block- or tehsil-level facilities layer by clipping a pan-India facilities dataset to the administrative boundary already available for that block.

In the current backend implementation, this module is an administrative-boundary clip and publish workflow. It does not expose separate MWS-specific tasks, village-code filters, or reporting helpers.

What It Uses

Source dataset

  • GEE facilities dataset: projects/corestack-datasets/assets/datasets/pan_india_facilities

ROI dataset

  • Admin boundary asset under the block path in the MWS asset hierarchy: admin_boundary_{district}_{block}

Output surfaces

  • GEE vector asset
  • layer metadata in the database
  • GeoServer publication in workspace facilities_proximity

Processing Flow

flowchart TD
    A[POST /api/v1/generate_facilities_proximity/] --> B[generate_facilities_proximity_task]
    B --> C[ee_initialize]
    C --> D[Verify pan-India facilities dataset exists]
    D --> E[Build output asset path]
    E --> F[Load admin boundary asset]
    F --> G[Load facilities FeatureCollection]
    G --> H[filterBounds admin boundary geometry]
    H --> I{Output asset already exists?}
    I -->|No| J[export_vector_asset_to_gee]
    J --> K[check_task_status]
    I -->|Yes| L[Reuse existing asset]
    K --> M[make_asset_public]
    L --> M
    M --> N[save_layer_info_to_db]
    N --> O[sync_fc_to_geoserver]
    O --> P{GeoServer sync succeeded?}
    P -->|Yes| Q[update_layer_sync_status]
    Q --> R[Return True]
    P -->|No| S[Return False]

API Surface

Route

  • /api/v1/generate_facilities_proximity/

Request fields

Parameter Type Required by the route shape Description
state string Yes State name
district string Yes District name
block string Yes Block or tehsil name
gee_account_id integer No GEE account to initialize before export

The API handler lowercases state, district, and block, then queues generate_facilities_proximity_task.


Main Functions

generate_facilities_proximity(state, district, block, gee_account_id)

This is the core implementation.

It:

  1. initializes Earth Engine
  2. verifies that the pan-India facilities asset exists
  3. builds an output asset path under the block asset directory
  4. loads the admin boundary asset for the block
  5. filters the facilities dataset by that boundary geometry
  6. exports the filtered collection to GEE if needed
  7. makes the asset public
  8. stores layer metadata
  9. syncs the feature collection to GeoServer

generate_facilities_proximity_task(self, state, district, block, gee_account_id)

This Celery task wraps the core function with retries:

  • bind=True
  • max_retries=3
  • default_retry_delay=60

Asset Naming

GEE asset suffix

  • facilities_proximity_{district}_{block}

Database / GeoServer layer name

  • facilities_{district}_{block}

Dataset name stored in metadata

  • Facilities Proximity

GeoServer workspace

  • facilities_proximity

Why The Module Uses Admin Boundaries

This implementation clips the facilities dataset with the administrative boundary asset for the requested state, district, and block. That keeps the workflow aligned with the route shape exposed in computing/api.py and the asset path conventions already used by block-scoped outputs.


Failure Conditions To Expect

The function returns False when:

  • the pan-India facilities dataset is missing in GEE
  • the admin boundary asset for the requested block is missing
  • the GEE export task cannot be started
  • GeoServer sync does not return a successful creation response
  • an exception is raised during execution

Integration Points

computing/misc/facilities_proximity.py
├── utilities.constants
│   ├── GEE_FACILITIES_DATASET_PATH
│   └── GEE_PATHS
├── utilities.gee_utils
│   ├── ee_initialize()
│   ├── valid_gee_text()
│   ├── is_gee_asset_exists()
│   ├── get_gee_dir_path()
│   ├── get_gee_asset_path()
│   ├── export_vector_asset_to_gee()
│   ├── make_asset_public()
│   └── check_task_status()
└── computing.utils
    ├── save_layer_info_to_db()
    ├── update_layer_sync_status()
    └── sync_fc_to_geoserver()

Example Trigger

from computing.misc.facilities_proximity import generate_facilities_proximity_task

generate_facilities_proximity_task.apply_async(
    args=["odisha", "koraput", "jaypur", 1],
    queue="nrm",
)