{"id":238,"date":"2011-09-12T15:58:34","date_gmt":"2011-09-12T20:58:34","guid":{"rendered":"http:\/\/areciv.com\/blog\/?p=238"},"modified":"2021-09-22T17:40:51","modified_gmt":"2021-09-22T22:40:51","slug":"georeferencing-trail-maps","status":"publish","type":"post","link":"https:\/\/areciv.com\/blog\/2011\/09\/georeferencing-trail-maps\/","title":{"rendered":"Georeferencing Trail Maps for PDF Maps on iOS"},"content":{"rendered":"\n<p>When I first got an iPhone, one of the first app ideas I had was one that would let me take a trail map image, mark a few known coordinates, then use the GPS to display the blue dot like in the built-in Maps app.<\/p>\n\n\n\n<p>I've searched for something similar a few times, and had actually started doing some research into libraries for doing the math. This weekend, I thought I'd search one more time, and there was actually a free app recently posted called <a href=\"http:\/\/avenza.com\/pdf-maps\">PDF Maps<\/a> by Avenza. Of course, I downloaded it immediately.<\/p>\n\n\n\n<p>Apparently, there are several standards for embedding the map projection data directly in PDF files to produce \"geospatial PDFs.\" The trail maps I wanted to use were just plain PDFs and image files, so I needed a way to add the metadata to use them with this app.<\/p>\n\n\n\n<p>After searching for a few minutes, I ran across <a href=\"http:\/\/www.gdal.org\/\">GDAL<\/a>, the Geospatial Data Abstraction Library. After reading up on the commands, it looked like it could do what I wanted, and a recent version added PDF support, however reading further, it was only to read PDFs, not to write them. Thankfully, it <em>could<\/em> output GeoTIFF format, which is the other format PDF Maps supports!<\/p>\n\n\n\n<p>After a few hours of experimentation, I finally worked out a process that made maps the app was happy with. Here is an example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nconvert -depth 8 -density 300x300 map.pdf map.png\ngdal_translate  -a_srs '+proj=utm +zone=16 +datum=NAD27' \\\n-gcp 389 1121 544000 3845000 \\\n-gcp 2158 1121 545000 3845000 \\\n-gcp 389 2886 544000 3844000 \\\n-gcp 2158 2886 545000 3844000 \\\nmap.png tmp.tiff\ngdalwarp -co COMPRESS=DEFLATE tmp.tiff map.tiff\nrm tmp.tiff\n<\/pre><\/div>\n\n\n<p>Since this map was a PDF and TIFF is a raster format, the first step is to rasterize the PDF. I used imagemagick's <em>convert<\/em> command to produce a high-quality 300 dpi PNG. (For some reason, imagemagick wanted to produce a 16-bit\/channel PNG, which looked fine. However, feeding it to the next step made the final output grayscale, so I had to force the depth to 8-bit.)<\/p>\n\n\n\n<p>Next, I figured out the X and Y coordinates of some known locations on the PNG. This particular trail map was in the UTM projection with NAD27 as the datum. It also had 1000-meter grid lines, which proved convenient for picking out a few locations. In the second command, <em>gdaltranslate<\/em> is used to specify the source projection, here in <a href=\"http:\/\/trac.osgeo.org\/proj\/\">PROJ.4<\/a> format for clarity, and to add the ground control points. As a note, the image coordinates are first, in X Y order, and the geographic coordinates come second in matching order, thus longitude comes first, followed by latitude! Or in the UTM case, easting then northing.<\/p>\n\n\n\n<p>Finally, the <em>gdalwarp<\/em> command takes the metadata applied in the previous command and performs any mapping needed to fit the image to the model. This step produces the final GeoTIFF that can then be loaded into the PDF Maps app. Be sure to delete the intermediate tmp.tiff or you may end up with inconsistent results if you are trying to tweak your map.<\/p>\n\n\n\n<p>After doing all of this, I went out for a hike to try it out. As a testament to both the high-quality trail data (<a href=\"http:\/\/www.briartech.com\/msmap.htm\">briartech<\/a> is a great resource for maps of trails around the Huntsville, AL area) and the accuracy of the gdal calculations, my true location was always within the GPS error circle every time I checked, and in many cases was directly on the trail. I took a screenshot while I stopped in one of the shelters to duck out of some light rain. You can also use the app to make distance measurements or look up coordinates of a location on the map.<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-4 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-1.png\"><img decoding=\"async\" width=\"640\" height=\"919\" data-attachment-id=\"245\" data-permalink=\"https:\/\/areciv.com\/blog\/2011\/09\/georeferencing-trail-maps\/pdfmaps-1\/\" data-orig-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-1.png\" data-orig-size=\"640,919\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"PDF Maps \u2014 In the shelter\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Screenshot of PDF Maps, showing geolocation dot exactly over shelter icon.&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-1-208x300.png\" data-large-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-1.png\" src=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-1.png\" alt=\"Screenshot of PDF Maps, showing geolocation dot exactly over shelter icon.\" data-id=\"245\" data-full-url=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-1.png\" data-link=\"https:\/\/areciv.com\/blog\/2011\/09\/georeferencing-trail-maps\/pdfmaps-1\/\" class=\"wp-image-245\" srcset=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-1.png 640w, https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-1-208x300.png 208w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-2.png\"><img decoding=\"async\" width=\"640\" height=\"880\" data-attachment-id=\"244\" data-permalink=\"https:\/\/areciv.com\/blog\/2011\/09\/georeferencing-trail-maps\/pdfmaps-2\/\" data-orig-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-2.png\" data-orig-size=\"640,880\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"PDF Maps \u2014 Map List\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Screenshot of map list in PDF Maps.&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-2-218x300.png\" data-large-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-2.png\" src=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-2.png\" alt=\"Screenshot of map list in PDF Maps.\" data-id=\"244\" data-full-url=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-2.png\" data-link=\"https:\/\/areciv.com\/blog\/2011\/09\/georeferencing-trail-maps\/pdfmaps-2\/\" class=\"wp-image-244\" srcset=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-2.png 640w, https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-2-218x300.png 218w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-3.png\"><img decoding=\"async\" width=\"640\" height=\"880\" data-attachment-id=\"243\" data-permalink=\"https:\/\/areciv.com\/blog\/2011\/09\/georeferencing-trail-maps\/pdfmaps-3\/\" data-orig-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-3.png\" data-orig-size=\"640,880\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"PDF Maps \u2014 Coordinate Lookup\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Screenshot of PDF Maps showing coordinate lookup tool.&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-3-218x300.png\" data-large-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-3.png\" src=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-3.png\" alt=\"Screenshot of PDF Maps showing coordinate lookup tool.\" data-id=\"243\" data-full-url=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-3.png\" data-link=\"https:\/\/areciv.com\/blog\/2011\/09\/georeferencing-trail-maps\/pdfmaps-3\/\" class=\"wp-image-243\" srcset=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-3.png 640w, https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-3-218x300.png 218w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-4.png\"><img decoding=\"async\" width=\"640\" height=\"880\" data-attachment-id=\"242\" data-permalink=\"https:\/\/areciv.com\/blog\/2011\/09\/georeferencing-trail-maps\/pdfmaps-4\/\" data-orig-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-4.png\" data-orig-size=\"640,880\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"PDF Maps \u2014 Measure Distance\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Screenshot of PDF Maps showing distance measurement tool.&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-4-218x300.png\" data-large-file=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-4.png\" src=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-4.png\" alt=\"Screenshot of PDF Maps showing distance measurement tool.\" data-id=\"242\" data-full-url=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-4.png\" data-link=\"https:\/\/areciv.com\/blog\/2011\/09\/georeferencing-trail-maps\/pdfmaps-4\/\" class=\"wp-image-242\" srcset=\"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-4.png 640w, https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-4-218x300.png 218w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p>While it's not the easiest process, it does produce usable maps. However, I am still looking in to a way to modify existing PDFs to add the projection information, which would leave the data in vector format and make deep zooming less pixelated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I first got an iPhone, one of the first app ideas I had was one that would let me take a trail map image, mark a few known coordinates, then use the GPS to display the blue dot like in the built-in Maps app. I've searched for something similar a few times, and had actually started doing some research into libraries for doing the math.  This weekend, I thought I'd search one more time, and there was actually a free app recently posted called PDF Maps by Avenza.<\/p>\n","protected":false},"author":1,"featured_media":245,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[88],"tags":[39,40],"class_list":["post-238","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-hack","tag-ios"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/areciv.com\/blog\/wp-content\/uploads\/2011\/09\/pdfmaps-1.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/posts\/238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/comments?post=238"}],"version-history":[{"count":11,"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/posts\/238\/revisions"}],"predecessor-version":[{"id":4391,"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/posts\/238\/revisions\/4391"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/media\/245"}],"wp:attachment":[{"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/media?parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/categories?post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/areciv.com\/blog\/wp-json\/wp\/v2\/tags?post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}