dd-l1-capetown-clinics-bbox
Map (reference ← swipe → agent)
0:00
I'm about to push the `capetown_clinics.csv` export through to our case-management system and I want a quick inventory check first. Can you produce a small JSON file with the total clinic count, the overall bounding box as a bbox array, and the count per subdistrict, so I can confirm every health subdistrict is represented? Please write it to `clinic_inventory.json` with keys `count`, `bbox`, and `count_per_subdistrict`.
0:00
System info
{
"adapter": "openrouter",
"model": "google/gemma-4-26b-a4b-it",
"base_url": "https://openrouter.ai/api/v1"
}
0:07
Bash
ls -F
capetown_clinics.csv
0:19
Bash
head -n 5 capetown_clinics.csv
clinic_id,name,subdistrict,wkt_geom 1,Mokoena Western Clinic,Western,POINT(18.478309 -33.888756) 2,Ndlovu Western Clinic,Western,POINT(18.421127 -33.924929) 3,Pieterse Western Clinic,Western,POINT(18.389237 -33.976099) 4,van der Merwe Western Clinic,Western,POINT(18.47354 -33.890933)
0:34
Write
/work/solve.py
content · 38 lines · py
import pandas as pd
import json
from shapely import wkt
from shapely.geometry import MultiPoint
def solve():
# Load the CSV
df = pd.read_csv('capetown_clinics.csv')
# Parse the wkt_geom column into shapely objects
df['geometry'] = df['wkt_geom'].apply(wkt.loads)
# Total count
total_count = len(df)
# Bounding box
# Collect all points
points = [row.geometry for idx, row in df.iterrows()]
multipoint = MultiPoint(points)
bbox = list(multipoint.bounds) # [minx, miny, maxx, maxy]
# Count per subdistrict
count_per_subdistrict = df['subdistrict'].value_counts().to_dict()
# Create the dictionary for JSON
inventory = {
"count": int(total_count),
"bbox": bbox,
"count_per_subdistrict": {k: int(v) for k, v in count_per_subdistrict.items()}
}
# Write to JSON
with open('clinic_inventory.json', 'w') as f:
json.dump(inventory, f, indent=4)
if __name__ == "__main__":
solve()
Wrote /work/solve.py (986 chars).
0:46
Bash
python solve.py
(no output)
0:49
Bash
cat clinic_inventory.json
{
"count": 80,
"bbox": [
18.380309,
-34.073855,
18.819549,
-33.701317
],
"count_per_subdistrict": {
"Western": 12,
"Southern": 12,
"Tygerberg": 11,
"Northern": 10,
"Eastern": 10,
"Klipfontein": 9,
"Mitchells Plain": 8,
"Khayelitsha": 8
}
}
1:08