Create Georeference PDF files for Avenza's PDF Maps app

rwingnut

Observer
A friend had shown my the really cool PDF Maps Android app by Avenza. This app allows you to navigate on top of a pdf or tiff image (geoTiff, geoPdf, or georeference PDF) that has been georeferenced. It's been discussed on this forum before. A lot of maps are available in geopdf, both free and nominally priced in the Avenza store. But, I have a few maps that I have notated with trails that are not georeferenced that I'd like to use. So, I set out to learn how to georeference these files for use with PDF Maps. Keep in mind, if you value your time at more than $1/hour, it will be cheaper to just buy the map. But for those cases when the map you want isn't georeferenced, here is the workflow that I've come up with. You'll want to be familiar (or willing to become familiar) with using the command line terminal of your computer.

Tools Used:
Gimp: http://www.gimp.org/
- grapical tool for image manipulation
Imagemagick: http://www.imagemagick.org/
- command line tool for image manipulation
Qgis (Quantum GIS): http://www.qgis.org/en/site/
- tool for determining georeferencing data
GDAL (Geospatial Data Abstraction Library)
- command line tool for creating the output files, this might come with Qgis, but I installed it separately.

I've done all this on Linux, but I believe these tools are also available on Windows PC. If not, OSGeo Live, a linux virtual machine configured for doing GIS work, can be run in VirtualBox on Windows and has these tools pre-installed.

Step 1: Prepare the image.
Use Gimp or your favorite image manipulation program to rotate and crop your image. The image needs to be flattened and reduced to a tiff with 8-bit color depth. This can probably be done with your image manipulation program, but I like running the image through Imagemagick convert just to make sure its properly prepaired:

>> convert <inputfile.pdf> -depth 8 -background white -flatten file1.tiff

Replace the <...> with the file names that you are using

Step 2: Create georeference data.
Open Qgis, select Plugins -> Manage and Install Plugins... Make sure that gdal and georeference plugin are checked.
Select Raster -> Georeferencer -> Georeferencer
In the Georeferencer select File -> Open Raster and open your tiff file. It will ask what CRS or coordinate system to use. This is the coordinate system in which you will be selecting georeferencing points. If you have UTM coordinates printed on your image and you want to use those, select the appropriate zone, for me in New Mexico, that's: NAD83 (EPSG:26913) for NAD83 / UTM zone 13 N If you have lat/lng or you're going to use landmarks and lookup a lat/lng use: WGS 84 (EPSG:4326) for gps lat/lng

Now, you want to find points in this image that you can assign a coordinate to. If your image has grid lines, it's easy. If not, look for landmarks such as trail heads, or road intersections. Find these same landmarks in Google Maps or Google Earth. Mathematically, you'll need a minimum of 2 points spread both horizontally and vertically. I'd recommend at least 4 so that any imprecision in your process gets averaged out. Plus, you can run an analysis in Qgis that will give you the error in agreement (residuals) of all your points. Sort of a sanity check.

For each of these points, use the 'Add Point' tool* to select your landmark and enter the coordinates.

* One of the buttons on the top has two intersecting lines and a yellow star, that's 'Add Point'

The Qgis georeferencer is supposed to be able to create the geopdf, but I've never been able to get the files to come out right. PDF Maps just says its an incompatible file. It has to do with the specific GDAL command-line options run in the background. Instead, there's a button that will give you the command-line switches to apply the georeference data with, that I add additional switched to.

