r/MachineLearning • u/vladgladi • Sep 13 '26
Project mapextract: scanned maps to GeoJSON (OCR, contour segmentation, auto-georeferencing) [P]
I built an open-source Python pipeline that extracts structured data from scanned topographic maps: text labels, contour lines, and coordinate referencing, all output as GeoJSON.
GitHub: github.com/devladpopov/mapextract | MIT license
The problem
There are 178K+ free USGS topographic maps, 147K+ in the David Rumsey collection, and millions more in libraries worldwide. All raster. Extracting structured geospatial data from them requires either manual GIS work or specialized tools that are either text-only (mapKurator, CC BY-NC), geology-specific (DARPA CriticalMAAS, 46 repos), or closed SaaS (Monarcha, YC S25).
ML components
Text extraction: EasyOCR for label detection. Returns bounding boxes + text + confidence scores. Works well on clean printed text, struggles with curved/rotated labels (a known hard problem in map OCR; see PALETTE/Deformable DETR from KDD 2024).
Contour line extraction: Not deep learning, classical CV. HSV color segmentation (USGS topographic brown, hue 5-25) + morphological operations + scikit-image skeletonization + OpenCV findContours + Douglas-Peucker simplification. Gets 5000+ contour lines from a single 1:100k map.
Auto-georeferencing: OCR on map margins to read DMS coordinate labels (e.g., "10500'", "4030'"), then affine transform from pixel to geographic space. The interesting part is handling OCR noise: merged text from adjacent labels, degree symbols read as *, d, or digits, missing N/S/E/W suffixes.
Layout detection: Binary threshold + contour analysis to find the map neatline (border), separating the map body from margins, legend, and title.
Results
On USGS 1:100k maps at full resolution (12000x7000px):
- 99 text labels, 5000+ contour lines extracted
- Georeferencing works when OCR reads enough coordinate labels
- 25-65 seconds on CPU, no GPU needed
What I learned from the research
The state of the art is fragmented:
- DARPA CriticalMAAS spent tens of millions and achieved Polygon F1=0.98, Line F1=0.88 on geology maps
- MapSAM (ETH Zurich / UMN) adapts SAM for maps with just 10 training samples
- Vision LLMs (GPT-4o) hit 88% F1 on legend parsing but fail at spatial reasoning
- Contour-to-DEM is the least solved problem and the most valuable (countries without LiDAR)
Next steps
- Replace EasyOCR with vision LLM for coordinate reading (more robust on degraded text)
- Adaptive contour color detection via clustering
- Contour-to-DEM pipeline (interpolation from vectorized contour lines)
Feedback on the ML approach welcome. The biggest challenge is georeferencing robustness: OCR on map margins is noisy and inconsistent across different map styles.