Wednesday, April 25, 2012

Exporting Map Tiles to Google Earth

Sometimes a flat map just doesn't cut it.  You want to be able to rotate it, skew it, project it onto real-world terrain.  Google Earth is great for this, but their aerial imagery only takes you so far in the backcountry.  You need trails, contour lines, streams - and you need to be able to match what you're seeing with the paper map you'll take into the field.

The view past Half Dome into Tenaya Canyon, Yosemite.
CalTopo now solves this problem by letting you export map layers to Google Earth with only a few clicks.  Simply start the CalTopo map browser, navigate to the area you'd like to capture, and click Export to Google Earth in the left navbar.  Select the map layer you'd like, hit Export, and open the downloaded KML file.

A few things to know:

  • There is a rendering bug with Google Earth that causes transparent images to occasionally show up with black backgrounds.  This unfortunately affects the slope shading and contour layers; a solution is in the works.
  • An export is limited to the current screen, but Google Earth will seamlessly patch multiple exports together.
  • For performance reasons, resolution is limited based on the map bounds.  Zooming in on a map will get you a higher resolution export that covers a smaller area.

Death Valley, CA
Tahoe City, CA circa 1930
If you find a map that looks especially cool when loaded in Google Earth, please post it in the comments section.

Tuesday, April 10, 2012

End of an Era: Lights Out at Terraserver/MSRMaps

MSRMaps, the site formerly known as Terraserver, is shutting down at the end of the month.  It was a groundbreaking service when it first came out, and I lost many hours poring over slow-loading aerial images and topo maps on it.  In some ways I'm not surprised as even today the site could hardly be accused of being speedy, and it was clearly not Microsoft's top priority.  However its absence will still leave a large hole in the online topo field, and it seems like a good opportunity to look at the current options.

MyTopo used to be the go-to source for web-compatible topo maps, but Trimble bought them, and after 9 months of business as usual, decided it was time to take their ball and go home.  You can still include their map tiles in a web app if you (1) pay them a bundle of money or (2) can live with watermarks that take up half the image.  I'm not sure if using them in a smartphone app is even an option.  It's a shame because MyTopo's map layer had a couple things going for it:
  • Seamlessly integrated Forest Service maps.  They made some bold claims about updating maps to reflect new USFS roads and trails, but in reality it seems like they took the Primary Base Series raster maps and added in vegetation shading, which is still no easy task.
  • Canada and Alaska coverage.
  • Normalized colors across scans.  Each quad used exactly the same color for white, green, brown, etc.
ESRI makes a number of maps available via WMS and a web tile scheme, including a topo layer based on scanned USGS maps.  All their licensing information seems directed at ArcGIS end-users and not websites, but it says nothing to indicate that you can't pull it into a web map.  These maps cover Alaska but not Canada; unfortunately the image quality is lower than I'd like to see.  They only go to zoom 15 v. CalTopo's 16, and even then you can see serious artifacting that suggests the images were over-compressed.

The National Map is run by the USGS and offers up a mishmash of layers via a mishmash of access schemes.  Much like Terraserver, they have the older low-res DRG scans available through WMS.  Although the scans leave a lot to be desired, this service seems like a good Terraserver stand-in for now.

And of course there's my favorite high-res map layer, CalTopo.  The USGS has finished high-res scans for all of the continental US except MA, so it's time to take another pass and fix some of the coverage gaps I ran into in January.  If you'd like to include any the CalTopo map layers in your web site / iPhone app / whatever, send me an email and we can work out the details.

Monday, April 9, 2012

Working with US Topo Maps

The USGS has stopped updating to their traditional 7.5' paper quads, replacing them with a new product called US Topo, a reincarnation of their Digital Map - Beta product.  This seems like a never ending source of confusion (I'm looking for a US Topo map.  You mean a map of the US?  No, a US Topo.  Yeah, like one that covers the whole country?), but it is what it is.

You can still buy paper copies of the US Topo maps, so don't think of the new approach as a shift from paper to digital, but rather as a change in the way maps are produced.  The traditional paper maps were hand-built from survey data and stereoscopic imaging; any computer involvement was more along the lines of photoshop than a GIS application.  The new maps combine a number of layers, some entirely computer generated, into a single PDF.  So with the right tools, you can switch between viewing trails on a traditional white-green background and viewing them on an aerial image.

A US Topo map with all layers turned on.

Having now built out a nationwide seamless tile set based on these new PDFs, I have some comments on them.  Although these comments are mostly of the negative variety, I actually think these maps hold a lot of promise, but that they need a little refining.  So on with the issues . . .

Poor Toolchain.  You can open a US Topo map in any PDF viewer, but it's virtually impossible to turn individual layers on and off.  The USGS directs you to TerraGo's windows-only toolbar, and I sure hope TerraGo paid them a bundle of cash because not only is their toolbar a pain to work with, it comes with an onerous registration and download process.  When I made the mistake of downloading it onto a Mac, I actually had to stick the installer onto a USB drive to move it to a windows machine because my 1 free download had been used up.  I don't know who exactly is clamoring to pirate a GeoPDF plugin . . .

I use GDAL to slice individual quads into the tile pyramid used by web maps, and its GeoPDF driver has no support for toggling layer visibility off and on.  I was about to give up after a lof of web searching when I stumbled on the missing link - although referred to colloquially as layers, the various map elements are implemented as optional content according to the PDF spec.  Armed with this knowledge, I  dove into C++ code for the first time in 15 years and modified pdfdataset.cpp to deal with optional content.

Inconsistent Layers.  US Topo PDFs have a lot of layers.  They're grouped hierarchically, with some of the high level groupings described here.  Unfortunately when you get beyond the spec, all bets are off.  I was hoping to create a white-green woodland base layer in addition the imagery base layer, but it's not present on all the maps - some you can roll back to the traditional look, some you can't.  Some have glacier shading, some don't.  Even when maps have the same layers they're not always named consistently, which doesn't matter for a casual user but is a killer when automating a process across 55,000 maps.  I'd really like to see the USGS expand the list of mandatory layers included in the spec.

Odd Rendering Choices.  The USGS has some beautiful sample maps and the US Topos certainly shine in some situations, but they're practically unusable in others.  The traditional brown contour color is almost impossible to distinguish against some imagery backgrounds; I decided to omit it and use my own orange-brown lines instead.  Some streams and trails are so faint that they virtually disappear if the map gets reprojected.  The biggest annoyance, however, is the labels: the white drop shadow makes them go from huge to unreadable over the course of about 2 zoom levels; water features use a baby-blue color that is even harder to read over the drop shadow than the standard black.  Simple black lettering from the traditional topo won't show up well on aerial images, but I wish they'd found a better solution than the one they went with.

Missing Data.  This is the part that really blows me away.  Google's Hybrid map has great coverage for urban areas; I was hoping that US Topos would be a substitute for backcountry roads and trails.  Unfortunately a number of trails are flat-out missing and some forest service roads aren't properly rendered, while the urban features I care least about are well cataloged.  As an example, the timberline post office is prominently labeled on Mt Hood, but neither Cascade River Rd nor the Cascade Pass Trail can be found on the map despite being one of the most scenic short hikes in the Pacific NW.  Nearby sits this very confusing road intersection which violates 100 years of the USGS' own mapping conventions by displaying 4WD roads as single dashed lines.  The map key gives no indication of whether double-dashed roads are gentler or rougher than single-dashed ones, or how to distinguish these roads v. the hiking trails from which their symbol was co-opted.

Although these maps look really cool, I wouldn't throw away the old-school "historic" maps until the roads and trails are better updated and every PDF gets a green/white land cover layer.