Skip to content

About

Databricks OGC Services: WMS and WFS for Unity Catalog on Databricks Apps. Any GIS tool (QGIS, ArcGIS Pro, GDAL) connects directly with a Databricks OAuth sign-in; data is read as the signed-in user.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WMS Server on Databricks Apps

A Web Map Service (WMS) 1.3.0 server hosted on Databricks Apps, serving Cloud Optimized GeoTIFFs (COGs) stored in Unity Catalog Volumes.

Release Notes

Release Status Description
1.0 βœ… Current Local proxy architecture for OAuth bridging
2.0 πŸ”œ Planned Direct QGIS-to-Databricks OAuth (no proxy)

Architecture (Release 1.0)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  QGIS   β”‚ ──── β”‚ Local Proxy β”‚ ──── β”‚ Databricks App   β”‚ ──── β”‚ COGs in UC      β”‚
β”‚ ArcGIS  β”‚ HTTP β”‚ (localhost) β”‚ OAuthβ”‚ (WMS Server)     β”‚ API  β”‚ Volumes         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚                  β”‚                      β”‚                        β”‚
     β”‚    WMS Requests  β”‚   + OAuth Token      β”‚   Files API            β”‚
     β”‚    (GetMap, etc) β”‚   Injection          β”‚   with Bearer Token    β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Why This Architecture? (Release 1.0)

The Challenge

Databricks Apps enforces OAuth authentication at the gateway level for all external requests. This means:

  1. Direct PAT authentication won't work - Requests with PAT tokens get redirected to OAuth login
  2. OAuth tokens are required - The Databricks Apps gateway validates OAuth before requests reach the app
  3. Complex OAuth flow - Databricks OAuth requires specific configuration for external clients

Release 1.0 Solution: Local Proxy

For the initial release, a local proxy bridges the gap between QGIS and Databricks OAuth:

  1. User logs into Databricks via browser β†’ gets OAuth token
  2. Local proxy stores the token in memory
  3. QGIS connects to local proxy (no auth needed)
  4. Proxy injects OAuth token and forwards to Databricks App
  5. Databricks App uses token to access COGs in UC Volumes (On-Behalf-Of)

Benefits

  • βœ… Secure: OAuth tokens are short-lived and validated by Databricks
  • βœ… Per-user permissions: UC Volume access controlled by user's permissions
  • βœ… No stored credentials: No PATs in config files
  • βœ… Standard WMS: GIS clients work with standard WMS protocol
  • βœ… Audit trail: Databricks logs show who accessed what

Limitations (Release 1.0)

  • ❌ Requires local proxy: Each user needs to run the proxy on their machine
  • ❌ Token expiration: OAuth tokens expire (~1 hour), requiring refresh
  • ❌ Not fully automated: Users must manually copy token from browser
  • ❌ Large files: Very large COGs (700MB+) may timeout for full-extent requests

Release 2.0 Roadmap: Direct OAuth

QGIS supports OAuth authentication. The next release will enable direct QGIS-to-Databricks connection:

Planned improvements:

  • πŸ”œ Configure QGIS OAuth to authenticate directly with Databricks
  • πŸ”œ Eliminate the need for local proxy
  • πŸ”œ Automatic token refresh within QGIS
  • πŸ”œ Simplified user experience

Files

File Description
app.py FastAPI WMS server (runs on Databricks Apps)
app.yaml Databricks App deployment configuration
local_proxy.py Local proxy for QGIS OAuth bridging
layers.json Layer configuration (auto-managed via admin UI)
requirements.txt Python dependencies

Databricks App Configuration

1. Create the App

databricks apps create wms-server

2. Deploy the Code

databricks apps deploy wms-server --source-code-path /path/to/this/repo

3. Configure App Settings

In Databricks Workspace β†’ Apps β†’ Your App β†’ Settings:

User Authorization (Required)

  • Enable User Authorization
  • This enables OAuth at the gateway level

App Service Principal Scopes (Required)

Add scope: files.files

  • This allows the app to access UC Volumes on behalf of users

4. Verify Deployment

Check app status:

databricks apps get wms-server

View logs:

databricks apps logs wms-server

Running the Local Proxy

1. Install Dependencies

pip install fastapi uvicorn requests

2. Start the Proxy

python local_proxy.py

The proxy will:

  • Start on http://localhost:8080
  • Open a browser for token setup
  • Show status at the home page

3. Set Your OAuth Token

  1. Visit http://localhost:8080 in your browser
  2. Click the link to open Databricks App admin page
  3. Open browser DevTools (F12 or Cmd+Option+I)
  4. Go to Network tab β†’ Refresh the page
  5. Click any request β†’ Headers β†’ find x-forwarded-access-token
  6. Copy the full token value
  7. Paste into the proxy web UI β†’ Click "Set Token"

