Thread: Create Georeference PDF files for Avenza's PDF Maps app

  1. #1
    Join Date
    Jul 2013
    Location
    New Mexico
    Posts
    54

    Default Create Georeference PDF files for Avenza's PDF Maps app

    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.

  2. #2
    Join Date
    Apr 2008
    Location
    ON, Canada
    Posts
    2,205
    Very cool - thanks for posting.
    - 2001 Ford Expedition Eddie Bauer 5.4
    - 2001 Jeep Cherokee Sport 4.0
    - 2005 Starcraft 11RT
    - Some indeterminate race car project (between whips)
    - My other car is in pieces

  3. #3
    Join Date
    Mar 2010
    Location
    Lake Villa, IL
    Posts
    775
    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?

  4. #4
    Join Date
    Jul 2013
    Location
    New Mexico
    Posts
    54
    Quote Originally Posted by fishEH View Post
    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.

  5. #5
    Join Date
    Sep 2016
    Location
    Charlotte, NC
    Posts
    2
    Quote Originally Posted by rwingnut View Post

    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.

  6. #6
    Join Date
    Jun 2013
    Location
    AZ
    Posts
    654
    Quote Originally Posted by fishEH View Post
    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.

  7. #7
    Join Date
    Jul 2013
    Location
    New Mexico
    Posts
    54
    Quote Originally Posted by yohohohowo View Post
    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.

  8. #8
    Join Date
    Jul 2013
    Location
    New Mexico
    Posts
    54
    Quote Originally Posted by yohohohowo View Post
    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.

  9. #9
    Join Date
    Sep 2016
    Location
    Charlotte, NC
    Posts
    2

    Default 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.

  10. #10
    Join Date
    Jul 2013
    Location
    New Mexico
    Posts
    54
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •