--- license: cc-by-3.0 pretty_name: GLiM API Backend Data size_categories: - 1M GLiM API Backend banner

GLiM API Backend

A lightweight, production-ready API for global lithological data — built for AI training, geospatial analysis, and low-memory deployment.

Python GeoPandas GLiM License Render

--- ## Overview The **GLiM API Backend** serves lithological (rock type) data for any point on Earth's land surface, sourced from the [Global Lithological Map (GLiM)](https://doi.org/10.1029/2012GC004370) database (Hartmann & Moosdorf, 2012). It exposes fast point and batch lookups without requiring the ~2.7 GB raw geodatabase to be loaded in full — making it practical to run on constrained environments like Render's free tier. This is a sibling project to [**AGDFS**](https://agdfs.onrender.com) (Automated Geological Data Fetching System), following the same design philosophy: unify large, awkward-to-host geoscience datasets behind a simple API, so downstream AI training and analysis pipelines never need to touch the raw source files directly. --- ## Data Source | | | |---|---| | **Dataset** | Global Lithological Map (GLiM) Geodatabase | | **Authors** | Hartmann, J. & Moosdorf, N. (2012) | | **Citation** | Hartmann, J., Moosdorf, N. (2012). *The new global lithological map database GLiM: A representation of rock properties at the Earth surface.* Geochemistry, Geophysics, Geosystems, 13, Q12004. https://doi.org/10.1029/2012GC004370 | | **License** | CC-BY-3.0 — attribution required in any derived product | | **Raw size** | ~1.1 GB compressed / ~2.7 GB uncompressed (File Geodatabase, ~1.24M polygons) | > **Note:** Always retain the citation above wherever this API's data is used downstream — it's a condition of the CC-BY-3.0 license. --- ## Production Files Rather than serving the raw geodatabase, the pipeline splits GLiM into two purpose-built files that keep the API's memory footprint low: | File | Contents | Purpose | |---|---|---| | `glim_spatial_index.parquet` | `polygon_id`, `geometry` only | Loaded at API startup for fast spatial lookups via GeoPandas' spatial index. Stripped of attribute columns to minimize RAM. | | `glim_metadata.csv` | All lithological attributes (age, rock type, lithology class, etc.), indexed by `polygon_id` | Queried **only after** a spatial match is found — attributes are never loaded per-polygon during the spatial search itself. | This split is the core of the memory optimization: the expensive part of a lookup (spatial search) runs against a geometry-only file, and the cheap part (attribute retrieval) runs against a plain indexed table. --- ## How It Works ``` Incoming request (lat, lon) │ ▼ Spatial index query — geopandas .sindex.query(point, predicate="intersects") │ ├── Match found ──────────────► polygon_id │ └── No match (near-coast / boundary) │ ▼ Fallback: .nearest() neighbor search → closest land polygon │ ▼ polygon_id │ ▼ Attribute lookup — glim_metadata.csv indexed by polygon_id │ ▼ Response: { lithology, rock_class, age, ..., polygon_id } ``` 1. **Spatial query** — the incoming point is tested against `glim_spatial_index.parquet`'s in-memory R-tree via `sindex.query(point, predicate="intersects")`. 2. **Fallback logic** — if the point falls just offshore or on a polygon boundary and returns no direct match, a `.nearest()` neighbor search finds the closest land polygon instead of returning empty. 3. **Attribute fetch** — once a `polygon_id` is resolved, the corresponding row is pulled from `glim_metadata.csv` (or a database equivalent) and merged into the response. --- ## API Endpoints > Endpoint paths below reflect the intended workflow described above — adjust to match your actual route implementation. | Method | Path | Description | |---|---|---| | `GET` | `/lithology/point?lat={lat}&lon={lon}` | Single coordinate lookup — returns lithology attributes for the containing (or nearest) polygon. | | `POST` | `/lithology/batch` | Batch lookup — accepts a list of `{lat, lon}` points, returns results for all in one call. | | `GET` | `/health` | Service health check. | | `GET` | `/mcp` | MCP layer for agent/tool integration (if enabled, matching the AGDFS pattern). | --- ## Tech Stack - **[GeoPandas](https://geopandas.org/)** + **[Pyogrio](https://pyogrio.readthedocs.io/)** — fast geodatabase and Parquet I/O - **[Shapely](https://shapely.readthedocs.io/)** — geometric operations and point-in-polygon tests - **[PyArrow](https://arrow.apache.org/docs/python/)** — high-performance Parquet storage engine - **FastAPI** — API layer (recommended, consistent with AGDFS) --- ## Project Structure ``` glim-api-backend/ ├── data/ │ ├── glim_spatial_index.parquet # geometry + polygon_id only │ └── glim_metadata.csv # attributes indexed by polygon_id ├── app/ │ ├── main.py # FastAPI app + endpoints │ ├── lookup.py # spatial query + fallback logic │ └── config.py ├── requirements.txt └── README.md ``` --- ## Getting Started ```bash git clone https://github.com/Nora-Research-Lab/.git cd pip install -r requirements.txt uvicorn app.main:app --reload ``` --- ## Data Hosting Given the size of the production files, large data assets are hosted externally rather than committed to the repo — following the same pattern as [AGDFS's Hugging Face dataset](https://huggingface.co/datasets/Adedoyinjames/AGDFS-DATA): ``` https://huggingface.co/datasets//GLiM-DATA ``` The API downloads/caches `glim_spatial_index.parquet` and `glim_metadata.csv` from this location at startup or build time. *(Replace with your actual dataset repo once published.)* --- ## Deployment Notes Built with Render's free tier (and similarly memory-constrained hosts) in mind: - Only the stripped-down spatial index is loaded into memory — never the full 2.7 GB geodatabase. - The spatial index (`sindex`) is built **once** at startup and reused across all requests. - Attribute data stays out-of-memory-critical-path, queried lazily per match. --- ## License Code: add your preferred license here. Data: GLiM is licensed **CC-BY-3.0** — see citation above. ---

Part of the NORA Research Lab geoscience API suite.