Select Settings -> Transformation Settings
- Transformation Type: Polynomial 1, 2, or 3 (I haven't experimented with this, but can effect accuracy of highly distorted maps.
- Resampling Method: Lanczos (This is supposed to be the best but takes longer to compute, I haven't noticed a difference)
- Output Raster: output file name (required by the software, but we won't use it)
- Target SRS: output coordinate system (again, required by the software, but we won't use it)

Select File -> Start Georeferencing...
This will update the table on the bottom. The residuals will tell you how much in agreement the coordinate are in. This should be 1 few pixels or less. If not, there is someting wrong with the points entered earlier.

If all looks good, select File -> Generate GDAL script. Copy this script to a text editor.

Step3: Georeference our image.
Now it's time to build the command line that will create the file that you need. To apply the coordinates, copy and paste all of the "-gcp x_pixel y_pixel x_coord y_coord" values into the <gcp> tag below and run on your command line:

>> gdal_translate -of GTiff -co "PROFILE=GeoTIFF" <gcp> file1.tiff file2.tiff

Now its time to apply all of the geolocation data, using the same EPSG number as was used during georeferencing:

>> gdalwarp -t_srs EPSG:4326 -r lanczos -co "PROFILE=GeoTIFF" file2.tiff file3.tiff

Now we convert the file to a pdf
>> gdal_translate -of file3.tiff georeferenced.pdf

Not a simple process, but once you've done it once, it's not so bad. I tried a lot of different methods trying to get Qgis to output a compatible file, but found a lot of things that didn't work. Hope this works for you.
 

fishEH

Explorer
Man I got excited when I read the title for this thread. But that was all Greek to me. :(
It'd be really nice if there was an app(like PDF Maps) that you can drop pins on a non-geocoded map, enter the coordinates for the pin(from Google or whatever), hit a button and it geocoded the map for you seems like it'd be pretty easy.
Does an app exist like that?
 

rwingnut

Observer
Man I got excited when I read the title for this thread. But that was all Greek to me. :(
It'd be really nice if there was an app(like PDF Maps) that you can drop pins on a non-geocoded map, enter the coordinates for the pin(from Google or whatever), hit a button and it geocoded the map for you seems like it'd be pretty easy.
Does an app exist like that?

In theory, that's what Quantum GIS should be able to do. I think it gets really close but I can never get the files to work in PDF Maps. But alas, it doesn't work, hence the need for all the other steps. ArcGIS is probably how all of the professional maps are done, but its pretty expensive.
 

yohohohowo

New member
Now we convert the file to a pdf
>> gdal_translate -of file3.tiff georeferenced.pdf

I couldn't get this command to work. I finally figured it out by adding PDF after -of. I think it defaults to GTiff. I used the windows version of GDAL and QGis. It took me about 45 minutes total to create a georeferenced map from a state park trail map pdf, and I have very little command prompt experience. If I can do it, anyone can. I'll find out tonight if it works on my backpacking trip.
 

1Louder

Explorer
Man I got excited when I read the title for this thread. But that was all Greek to me. :(
It'd be really nice if there was an app(like PDF Maps) that you can drop pins on a non-geocoded map, enter the coordinates for the pin(from Google or whatever), hit a button and it geocoded the map for you seems like it'd be pretty easy.
Does an app exist like that?

Look up Maptiler.com. They have software that starts at $29 but there is a free basic version to try. It is meant to convert Georeferenced PDFs to map tiles that can be used with apps like Gaia GPS. Gaia allows for custom map imports. I think the online tool to convert maps is called Georefrencer.com but go to the main site and double check. Pretty easy to use but helps to have a larger screen. You have a regular map on the left and your PDF on the right. You then click the same area on each map to set reference points. The more you have the more accurate your map will be. My first attempt put the data about 1000ft off. Usable but I would like to try again and see if I can get closer.
 

rwingnut

Observer
I couldn't get this command to work. I finally figured it out by adding PDF after -of. I think it defaults to GTiff. I used the windows version of GDAL and QGis. It took me about 45 minutes total to create a georeferenced map from a state park trail map pdf, and I have very little command prompt experience. If I can do it, anyone can. I'll find out tonight if it works on my backpacking trip.

Good catch. I think GDAL must have had an update that changed that. I think it used use try to figure out the output type from the file extension. Now you have to specify it explicitly with the -of. I tried to do a map last week with a new version GDAL and my script wasn't working. I had to add the -of too.
 

rwingnut

Observer
I couldn't get this command to work. I finally figured it out by adding PDF after -of. I think it defaults to GTiff. I used the windows version of GDAL and QGis. It took me about 45 minutes total to create a georeferenced map from a state park trail map pdf, and I have very little command prompt experience. If I can do it, anyone can. I'll find out tonight if it works on my backpacking trip.

Good catch. I think GDAL must have had an update that changed that. I think it used use try to figure out the output type from the file extension. Now you have to specify it explicitly with the -of. I tried to do a map last week with a new version GDAL and my script wasn't working. I had to add the -of too.
 

yohohohowo

New member
It worked!

I was very excited that the map worked perfectly. The NC state parks have pdfs for all of their trails, but no georeferenced maps. If I wanted to georeference all of the maps, do you think I can share them on the PDF Maps app for others to utilize? Or do I need to contact the state parks for permission? Don't know if I'd get into legal trouble. It'd be in everyone's best interest to help hikers from becoming lost.
 

rwingnut

Observer
Excellent. I'm glad it worked. I'd contact the NC state parks either through their website or a local office and see if they're interested in the maps. I think that's where they would reach the most people looking for NC maps. Plus, I try to support the local park offices as much as I can.
 

werdnaelliott

New member
rwingnut, this thread from 2016 is the reason I joined the forum. I wanted to say THANK YOU for posting EXACTLY what I needed to turn a pdf I had into a geospatial pdf for the purpose of uploading to Avenza Maps for an upcoming trip I'm going on where I expect to have no internet access in unfamiliar territory. I'm happy to report, 4 years later your instructions still work (with the "-of PDF" option added to the final gdal_translate command as others mentioned). I also appreciate you provided instructions for linux! Very little search results online step away from Windows. Love that this can be created using free tools.
Having the geospatial pdf is going to be super helpful on my trip. So thanks again. Stay healthy.
 

Fishenough

Creeper
Curious, do many people still use Avenza? What's new on converting maps? Any sharing platforms appear in the last few years?

This post helped me when it was originally posted, I have ArcGIS for work and use that. Been collecting updated resource maps for BC and the Yukon, a number are not Georeferences.

With everyone I know, different backcountry activities from rallyraid gang, hikers, and hunters, using Gaia exclusively. Only those with the logging companies still use it as far as I know. Wonder who still uses Avenza.
cc391cb792519309d9088bad7cc824d9.jpg
 

jhl99

New member
Something that is new in the last couple of years is that there are cell phone apps that can use QGIS files. I've been using QFIELD for a couple of years on my Android phone. The cellphone app can synch data with your PC based QGIS file, it maintains the same visual formatting as the PC based file and lets you add points, lines and polgons in the field to various layers ( it also shows your position and lets you make measurements).... it will also use internet served datasets (like Open Street Maps) if you have an internet connection.

Like the original poster to this thread eluded to, if you place a dollar amount on the time to learn this process, it may not be worth effort, but if you want total flexibility of combining data from multiple sources as well as extreme control of over the presentation of the data, this method will do it.

I typically include USGS 7.5 deg Tiff maps, Federal land ownership data, state ownership data, state road vector data, trail data, POI data as well as my own waypoints, notes and tracks in the files.

QFIELD, screen shots:

Normal map display:


Screenshot_1.png


Layer List Menu:

Screenshot_2.png
 

Forum statistics

Threads
185,783
Messages
2,878,193
Members
225,329
Latest member
FranklinDufresne
Top