How To Create Garmin Topo Maps - Part 4 - Transportation Data
Author: Dan Blomberg | Last updated December 21st, 2008 at 02:18pm
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 in 2009. The data comes from the U.S. Census Bureau.
Some software is required and some is reccomended for downloading and processing transportation data:
- High speed internet (don't even try it with dialup)
- Modern browser (IE 6, IE 7, Firefox 2+, Safari 3+, Opera 8+, etc)
- PostGIS & PostgreSQL server (free/open source) (Install/Setup Tutorial)
- FWTools - allows for rapid shapefile combining (optional) (free/open source)
- Global Mapper - the postGIS files will be modified to work very easily in Global Mapper (free demo/expensive)
- GPSMapEdit - can also read the files which will be modified by postGIS (free demo/cheaper)
Downloading The Transportation Data
The data will come from the U.S. Census Bureau which recently released the Tiger data in shapefile format. The 2008 data is available as of December 2008.
- Go to the National TIGER/Line Shapefiles page (will open in new window).
- From the drop down menu on the right select your state.
- 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"
- Create a new folder in your /transportation folder for each county
- Click "All Lines" on the left hand side:
- Open the zip file
- Drag the contents from the zip file to the appropriate county folder in /transportation
- Repeat this for all the counties in your state.
Combining The Transportation Data
There are three ways to combine the data, I reccomend using FWTools since it is the fastest method and you probably used it for the water data.
FWTools is the fastest and least time consuming way to combine the shapefiles but is slightly more advanced. It also requires you to have FWTools installed.
- Install FWTools and remember its location (normally: C:\Program Files\FWTools2.1.0)
- Download the batch files we will need: Merge Transportation Batch File
- Extract the file to your transportation folder.
- You will need to edit it (right click on the file and click Edit)
- On the first line change "C:\your_map_directory\transportation" to match your directory, for example "C:\My Maps\transportation"
- On the second line change the C:\Program Files\FWTools2.1.0 if you are using a different version than 2.1.0 or installed it to another location.
- Save the files
- In your first county's directory take the first shape files and rename them. Take the first tl_2008_#####_edges.shp file and rename it all_lines.shp. Then rename the dbf, shx, and prj file to all_lines.dbf, all_lines.shx, all_lines.prj. Delete the .shp.xml file.
Note: If you cannot see the extensions (.dbf, .shp, .shx, etc) do not add the extension, just rename the files all_lines.
- Drag the all_lines files to your transportation directory.
Now that our basics are setup will will start combining files.
- Open a new Windows Explorer/My Computer window.
- Go to the second county folder
- Drag the .shp file onto mergetrans.bat in the transportation folder.
- Repeat this for all your counties.
- Delete all the county folders.
You have now combined all the shapefiles together with FWTools. Contine to Processing The Data.
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.
- Open Global Mapper
- Click File> Create New Catalog
- Save the catalog as transportation
- Click Add Directory
- Select your transportation direct
- in the fields mask put *.shp as shown below:
- It will load all the shapefiles, click "Ok"
- Now click File>Export Vector Data>Export Shapefile
- Check the "Export Lines" box
- Save the file as all_lines.shp in your main /transportation folder
- You can now delete all the county folders.
Although it is possible to combine the files by opening them all and then saving them as a shapefile I do not reccomend it because it will make processing the data more difficult since you have to "type" them all currently. I would use the FWTools method over GPSMapEdit. If you want to do it with GPSMapEdit just select a random type for each line (road would work well) because we will override it when we process the data.
As with the water data we will process the transportation data with PostGIS.
Putting The Data In The Database
A few assumptions are made about your PostGIS setup. We assume you have a postgis database called postgis. We assume you have a postgres username.
- Open the command prompt (Start>Run>cmd)
- Change to the postgresql bin directory normally: C:\Program Files\PostgreSQL\8.3\bin use this command: cd "C:\Program Files\PostgreSQL\8.3\bin"
- We will use the following command to convert the shapefiles to sql files:
shp2pgsql "C:\your_map_directory\transportation\all_lines.shp" all_lines > all_lines.sql
Make sure the part in blue points to your actual map directory.
- Now that we have a .sql file we need to load it into the database with this commands
psql -d postgis -h localhost -U postgres -p -f all_lines.sql
Remove the red -p if your username does not use a password.
Processing The Data With PostGIS
- With the DOS prompt that is still open and hopefully in the PostgreSQL bin folder we will execute a series of queries.
- Download the Transportation Queries.
- Extract all the file (transportation.sql) to the PostgreSQL bin folder
- In the dos prompt run the following commands for each water type:
psql -d postgis -h localhost -U postgres -p -f transportation.sql
Remove the red -p if your username does not use a password.
- This could take quite a few minutes to run depending on how much data there is (Arizona took just under 30 minutes).
Export Shapefiles From PostGIS
Your command prompt should still be open to the PostgreSQL bin folder at this time.
- Modify and execute the following command. Make sure the blue points to your transportation directory and remove the -p if your username does not require a password
pgsql2shp -f "C:\your_map_directory\transportation\transportation.shp" -u postgres -p postgis all_lines
- At this time delete all_lines.sql.
- Go to your transportation folder
- Rename the following file:
all_lines.prj --> transportation.prj
- Delete all all_lines files.
- This should leave you with: transportation.shp, transportation.dbf, transportation.prj, and transportation.shx
Final Data Preparations
The data is already prepared for use by Global Mapper. No editing of the shapefiles is needed.
- Open your transportation shapefile with GPSMapEdit
- On the screen that pops up asking you to select the "type of object" click the "From Field" tab
- Scroll until you find the "MP_TYPE" column.
- Click on the header to select the column, it should look similar to this:
- Click Next
- Click the "name" column for naming.
- Make sure the datum is NAD83 and click next.
- Click finish
- Click file> save map as
- Name it something useful (like transportation) and save the .mp file in your transportation folder.
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.