How To Create Garmin Topo Maps - Part 4 - Transportation Data

Author: Dan Blomberg | Last updated April 2nd, 2016 at 02:52pm

Introduction

The 4th part of this tutorial details where to get and how to process transporation data.  This includes roads, highways, railroads, ferry routes, and a few other key landmark features (such as major powerlines).  In this tutorial's case we will be getting the most recent, free, roads data available which was released in 2007 and now updated yearly.  The data comes from the U.S. Census Bureau.

Downloading The Transportation Data

The data will come from the U.S. Census Bureau which recently released the Tiger data in shapefile format.

  1. Go to the National TIGER/Line Shapefiles page (will open in new window).
  2. Select download and then web interface.
  3. Select the most current year (if the year doesn't have the layer you need select the previous year).
  4. For select a layer type pick "All Lines" under "Features"
  5. Click Submit
  6. From the drop down menu on the right select your state.
  7. Transportation data has to be downloaded on a per county basis.  Select the first county from the drop down menu on the right and click "submit"
  8. Now select the next county and click Download.
  9. Repeat this process until you have all the counties.
  10. Extract each zip file into your transportation directory (they don't have to be in their own folders).

Combining The Transportation Data

There are three good ways to combine the data, I recommend using FWTools since it is the fastest method and you probably used for the contour data already.

FWTools

FWTools is the fastest and least time consuming way to combine the shapefiles but is slightly more advanced since you have to edit a .bat file.

  1. Install FWTools and remember its location (normally: C:\Program Files\FWTools2.1.0)
  2. Download the batch file we will need: Merge Transportation Batch File
  3. Extract the file to your transportation folder.
  4. You will need to edit it (right click on the file and click Edit)
  5. On the first line change "C:\your_map_directory\transportation" to match your directory, for example "C:\My Maps\transportation"
  6. On the second line set your location to the FWTools bin folder (the default for 2.4.7 on a 64-bit OS is already set).
  7. Save the bat file.
  8. Now double click on the bat file to combine all the contours together.
  9. Your final file is named mergededges.shp

You have now combined all the shapefiles together with FWTools. Contine to Processing The Data.

QGIS

A quick note; this may crash QGIS. In v2.12.2 I had issues with the merge crashing mid way through. If this happens just use the FWTools method above.

  1. Open QGIS and select all the county's edge files by going to Layer > Add Layer > Add Vector Layer
  2. In the lower right change All files (*) (*.*) to "ESRI Shapefiles (*.shp, *.SHP)
  3. Now select all the edge files (click the top one, hold shift and click the bottom one)
  4. Click open
  5. We will merge the shapefiles by going to Vector > Data Management Tools > Merge Shapefiles to One...
  6. Change the shapefile type to Line
  7. Set the input directory to the transportation directory
  8. For output save a file in your transportation directory and call it mergededges
  9. Click save
  10. Click OK

You have now combined all the shapefiles together with QGIS. Contine to Processing The Data.

Global Mapper

Creating the single shapefile in GlobalMapper is a little more resource intensive than using FWTools.  It could take awhile to load the files on your computer.

  1. Open Global Mapper
  2. Click File> Create New Catalog
  3. Save the catalog as transportation
  4. Click Add Directory
  5. Select your transportation direct
  6. in the fields mask put *.shp as shown below:
  7. It will load all the shapefiles, click "Ok"
  8. Now click File>Export Vector Data>Export Shapefile
  9. Check the "Export Lines" box
  10. Save the file as mergededges.shp in your main /transportation folder
  11. You can now delete all the individual edge files.

Processing The Transportation Data

As with the water data, we will process the transportation data with PostGIS.

Putting The Data In The Database

  1. Open pgadmin III (in the start menu)
  2. Double click the PostgreSQL database to connect to it. Enter the password if required.
  3. Expand databases
  4. Click on postgis to access/initialize that database.
  5. Expand postgis
  6. Expand Schemas
  7. Expand public
  8. Expand Tables
  9. Make sure that you don't currently have a mergededges table. If you do, right click it and select Delete/Drop
  10. Now go to the Plugins menu and select "PostGIS Shapefile and DBF Loader 2.2"
  11. In the Import tab click "Add File"
  12. Select the mergededges.shp file and click Open
  13. Click Import
  14. If you run into an error follow the steps shown in the log window.  I had to select options and change my type of LATIN1 for some of the files.
  15. Close the PostGIS Shapefile Import/Export manager.

Now that the data is loaded we will start processing it.

 Processing The Data With PostGIS

  1. Still in pgAdmin III right click on tables and select refresh.
  2. You should now see a new table: mergededges
  3. Click the SQL query button.
  4. Put the following query into the SQL editor box:
    ALTER TABLE mergededges ADD COLUMN MP_TYPE character varying(50);
    ALTER TABLE mergededges ALTER COLUMN MP_TYPE SET STORAGE EXTENDED;
    ALTER TABLE mergededges RENAME COLUMN fullname TO name;
    UPDATE mergededges SET MP_TYPE = '0x29' WHERE mtfcc = 'L4020'; -- Power lines
    UPDATE mergededges SET MP_TYPE = '0x0106' WHERE mtfcc = 'L4031'; -- Ski Lift/Tram (Overhead Cable)
    UPDATE mergededges SET MP_TYPE = '0x27' WHERE mtfcc = 'K2451'; -- Airport
    UPDATE mergededges SET MP_TYPE = '0x1a' WHERE mtfcc = 'L4165'; -- Ferry
    UPDATE mergededges SET MP_TYPE = '0x14' WHERE railflg='Y'; -- Railroads
    UPDATE mergededges SET MP_TYPE = '0x06' WHERE roadflg='Y'; --make them all simple roads
    UPDATE mergededges SET MP_TYPE = '0x01', "name" = concat('~[0x01]',substring("name" FROM '[0-9]+')) WHERE mtfcc='S1100'; -- Interstates (convert for shield)
    UPDATE mergededges SET MP_TYPE = '0x02' WHERE mtfcc = 'S1200'; -- Other Highways
    UPDATE mergededges SET "name" = concat('~[0x02]',substring("name" FROM '[0-9]+')) WHERE mtfcc='S1200' and "name" LIKE 'US Hwy %' and "name" NOT LIKE '%Byp%' and "name" NOT LIKE '%Bus%' and "name" NOT LIKE '%Spr%'; -- US Hwy (convert for shield)
    UPDATE mergededges SET MP_TYPE = '0x0a' WHERE mtfcc = 'S1500'; -- 4WD
    UPDATE mergededges SET MP_TYPE = '0x08' WHERE mtfcc = 'S1630'; -- Ramp
    UPDATE mergededges SET MP_TYPE = '0x07' WHERE mtfcc = 'S1730' or mtfcc='S1750' or mtfcc='S1740'; -- Alley/Private Drive
    UPDATE mergededges SET MP_TYPE = '0x16' WHERE mtfcc = 'S1710' or mtfcc='S1820' or mtfcc='S1830'; -- Trail
    DELETE FROM mergededges WHERE MP_TYPE IS NULL; --remove all non-typed features
  5. Click execute query (This could take quite a few minutes to run depending on how much data there is)
  6. Close the SQL window.

Export Shapefiles From PostGIS

  1. With pgAdmin III still open go to the Plugins menu and select "PostGIS Shapefile and DBF Loader 2.2"
  2. Click the export tab
  3. Click "Add Table"
  4. Select mergededges and click OK
  5. Click "Export"
  6. Go to the folder where your transportation data is stored and click "Open". This will overwrite the old transportation (mergededges) data and replace it with the modified data.
  7. Once the export is complete close the Loader
  8. To save space and not make a mistake later, in pgAdmin III delete each table. Right click on mergededges and click Delete/Drop.
  9. In that folder you can now delete everything that isn't the final mergededges file.

What's Next?

Next we will go over getting and processing the points of interest data.  This next lesson should be pretty easy compared to these more challenging ones.

<-- Previous - Water Data | Table Of Contents | Next - Points of Interest -->