World Files

Have you ever tried pulling web imagery into RAS Mapper only to find that it doesn’t line up with your existing shape files, terrain surfaces, or other geospatial data?

Or have you ever received your background data in hard copy or pdf format and wished you could view it in its georeferenced location? 

In this article on using RAS Mapper as a GIS tool we’ll first cover the modification of world files for georeferencing then we’ll cover the steps required to georeference your map using world files.

Using RAS Mapper as a GIS tool:
Shifting Web Imagery with World Files

In some cases, the misalignment of web imagery may result from an incorrectly applied projection file. If needed, projection files can be downloaded for free from spatialreference.org and other online data sources. You can check the projection of your terrain file by double-clicking on it in RAS Mapper, then select the “Source Files” tab and view the metadata using the Info column. 

If you have confirmed that the correct projection file is being used and you are still having issues, there are a few additional workarounds you may wish to try. One option is to select the “Alternate HEC-RAS Raster Warping Method” under “Tools | Options” in RAS Mapper. This method applies the gDAL OGR vector reprojection. I have found this method useful for resolving discrepancies in European data sets in particular.

In some cases, the alternate method doesn’t do the trick either. RAS Mapper uses the ESRI projection file format, which as I understand it does not recognize TOWGS84 parameters and in some cases improperly applies the proj.4 projection parameters. In any case, you may find yourself stuck with misaligned web imagery.

One workaround is to save static images of your web imagery and then shift the image to the correct location by making adjustments to the world file (Wikipedia has a good summary of the six lines of code comprising a world file here).

Here’s a video walk-through of the process:

https://youtu.be/5REWQ8Z_08I

The “World File Calculator” spreadsheet referenced in the video can be downloaded here:

https://www.surfacewater.biz/wp-content/uploads/2018/12/Surface-Water-Solutions-World-File-Calculator.xlsx

Here are the steps covered in the video:

1. Adjust transparency as needed so that you can see a known point in both the web imagery and in the survey or LiDAR data.

2. Using the measure tool in RAS Mapper, click on a known point from the web imagery (with incorrect location), then double-click on the the same known point based on the correct location.

3. Select “Copy coordinates to clipboard”.

4. Zoom to preferred extents for results and save view (click here for further details on saved views and static imagery).

5. Right-click on web imagery and select “export layer”. Note: RAS Mapper currently has two export options: tif and jpg. The tif format will embed the metadata and georeferencing information into the encoded text of a geotif file without generating a separate world file. A tfw file can still be created to override the embedded georeferencing, but I suggest using the jpg format so that the world file is automatically generated. Save the image (I suggest creating an “aerial imagery” subfolder within the current project’s directory structure to store static images).

6. Open the world file calculator spreadsheet.

7. Paste the coordinates from RAS Mapper into the blue cell.

8. Open the newly created jgw file (jpg format world file) in a text editor and copy the values.

9. Paste the values into the “Original World File” column of the spreadsheet.

10. Copy the “New World File” values over the original values in the jgw file, save, and close.  

11. Under Map Layers in RAS Mapper, right-click and select “Add Existing Layer”. Be sure to drag down file types to show all image files and browse to the newly created file.

12. Adjust transparency as needed to confirm common points are now co-located.

The process can be repeated to fine-tune the positioning. Because a static image won’t be pyramided like web imagery, you will unfortunately need to complete these steps at every desired zoom level and view extent, the but the process of saving static images allows you to control the appearance of your figures without having to worry about losing your internet connection while presenting or viewing results.

Note that these steps assume the units and north alignment are the same (or close enough) between the data sets and that the static image can be simply shifted without scaling or rotation factors, which we’ll cover in more detail in our next post.

Please let us know any feedback or suggestions for improvements or additional efficiencies in adjusting web imagery.

Using RAS Mapper as a GIS tool:
Georeferencing Hard Copy or PDF Maps

This application is addressed in this video walk-through beginning at 6:37:

Here are the steps covered in the video: 

1. For hard copies, scan your image to a raster format (commonly jpg or tif). For pdf files, use “save as” in Adobe Acrobat and select jpg (resolution can be adjusted under settings). For other file types, you may wish to use the Snipping tool that ships with Windows and save the screenshot as a jpg (best if it’s on a high-resolution screen as you’ll be stuck with the screen resolution and not the original source file’s resolution).

