This repository contains a suite of R tools, including a Shiny web application and command-line scripts, designed to process scanned map images (specifically .tif files). The primary goals are to extract geographic extents using the Google Gemini Vision API, detect map corners, and georeference the map to create interactive web visualizations.
- Shiny Web Interface (
app.R): A user-friendly web interface that uses your localopencodeCLI to read a local.tifmap and extracts the map's extent in degrees and minutes by reading its corners. - Command-Line Extractor (
cli.R): A CLI alternative to the Shiny app for headless extraction of map extents viaopencode. - Georeferencing (
georeference.R): Uses Ground Control Points (GCPs) to attach spatial references to the scanned map, warps it to Web Mercator projection, and generates an interactive Leaflet map (georeferenced_map.html). - Corner Detection & Image Processing: Various R scripts (e.g.,
find_corners.R,crop_corners.R,analyze_corners.R) aimed at isolating map frames, finding crosshairs, and determining pixel coordinates for georeferencing.
- R (>= 4.0 recommended)
- GDAL: Required for geospatial transformations.
- ImageMagick: Required for image manipulation (
magickpackage).
Install the required R packages before running the scripts:
install.packages(c(
"shiny", "magick", "bslib",
"sf", "terra", "leaflet", "leafem", "raster", "htmlwidgets"
))To use the extent extraction features (app.R and cli.R), you need the opencode CLI installed and configured on your system. These scripts invoke opencode run to process the map image.
Ensure you have a .tif file (e.g., 6840s_100_r8_f-50-2-m.tif) in the working directory before running the extraction tools.
Run the Shiny app to use the graphical interface:
Rscript -e "shiny::runApp('app.R')"Once the app is running in your browser, click Analyze Map.
To use the CLI, simply run the script:
Rscript cli.RIf you have predetermined Ground Control Points (as configured in the script), you can georeference the image and generate an interactive Leaflet map:
Rscript georeference.RThis will produce a georeferenced_map.html file that you can open in any web browser to view the map overlaid on standard map tiles.