Skip to content

Instantly share code, notes, and snippets.

@nathanielatom
Last active August 11, 2022 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanielatom/c12e4150441ea4b20d16d09618f13e73 to your computer and use it in GitHub Desktop.
Save nathanielatom/c12e4150441ea4b20d16d09618f13e73 to your computer and use it in GitHub Desktop.
Map Georeferencer Using QGIS
# Install: https://qgis.org/en/site/ (GDAL gets installed automatically)
# Follow the guide here: https://expeditionportal.com/forum/threads/create-georeference-pdf-files-for-avenzas-pdf-maps-app.137086/
# QGIS Version used: 3.10.4
# 0. The general idea is to identify the coordinates of several points on the map, whether
# landmarks or grid intersections, and use that to calculate the geographic reference metadata.
# 1. Convert map file to TIFF (.tiff) image format. Use uncompressed if given the option.
# The Mac Preview application seems better than ImageMagick at creating high quality tiff files, but any
# imaging program with reasonable resolution conversion capability should work. If you don't have one,
# Gimp should work: https://www.gimp.org/downloads/
# 2. Set the Coordinate Reference System (CRS), by clicking in the bottom right where it says "EPSG".
# Ideally for the Coordinate Reference System (CRS) use a NAD83 / UTM zone (17N for Toronto, EPSG:26917),
# and later on pick georeference points based on the UTM grid intersections at each corner of the map - if
# your map has a UTM grid that is. Otherwise use CRS WGS 84 EPSG:4326 and pick landmarks on the map and
# infer their coordinates by cross-comparing with Google Maps Lat/Long satellite imagery coordinates.
# 3. Open QGIS->Plugins->Manage and Install Plugins and enable the builtin Georeferencer GDAL plugin.
# 4. Raster->Georeferencer and Open Raster
# 5. Settings->Transformation Settings
# a. Transformation type: Polynomial 1
# b. Resampling method: Lanczos
# c. Target SRS: Project CRS (chosen in Step 2)
# d. Output raster: <desired name.tif>
# e. Compression: None
# Leave the rest blank.
# 6. Edit->Add Point, then use scroll to zoom, middle-mouse to pan, and click
# on the (ideally really zoomed in single pixel) map to add a point. Enter
# the coordinates of that point - be mindful of units, UTM is likely in metres.
# Protip: grid intersection pixels have better contrast over features like water.
# Repeat for a point near each corner of the map (at least 4 points).
# 7. File->Start Georeferencing, then View->Panels->GCP table (ensure it's checked).
# Validate your Georeferencing Coordinate Points; the Residuals should be small,
# less than a single pixel. Optionally, save the GCPs to file.
# 8. File->Generate GDAL Script and Copy to Clipboard. Paste into a text editor and
# save as a .txt file.
# 9. Execute the following line in terminal, but replace the -gcp data, CRS (EPSG#),
# and filenames with the corresponding entries that you generated:
gdal_translate -of GTiff -co "PROFILE=GeoTIFF" -gcp 599.469 312.465 446000 5.123e+06 -gcp 6741.47 154.483 485000 5.124e+06 -gcp 7371.48 5824.47 489000 5.088e+06 -gcp 442.456 5509.48 445000 5.09e+06 -gcp 284.461 5666.48 444000 5.089e+06 -gcp 6899.49 5351.47 486000 5.091e+06 "Unlostify Killarney Map (First Edition) - Trip Side - Wall Map.tiff" "custom_topo_geo.tiff"; gdalwarp -t_srs EPSG:26917 -r lanczos -order 1 -co "PROFILE=GeoTIFF" "custom_topo_geo.tiff" "custom_topo_geo_modified.tif"; gdal_translate -of PDF "custom_topo_geo_modified.tif" "Unlostify Killarney Map (First Edition) - Georeferenced.pdf" -co COMPRESS=DEFLATE -co PREDICTOR=2
@rhardy613
Copy link

rhardy613 commented Aug 10, 2022

Thanks! This example is awesome! It isn't the easiest to follow but was very helpful. Despite the description I was having trouble with how you did some of your statements for particular maps. Your example has already solved the issue for the Killarney map, which I need in a couple days. It reduces that two steps to get a working Geo Ref PDF i.e. make a .tiff with gimp and run the cmd line. Any chance you could post example command lines for French River and Massasauga?

@nathanielatom
Copy link
Author

Thanks! Sorry the documentation / instructions aren't super clear for a general audience, I wrote them for myself and didn't actually realize I made this gist public. The link at the top to an Avenza forum post also has several comments that describe the same process in QGIS to get the coordinates needed for the command line. Sorry, it takes about 45 minutes to go through the process, and I don't have bandwidth. Could you be more specific about what you tried and what trouble you had? I may be able to give tips to help get it working. It's very useful to know the process for custom maps, I once had a map with an inset where cropping and georeferencing the inset may have saved my hike since there was no trail and it was so hard to navigate in that region. I highly highly recommend using a "paper" (waterproof/tearproof) map and compass for safety/redundancy and to support your local cartographers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment