Export API¶
Export block data as a downloadable CSV file. Supports exporting raw data or data with calculated feasibility scores.
Export Data as CSV¶
Exports block data as a CSV file. If an intervention or custom filters are provided, feasibility scores and classifications are calculated and included as additional columns.
Request Body¶
{
"intervention": "Organic Farming",
"filters": [
{
"column": "AD",
"min_val": 20,
"max_val": 60,
"weight": 1.0
}
]
}
| Field | Type | Required | Description |
|---|---|---|---|
intervention |
string | No | Intervention name. Its default config is used only when no filters are supplied |
filters |
array | No | Custom filter criteria. Each item: column, min_val, max_val, weight |
Export Modes
- With intervention/filters: CSV includes the calculated feasibility columns (see below).
- Without intervention/filters: CSV contains raw block data only (all variables, no scores).
- If both
interventionandfiltersare provided, the suppliedfilterstake precedence — the intervention default is applied only whenfiltersis empty.
Response¶
- Content-Type:
text/csv - Content-Disposition:
attachment; filename=leaf_data.csv - Body: CSV text with a header row
The CSV includes every block-data column (e.g. BLOCK_ID, Block_name, Dist_Name, and all variable codes); only the geometry column is dropped. When feasibility is calculated, four additional columns are appended:
| Column | Type | Description |
|---|---|---|
feasibility |
number | Weighted feasibility score, 0–100 (blank/NaN when a block has no data for the criteria) |
feasibility_class |
string | Category key: very_high, high, moderate_high, moderate, low, very_low, or no_data |
feasibility_label |
string | Display label for the class: 100%, 75-100%, 50-75%, 25-50%, 1-25%, 0%, or No Data |
feasibility_color |
string | Hex color for the class (used by the map legend) |
Column name is feasibility, not feasibility_score
The numeric score column is named feasibility. The category key column feasibility_class holds lowercase keys (e.g. moderate_high) — the human-readable text lives in feasibility_label.
Error Codes¶
| Status | Meaning |
|---|---|
500 |
Server error (e.g. malformed/empty request body, or an internal failure). Returns JSON {"error": "<message>"} |
Example¶
# Export with intervention defaults
curl -X POST https://leaf-asrlm.in/api/export/csv \
-H "Content-Type: application/json" \
-d '{"intervention": "Organic Farming"}' \
-o leaf_data.csv
# Export raw data (no scores)
curl -X POST https://leaf-asrlm.in/api/export/csv \
-H "Content-Type: application/json" \
-d '{}' \
-o leaf_raw.csv
# Export with custom filters
curl -X POST https://leaf-asrlm.in/api/export/csv \
-H "Content-Type: application/json" \
-d '{
"filters": [
{"column": "AD", "min_val": 20, "max_val": 60, "weight": 1.0},
{"column": "WA", "min_val": 30, "max_val": 70, "weight": 0.8}
]
}' \
-o leaf_filtered.csv
import requests
import pandas as pd
from io import StringIO
# Download CSV with feasibility scores
response = requests.post(
"https://leaf-asrlm.in/api/export/csv",
json={"intervention": "Organic Farming"}
)
# Save to file
with open("leaf_data.csv", "wb") as f:
f.write(response.content)
# Or load directly into pandas
df = pd.read_csv(StringIO(response.text))
print(f"Rows: {len(df)}, Columns: {len(df.columns)}")
print(df[['Block_name', 'Dist_Name', 'feasibility']].head())
# Top 10 blocks by feasibility
top = df.nlargest(10, 'feasibility')
print("\nTop 10 blocks:")
print(top[['Block_name', 'Dist_Name', 'feasibility', 'feasibility_class']])
const response = await fetch('/api/export/csv', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ intervention: 'Organic Farming' })
});
// Trigger browser download
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'leaf_data.csv';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
Opening in Excel
The downloaded CSV can be opened directly in Excel, Google Sheets, or LibreOffice Calc.