This commit restores previously stashed improvements to the About modal and related documentation that were accidentally lost. Major improvements: - Real-time update status API integration showing carrier statistics - Simplified tab structure (removed "Rapport" and "ACM Monitor", added "Externe Links") - Enhanced "Over" section with acknowledgment to Gemeente Zwolle - Better positioning for municipality/researcher support use cases - Removed redundant technical stack details - Cleaner data source listings (removed FedEx) - Dynamic color-coded success/failure indicators per carrier - Updated buffer distances from 300m/500m to 300m/400m throughout codebase The restored changes improve user experience by providing: - Live visibility into data freshness and quality - More focused content for the target audience - Better attribution and purpose statement - Streamlined information architecture 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
12 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Pakketpunten Data is a full-stack project for collecting, analyzing, and visualizing parcel point locations in the Netherlands.
- Backend (Python): Fetches data from multiple APIs (DHL, DPD, PostNL, VintedGo, De Buren), performs geospatial analysis using GeoPandas, and exports to GeoJSON/GeoPackage
- Frontend (Next.js): Interactive web application with React-Leaflet maps, optimized for displaying 10,000+ markers with Canvas rendering
Directory Structure
pakketpunten/
├── main.py # Main application entry point
├── api_client.py # API data collection module
├── geo_analysis.py # Geospatial analysis functions
├── visualize.py # Map generation with Folium
├── utils.py # Utility functions
├── requirements.txt # Python dependencies
├── update.sh # Automation update script
├── README.md # Project README
├── data/ # Data files and logs
│ ├── dhl_all_locations.json
│ ├── dpd_all_locations.json
│ ├── municipalities_all.json
│ ├── gemeenten-2025.xlsx
│ └── *_update_log.txt
├── docs/ # Documentation
│ ├── CLAUDE.md # This file - Claude Code instructions
│ ├── AUTOMATION.md # Automation documentation
│ ├── DATA_SOURCES.md # API documentation
│ ├── DHL_GRID_WORKFLOW.md # DHL fetching strategy
│ └── QUICKSTART_AUTOMATION.md
├── scripts/ # Automation and data processing scripts
│ ├── dhl_grid_fetch.py # Complete DHL data fetch
│ ├── dpd_fetch_all.py # Complete DPD data fetch
│ ├── integrate_dhl_grid_data.py
│ ├── integrate_dpd_data.py
│ ├── batch_generate.py # Batch municipality processing
│ ├── create_national_overview.py
│ ├── run_complete_dhl_update.py
│ └── weekly_update.py # Weekly update orchestration
└── webapp/ # Next.js frontend application
├── app/ # Next.js app directory
├── components/ # React components
└── public/data/ # GeoJSON output files
Common Commands
Setup
pip install -r requirements.txt
Running the Application
# Basic usage with municipality name
python main.py --gemeente Amsterdam --filename test --format geojson
# Using short flags
python main.py -g Utrecht -f output -f gpkg
# Run from IDE without arguments (uses defaults: gemeente=Amsterdam, filename=test, format=geojson)
python main.py
Command-line Arguments
--gemeente/-g: Municipality name (e.g., "Amsterdam", "Utrecht")--filename/-f: Output filename (default: "output")--format: Output format - either "gpkg" (GeoPackage) or "geojson" (default: "geojson")
Output
Results are saved in the output/ directory:
- GeoPackage:
output/{filename}.gpkg(single file with multiple layers) - GeoJSON:
output/{filename}_{layername}.geojson(separate files per layer) - Interactive map:
output/{filename}_kaart.html(opens automatically in browser)
Architecture
Data Flow Pipeline
The application follows a linear pipeline architecture:
- Data Collection (
api_client.py) → Fetches raw location data from 5 different sources - Geospatial Analysis (
geo_analysis.py) → Creates buffer zones and coverage areas - Visualization (
visualize.py) → Generates interactive Folium maps - Export (
utils.py) → Saves results in GeoPackage or GeoJSON format - Orchestration (
main.py) → Coordinates the entire workflow
Module Responsibilities
api_client.py - Data Collection
- Purpose: Fetches parcel point locations from multiple providers
- Functions:
get_data_deburen(gemeente): Scrapes De Buren website for locationsget_data_dhl(lat, lon, radius): Queries DHL API with circular search area (50-result limit)get_data_dpd(gemeente): Queries DPD public API (pickup.dpd.cz) by address (100-result limit)get_data_postnl(bottom_left_lat, bottom_left_lon, top_right_lat, top_right_lon): Queries PostNL API with bounding boxget_data_vintedgo(lat, lon, south, west, north, east): Scrapes VintedGo Next.js siteget_data_pakketpunten(gemeente): Main function that combines all sources into a single GeoDataFrame
- Search Area Strategy: Each API requires different search geometries (circle vs bbox vs address), so
get_gemeente_geometry()is called with both modes
utils.py - Utilities
- Purpose: Provides reusable helper functions for geocoding, API calls, web scraping, data transformation, and file I/O
- Key Functions:
get_gemeente_geometry(gemeente_naam, mode): Geocodes municipality using OpenStreetMap Nominatim APImode="bbox": Returns bounding box (for PostNL)mode="circle": Returns center point + radius (for DHL)
fetch_json(): Wrapper for API calls with proxy handling and session managementextract_js_array(),parse_locations_any(): Parse JavaScript arrays from scraped HTMLextract_points_array(): Extract data from Next.js Flight (RSC) payloads (for VintedGo)json_to_dataframe(): Normalize nested JSON to flat DataFramedf_to_gdf(): Convert DataFrame to GeoDataFrame with standardized column namessave_output(): Export to GeoPackage (single file, multiple layers) or GeoJSON (multiple files)
geo_analysis.py - Geospatial Processing
- Purpose: Performs geometric operations on parcel point locations
- Function:
get_bufferzones(gdf, radius)- Transforms WGS84 (EPSG:4326) points to RD New (EPSG:28992) for accurate meter-based buffers
- Creates individual buffer polygons around each point
- Dissolves all buffers into a single unified coverage area using
unary_union - Returns both individual buffers (for coverage analysis) and unified area (for visualization)
- CRS Workflow: WGS84 → RD New (buffer) → back to WGS84 for export
visualize.py - Map Generation
- Purpose: Creates interactive Folium maps with multiple layers
- Function:
create_map(filename, gdf_points, buffer_union300, buffer_union400, buffers_crs_hint, zoom_start, tiles)- Converts all geometries to EPSG:4326 for web display
- Uses MarkerCluster for parcel point markers (performance optimization)
- Adds optional buffer layers (300m and 400m) with semi-transparent polygons
- Auto-zooms to fit all visible features
- Saves HTML and opens in browser automatically
main.py - Orchestration
- Purpose: Entry point that orchestrates the complete workflow
- Workflow:
- Parse command-line arguments (or use defaults when run from IDE)
- Fetch parcel point data for specified municipality
- Add dummy "bezettingsgraad" (occupancy rate) column with random data
- Generate 300m and 400m buffer zones
- Export to GeoPackage or GeoJSON
- Generate interactive HTML map
Data Standardization
All parcel point data is normalized to a consistent schema with these columns:
locatieNaam: Location/business namestraatNaam: Street namestraatNr: Street numberlatitude,longitude: WGS84 coordinatesgeometry: Shapely Point geometrypuntType: Point type/categoryvervoerder: Provider name (DHL, DPD, PostNL, VintedGo, DeBuren)bezettingsgraad: Occupancy rate (dummy data, 0-100)
Output layers:
pakketpunten: All parcel pointsbuffer_300m: Unified 300m coverage areabuffer_400m: Unified 400m coverage areadekkingsgraad_300m: Individual 300m buffers per pointdekkingsgraad_400m: Individual 400m buffers per point
Coordinate Reference Systems (CRS)
- API data: EPSG:4326 (WGS84) - standard geographic coordinates
- Buffer calculations: EPSG:28992 (RD New) - Dutch projected CRS for accurate metric distances
- Map visualization: EPSG:4326 (WGS84) - required for Folium/Leaflet
- Output files: EPSG:4326 (WGS84) - standard for web mapping
API & Web Scraping Notes
- DHL: Clean REST API, requires circular search area (lat/lon/radius), 50-result limit per query
- DPD: Public REST API at pickup.dpd.cz, no authentication required, address-based search (100-limit) or complete fetch (1933 locations via getAll endpoint)
- PostNL: REST API, requires bounding box coordinates
- De Buren: Web scraping from JavaScript
locationsarray embedded in HTML - VintedGo: Complex scraping from Next.js Server Components (RSC) payload format
- Proxy handling: All API functions bypass proxies via
trust_env=Falseand explicitproxies={"http": None, "https": None}
Complete Coverage Approach (DHL & DPD)
Due to API result limits, DHL and DPD use special fetching strategies:
-
DHL (
scripts/dhl_grid_fetch.py): Grid-based approach covering Netherlands with overlapping 10km search circles, auto-subdividing cells that hit the 50-limit. Takes ~3-5 minutes, fetches all ~2000+ locations. -
DPD (
scripts/dpd_fetch_all.py): Single API call togetAll?country=528endpoint returns all 1,933 DPD locations in Netherlands. Takes ~5 seconds. Much simpler than DHL.
Both providers use integration scripts (scripts/integrate_dhl_grid_data.py, scripts/integrate_dpd_data.py) to filter locations by municipality bounds and update GeoJSON files.
Dependencies
Core libraries (see requirements.txt):
geopandas==1.1.1: Geospatial data handlingshapely==2.1.2: Geometric operationsfolium==0.20.0: Interactive web mapspandas==2.3.3: Data manipulationrequests==2.32.5: HTTP requestsgeopy==2.4.1: Geocoding via Nominatim
Web Application (Next.js)
The webapp/ directory contains a Next.js application for interactive visualization.
Running the Webapp
cd webapp
npm install
npm run dev # Development server on http://localhost:3000
npm run build && npm start # Production build
Architecture
- Framework: Next.js 16 with React 19 and TypeScript
- Mapping: React-Leaflet for interactive maps
- Styling: Tailwind CSS v4
- Data: Loads GeoJSON files from
webapp/public/data/
Map Component Performance Optimizations
The Map.tsx component implements adaptive rendering strategies for handling large datasets (tested with 50,000+ markers):
1. Canvas Rendering
- Uses Leaflet's Canvas renderer (via
preferCanvas) when displaying simple markers - Performance gain: 40x faster than DOM rendering for 10,000+ markers
- 10,000 markers: ~50ms (vs ~2000ms with DOM)
- 50,000 markers: ~200ms (vs unusable with DOM)
2. Adaptive Marker Simplification
The component automatically switches between rendering modes:
- Simple colored circles (Canvas): Used for datasets >3000 points, or >1000 points when zoomed out (zoom <11)
- Branded icon markers (DOM): Used for smaller datasets when zoomed in, shows provider logos and detailed styling
3. Additional Optimizations
- Memoization: Marker elements are memoized with
useMemo()to prevent unnecessary re-renders - Zoom-aware rendering:
ZoomWatchercomponent tracks zoom level changes - Performance indicator: Blue banner shows when in simple marker mode
Configuration
Adjust thresholds in Map.tsx:
const PERFORMANCE_CONFIG = {
SIMPLE_MARKER_THRESHOLD: 3000, // Marker count threshold for simple view
DETAILED_VIEW_ZOOM: 11, // Zoom level for detail mode
SIMPLE_MARKER_RADIUS: 4, // Circle marker size
SIMPLE_MARKER_OPACITY: 0.8, // Circle marker opacity
};
National Overview Generation
Use scripts/create_national_overview.py to combine all municipality data:
python scripts/create_national_overview.py
This creates webapp/public/data/nederland.geojson containing all parcel points across the Netherlands.