2. Create a new file in Word, Notepad, Wordpad, or other text editor or word processor (or copy an existing world file and skip to Step #5).

3. Enter six lines of text. Use dummy values from “original world file” column in the World File Calculator spreadsheet (available for free downloaded here) or take an initial guess at values based on the assumed coordinates of the upper left pixel.

4. Save file as plain text format (*.txt) using the same file name as the image file (select “default settings” if prompted).

5. Change file extension in Windows Explorer using the world file extensions listed below (click yes if prompted with unusable file warning).

6. Under Map Layers in RAS Mapper, right-click and select “Add Existing Layer”. Be sure to drag down file types to show all image files. Browse to file and select OK.

7. Using the measure tool, measure the distance between two points that are a known distance apart (preferably from a scale bar or coordinate tick marks on the map).

8. Open the World File Calculator spreadsheet and enter the measured and actual distances under Line #1 (cells D3 and E3) and Line #4 (cells D6 and E6).

9. Copy values from “New World File” column, open the world file in a text editor, and paste the updated values over the old values.

10. Right click on the image file and select “remove layer”.

11. Re-add the image file and adjust transparency as needed.

12. Using the measure tool, click on a known point from the original image (with incorrect location), then double-click on the same known point based on the correct location.

13. Select “Copy coordinates to clipboard”.

14. Paste the coordinates into Cell C10 in the spreadsheet (Note: values will be replaced in the cell range C10:F12 but only C10:D11 are used in the spreadsheet).

15. Copy “New World File” column over the previous values in the world file.

15. Remove and re-add the image file.

16. Adjust transparency as needed to confirm common points are now co-located. Measure the scale bar to confirm correct scaling.

Note on rotation factors: These steps assume that north is straight up in your hard copy or pdf map based on the applied projection (or at least close enough to straight up to suit your purposes). If not, raster image can be rotated in graphics program (Photoshop, Paintshop, Word, etc.) to get north to align. [The “Z axis rotation” can be used in Microsoft Word to apply specific sub-degree rotation factors.] Rotation terms can be added to the world file, but in my experience this can lead to some confusion, as the pixels shift on the fly at different zoom levels, so my preference is to make rotation adjustments graphically before diving into the world file adjustments.

By the way, here’s a great video on why projections matter: Why all world maps are wrong. With this in mind, it is no surprise that even if you get two points to line up perfectly, a third point can still be shifted, particularly for points located a significant distance away from the alignment points. I suggest using points that are as far apart as possible for your selected zoom extent to avoid major discrepancies. Keep in mind that these adjustments only provide a visual approximation and should be treated cautiously if the results are to be used for permitting or construction purposes. In that case, you’d want to get a surveyor on board with the proper tools to apply all of the required warping and address any discrepancies. 

We’ll continue to add periodic posts on the use of RAS Mapper as a GIS tool. In addition, we are working on an upcoming post covering hacks for removing flow from HEC-RAS models. Internal boundary conditions are very useful for adding flow anywhere in your model, but removing flow can be a tedious process. Once spatially varying infiltration and other features are added to Version 5.1, the process may be simplified, but in the meantime it requires a bit of creativity. I’ve seen some clever workarounds being applied that we would like to share with this forum; please contact me if you have done this successfully so we can perhaps feature your method in an upcoming blog post.

And speaking of Version 5.1, right at the top of my wish list is for HEC-RAS project files to be called *.ras files, *.hrp (HEC-RAS Project) files or any unique extension that doesn’t happen to coincide with thousands of other files on my computer (in this case, of course the ESRI-format *.prj projection files). I understand the Corps may have been first in this case (calling their project files prj’s well before ESRI did) but the rest of the industry is not about to change their format for shape files, so maybe HEC-RAS project files can get a unique identity in the next version – or at least a search tool within RAS that can recognize and distinguish HEC-RAS-format project files. Let us know if you agree and maybe we can turn this into a grass roots, crowd-based request!

Let us know what you think or if you have other suggestions for improving any of these processes.