How peterargueta/csv2map works
Project Type and Purpose
• This is a full-stack web application (“CSV2MAP GT”) whose goal is to let users upload CSV files containing Guatemalan department codes, preview the selected departments on an interactive map, and download corresponding geospatial files (.shp and .kml) packaged in a ZIP.
File Structure Analysis
• Top level
• main.py (FastAPI app)
• requirements.txt (Python deps)
• Departamentos/ (base shapefile assets: .shp, .dbf, etc.)
• utils/normalizar_csv.py (CSV‐to‐Geo preparation)
• Frontend (geo_guate_frontend/)
• public/Departamentos/departamentos.geojson (static GeoJSON)
• src/ (React components: MapaDepartamentos.jsx, UploadForm.jsx, App.jsx)
• Vite/Tailwind config
• Deployment/config: .npmrc, vite.config.js, postcss.config.js, etc.
README Insights
• Frontend: React + Vite + Tailwind CSS + Leaflet.js
• Backend: FastAPI + GeoPandas
• Hosting: Vercel (frontend), Render (API)
• No relational database—geospatial data served from static shapefiles or on-the-fly generation.
Main Components (to include
A. Client Browser (React SPA)
• Components: UploadForm, MapaDepartamentos
• Leaflet.js to render GeoJSON layers
B. Frontend Server (Vercel)
• Serves static React build and public assets (including base GeoJSON)
C. REST API Service (Render)
• FastAPI app (main.py) with endpoints:
• /upload accepts CSV, returns map data & ZIP download URL
• /download streams generated ZIP
D. Data Processing Layer
• utils/normalizar_csv.py normalizes CSV → GeoDataFrame
• GeoPandas reads Departamentos/*.shp and filters by codes
• Generates .shp and .kml, packages into ZIP
E. Storage/Filesystem
• Base shapefiles (Departamentos/)
• Temporary output (in-memory or temp folder for ZIP)
F. External Services
• Vercel (frontend hosting)
• Render.com (API hosting)
• Google Analytics (tracking on frontend)
Relationships & Data Flows
1) User interacts with React SPA → selects CSV file
2) SPA (browser) sends POST /upload → FastAPI
3) FastAPI calls normalizar_csv, loads shapefile, filters, writes .shp/.kml, zips
4) FastAPI returns:
• GeoJSON payload for immediate map rendering
• URL or stream to download ZIP
5) SPA displays GeoJSON via Leaflet
6) User clicks “Download” → SPA fetches ZIP from /download endpoint
7) Analytics events sent to Google Analytics
Architectural Patterns & Principles
• Clear separation of concerns: UI layer (React) vs. API/data layer (FastAPI)
• Stateless API calls; no persistent DB
• Reuse of base geospatial assets (shapefiles)
• Temporary data generation on demand
• Single-page application (SPA) communicating with RESTful endpoints