Jump to content
Sign in to follow this  
_SCAR

[TUTORIAL] A guide to importing roads from real data

Recommended Posts

Dear all,

Those of you who have tried importing roads from real data might have experienced the pain. There are multiple tutorials out there, but most of them give bits and pieces and it's hard to understand the exact workflow that needs to be followed.

 

FYI, reference is mainly from these tutorials:

 

Software that you'll need:

  • Terrain Builder
  • Global Mapper
  • QGIS
  • SAS Planet
  • Photoshop / Gimp

 

Some of these software are not free, however there are trial versions that you may consider using. Let's get started.

 

 

SETTING UP TERRAIN BUILDER & EXPORTING THE REFERENCE HEIGHT MAP

 

Fire up Terrain Builder. Click on "Mapframes > Add mapframe":

 

LN7ym9XRDI.png

 

Leave the default Zone 31N selected and click OK:

 

5zqzPokJdl.png

 

Set the name of the Mapframe, the output root folder (in your P drive), Easting to 200000 and Northing to 0:

 

g74v-E7658.png

 

Click on the "Samplers tab" and choose your map size. I've set everything to have a map size of 10,240Km:

 

kop5Rj0DEL.png

 

Click on the "Processing" tab:

 

bDJr3c8C9i.png

 

Then click on "Rebuild Terrain":

 

e2GzNKFYxL.png

 

Confirm, and you will now have an empty terrain layer in Terrain Builder. We are going to export it so that we will be able to use it as a reference, further down in the tutorial:

 

06Oi38mzSP.png

 

We're going to save it as reference-terrain.asc.

 

 

DOWNLOADING ROADS

 

There are multiple ways that you can get the roads shapefiles from Open Street Map. You can go on the https://www.openstreetmap.org/ website and export a specific area if you'd like, but we're going to download the data from http://download.geofabrik.de/

 

Head there, and select the country of your interest. In our case, we're going to need the data from Afghanistan:

 

qXPfs4okcN.png

 

Download the .shp.zip format, and unpack it somewhere on your drive.

 

 

 

SELECTING A PRECISE AREA

 

Open Global Mapper and start a new project by selecting "Load Default Data":

 

lfkyrLAejz.png

 

Click on Find address:

 

bJKzmSuayZ.png

 

Enter the name / coordinates of the area you're interested in (in this case Feyzabad, the map I'm currently working on):

 

58wrQj_js5.png

 

Click to center map on result:

 

zvtKNPMv_t.png


Let's now add some visual reference by clicking on the icon to connect to online data:

 

rJJe_YBwTL.png

 

Select "World Imagery" and click on "Connect":

 

Pnsr0rqENr.png

 

Use the zoom tool to zoom on your area.

 

arCkTaBsJz.png

 

You can now enable the Control Center from the menu:

 

TJFxtnZIdD.png

 

So you can enable / disable the layers to view either the world imagery or the countries default data.

 

We are now going to select our precise area of interest. Click on the "Create rectangle/Square area" tool:

 

APt8vaf2ZN.png

 

Draw an area (doesn't need to be precise) on the terrain where you want your area to be. In the menu that pops up when you release the mouse button, enter the name of your reference area (I've called it "border"):

 

dvQxA3HjsK.png

 

We can now better move the selection to your area of interest. Click on the Digitizer Tool:

 

9DZ_3glxIp.png

 

Select your area, then on the move tool:

 

dJXUekb_Zh.png

 

This allows you to move your area of interest around:

 

wHzPXT6N72.png

 

Once you're satisfied with the position, we're going to adjust this area to be a perfect square in terms of meters. Right click on the area and select "Vertex Editing > Edit Feature Vertices":

 

Pj0OjKuXIb.jpg

 

In the menu that pops up, we're going to change all of the vertices distances so that they reflect our map size, i.e. 10,240m. To do so, click on the first vertex, then on the "Edit Length" button, and enter the value 10240 meters:

 

RfaAKsjLqI.png

 

Once you're done, you will have a perfect square of 10,240m x 10,240m (look at the "Length" column):

 

40THie2uVZ.png

 

Click on "Copy to clipboard" to be able to access these references later:

 

AJLoJ5JNYK.png

 

These are my coordinates:

Idx,Longitude,Latitude,Length,Total Length,Heading
1,70° 30' 01.1798" E,37° 09' 41.4202" N,10.24 km,---,90.0°
2,70° 36' 56.2072" E,37° 09' 41.4496" N,10.24 km,10.24 km,180.0°
3,70° 36' 56.2072" E,37° 04' 09.2811" N,10.24 km,20.48 km,270.0°
4,70° 30' 01.6831" E,37° 04' 09.3107" N,10.24 km,30.72 km,0.0°
5,70° 30' 01.6831" E,37° 09' 41.4793" N,---,40.96 km,---

Use a converter tool to convert these coordinates in UTM. I used this online converter tool to do so:

http://home.hiwaay.net/~taylorc/toolbox/geography/geoutm.html

 

5Qs3dcJBwS.png

 

The result of my conversion is to have the following 4 points:

top left
37.0692447463377,70.5003277260268
UTM: 4103606.716118635,633376.3161381673

top right
37.0692447463377,70.6156131229525
UTM: 4103774.7515539424,643625.6939804782

bottom left
37.1615056060246,70.5003277260268
UTM: 4113842.6755561405,633214.540454661

bottom right
37.1615056060246,70.6156131229525
UTM: 4114010.864559334,643451.4784080114
Note that the UTM zone of my area is 42N.
 
Now it's time to import the roads downloaded from Geofabrik. For the purpose of this tutorial (importing roads) we're only interested in the gis.osm_roads_free_1.* files:
 
QASUf5VuNc.png
 
Import the gis.osm_roads_free_1.shp file to Global Mapper (a simple drag & drop will do), and you will see the roads surrounding your selection:
 
xtAtmDtyzR.png
 
Now we need to convert the project to use UTM. Click on "Configure":
 
ZiYP0WSRwe.png
 
In the resulting popup, set the Projection to UTM (the correct zone should already be set for you, if not just use the one that resulted from your computations here above):
 
hvfimrkOt7.png
 
You might see your areas tilting a bit.
 
Now, let's crop the roads to our area of interest. With the Digitizer Tool active, and only the roads and your border layer visible, select your border, and right click to select "CROP - Crop Loaded Features to Selected Area(s)":
 
Z-vwW3HDQM.png
 
 
Ensure that you consider only lines and that you create a new layer:
 
MLW5UHdmu6.png
 
Name your layer:
 
kKjIX5Prso.png
 
Verify that the projection of your new layer is correct:
 
yXQOSrai8i.png
 
and then click on OK.
 
You can now hide the layer with the full roads, and if you visualize only the newly created "roads_clipped" layer and the border you'll see only the roads you're interested in:
FBLx8g2byc.png
We can now export those clipped roads:
 
2J7cGp25uc.png
 
Export them as "shapefile":
 
Lbe8vYVxft.png
 
Specify your destination file for your lines (in my case, roads_exported.shp) and that "Generate Projection" is selected.
 
xSYbPRbcHE.png
 
 
 
PREPARING ROADS FOR IMPORT
 
Open up QGIS. Open the options:
 
5ZUe9z8e9U.png
 
Ensure that your projection is set to WGS 84 / UTM zone 31N by default:
 
uQEz4K7YDj.png
 
Click on OK and start a new project.
 
Now import (drag & drop will suffice):
  • The reference height map that you exported here above from terrain builder (reference-terrain.asc).
  • The roads_exported.shp that you exported from Global Mapper.
 
Right click on roads_exported and select "Zoom to Layer":
 
aVvBwrP9Rt.png
 
You will see:
 
oG4xOEGWH4.png
 
Ensure that both layers are set to the proper CRS: right click on both layers, select "Set Layer CRS" and select "WGS 84 / UTM Zone 31N":
 
0DzVR2kWQC.png
 
Do this for both layers. If you don't see roads anymore, just right click on the layer, "Zoom to Layer" again.
 
Now it's time that we move the roads to the appropriate place, which is Easting 200000 and Northing 0, as per the data we entered when creating our Mapframe in Terrain Builder.
let's compute how much our roads are off, in terms of UTM:
 
Our top left corner UTM coordinates are (see computations above):
4103606.716118635, 633376.3161381673

We need to make them become:

0, 200000

Hence we need to shift the coordinates:

X shift: 200000 - 633376.3161381673 = -433376,3161381673
Y shift:      0 - 4103606.716118635 = -4103606,716118635

 

Bring up the Processing Toolbox with CTRL+ALT+T, and search for the v.transform algorithm. Once it appears, double-click on it, which will bring up the dialog. Enter the shifting values that we just computed:
 
B2e3au4mSY.png
 
Clic on "Run". This will create a new layer "Transformed". Right-click on this layer, and select "Zoom to Layer". You will see:
 
1_FvUoUHsv.png
 
The black square is our reference-terrain level, so the roads are now in the right position for Terrain Builder. Great!
 
However, you can notice that the roads are slightly rotated in comparison to the reference terrain. We can fix that by applying some rotation. I'm going to choose -1 and apply it with v.tramsform again:
 
O_UTL5T4Qm.png
 
This results in roads being rotated but also shifted southwards:
 
P3g83KMZ7D.png
 
Right click on the upper "Transformed" layer and select "Toggle Editing":
 
IQ9vrkenrc.png
 
Now use the Move Tool to move your roads so that they are fully contained in the black area (the reference terrain):
 
4P-MZ17eN2.png
 
Repeat if necessary.

When you're done, we can export those roads to be used in Terrain Builder. Right-click in the uppermost "Transformed" layer, and select "Save as:"
 
At7HlG-DaB.png
 
Export the layer as ESRI Shapefile (ensure that the proper CRS is set, which should be the default):
 
1pkkMZn2XG.png
 
Here I've saved the file as roads_final.shp.
 
We now need to set the appropriates attributes for roads.
 
xqEluUYfTi.png
 
In the resulting excel-like table, toggle editing mode:
 
4HBoIWr6vH.png
 
Click to create a new field:
 
CQk1ibKysH.png
 
Create a new numerical field called ID:
 
22XJIpXED7.png
 
Now we need to populate this field. Click on "Open field calculator":
 
qNlSPezi52.png
 
and fill the data to look like this:
 
dE7br5Q4J1.png
 
The ID field needs to contain the roads reference as specified in your roadslib.cfg file of your terrain project. Basically, we are populating the newly created ID field based on the values contained in the fclass field by using this expression:
CASE
  WHEN fclass is 'primary' THEN 1
  WHEN fclass is 'secondary' THEN 2
  WHEN fclass is 'tertiary' THEN 3
  WHEN fclass is 'residential' THEN 4
  WHEN fclass is 'service' THEN 4
  ELSE 5
END

Click on OK. You ID field will now be properly populated:

 

rLi777sNdR.png

 

Now let's remove the unneeded fields. Click on the delete field icon:

 

a6z9E_3xC3.png

 

Select all the fields except the newly created ID:

 

st0WPOt-iz.png

 

Click OK. Save Edits:

 

SPlTZTDs3z.png

 

Quit the Attributes Table and If prompted, save the layer.

 

 

 
PREPARING THE SATELLITE IMAGE
 
Open SAS Planet, and click to enter a selection area by coordinates:
 
tyovSa7uH9.png
 
Enter the coordinates as exported by Global Mapper:
 
Se2CtG2pzN.png
 
This will bring up the selection manager. Select "Bing Maps - satellite" (or your preferred satellite source) and then click on the first zoom level that has a resolution higher than your terrain size (in this case, you can see that with zoom level of 18 the resulting image size is greater than 10,240 x 10,240): 
 
nAz2-PcqsC.png
 
Click on "Start" to download the tiles:
 
70SDPF7kyE.png
 
Once the process is finished, click to select the last area:
 
dsmGGnnZzl.png
 
Move to the "Stitch" tab:
 
8JnsObhcRu.png
 
Ensure to select the same Map source (in this case, "Bing Maps - satellite") and level of zoom (here, 18), select where to save your file and click on "Start". This will save your satellite image as a single JPG file.
 
Open up this image in Photoshop (or other editor of choice) and change the size of the satellite image to match the size of your terrain (you will have to un-tick "Constrain Proportions"), in this case 10240:
 
DlfUBf7GWL.png
 
Save your resulting satellite image as a BMP file. Do not save it in other formats, as those might take significantly longer when imported in Terrain Builder (we're talking about hours in comparison to few seconds).
 
 
IMPORTING EVERYTHING BACK IN TERRAIN BUILDER
 
Back in Terrain Builder, import the newly created satellite image:
 
2rsT9zu4bW.png
 
Now import your roads (roads_final.shp):
 
ekmjInDSFb.png
 
When prompted, leave unchanged:
 
3b4J759Zkd.png
 
And there you have it. Enjoy your freshly imported roads:
 
qe9Qa3FFLm.png
 
And if you select them and open up the Database Properties:
 
BesWtG8svA.png
 
You are going to see the correct road ids:
 
lIODXemOSH.png
 
 
 
Many thanks to the various tutorial writers that originally helped me, and to W4lly63 for his great support.
 
Best,
_SCAR.
  • Like 5

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×