4. Token Refresh

OAuth tokens expire after ~1 hour. To refresh:

  1. Clear browser cookies for Databricks
  2. Visit the admin page again (re-login)
  3. Copy new token from DevTools
  4. Update in proxy UI

Connecting QGIS

1. Prerequisites

  • Local proxy running on http://localhost:8080
  • OAuth token set in proxy

2. Add WMS Connection

  1. Layer β†’ Add Layer β†’ Add WMS/WMTS Layer
  2. Click New to create connection:
    • Name: Databricks WMS
    • URL: http://localhost:8080/wms
    • Authentication: None (proxy handles it)
  3. Expand Options:
    • Tile size: 256 (recommended for large layers)
  4. Click OK

3. Add Layers

  1. Click Connect
  2. Select your layer(s)
  3. Click Add

4. Tips for Large Layers

  • Zoom in first before adding large layers
  • Set Tile size to 256 for better performance
  • Use scale-dependent visibility to prevent full-extent requests
  • Large COGs should have overviews/pyramids for best performance

Admin UI

The WMS server includes a web-based admin UI for managing layers:

  1. Start local proxy
  2. Visit http://localhost:8080/admin
  3. Add layers by specifying UC Volume paths
  4. Changes are saved to layers.json

API Endpoints

Endpoint Description
GET /wms WMS endpoint (GetCapabilities, GetMap)
GET /admin Layer management UI
GET /admin/layers List layers (JSON)
POST /admin/layers Add a layer
POST /admin/layers/{name}/delete Delete a layer
GET /layer-extent/{name} Get layer bounds
GET /health Health check
GET /debug Debug info

Layer Configuration

Layers can be configured via:

  1. Admin UI (recommended) - http://localhost:8080/admin
  2. layers.json file - manually edit

Layer Schema

{
  "name": "my_layer",
  "title": "My GeoTIFF Layer",
  "path": "/Volumes/catalog/schema/volume/file.tif",
  "crs": "EPSG:4326",
  "bbox": [-180, -90, 180, 90],
  "supported_crs": ["EPSG:4326", "EPSG:3857"],
  "bands": [1, 2, 3]
}
  • crs and bbox are auto-detected if not specified
  • supported_crs defaults to native CRS + EPSG:4326 + EPSG:3857
  • bands defaults to [1,2,3] for RGB or [1] for single-band

Supported Features

WMS 1.3.0

  • βœ… GetCapabilities
  • βœ… GetMap
  • ❌ GetFeatureInfo (not implemented)

Image Formats

  • βœ… PNG (with transparency)
  • βœ… JPEG

Coordinate Reference Systems

  • βœ… EPSG:4326 (WGS84)
  • βœ… EPSG:3857 (Web Mercator)
  • βœ… CRS:84 (WGS84 lon/lat order)
  • βœ… Native CRS of each layer
  • βœ… On-the-fly reprojection

Data Formats

  • βœ… Cloud Optimized GeoTIFFs (COGs)
  • βœ… Regular GeoTIFFs
  • βœ… Multi-band imagery
  • βœ… Single-band rasters

Performance Considerations

For Large COGs (100MB+)

  1. Use COGs with overviews:

    gdaladdo -r average input.tif 2 4 8 16 32
  2. Request smaller areas - Avoid full-extent requests

  3. Use tile size 256 in QGIS connection settings

  4. Zoom in before adding large layers

Server Optimizations

  • Automatic overview level selection for zoomed-out views
  • GDAL HTTP caching enabled
  • HTTP/2 multiplexing for parallel requests

Troubleshooting

"OAuth redirect" when using curl directly

This is expected. Databricks Apps requires OAuth - use the local proxy.

Token expired

Refresh your OAuth token (see "Token Refresh" section).

Large layer times out

  • Zoom into a smaller area
  • Set tile size to 256 in QGIS
  • Ensure COG has overviews

Black rectangle in QGIS

The server applies contrast stretching (2nd-98th percentile). If data still appears black:

  • Check the layer's value range
  • Try different bands

QGIS shows white/blank

  • Check proxy logs for actual tile requests
  • Ensure project CRS matches layer CRS
  • Try "Zoom to Layer Extent"

License

MIT License

About

Databricks OGC Services: WMS and WFS for Unity Catalog on Databricks Apps. Any GIS tool (QGIS, ArcGIS Pro, GDAL) connects directly with a Databricks OAuth sign-in; data is read as the signed-in user.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages