Friday, January 29, 2010

How to put a background image from AutoCAD into HEC-RAS

You can use a background image from AutoCAD as a world coordinate background for HEC-RAS. To do it, you print to an image from AutoCAD, create a coordinate World File, and Add the Background Picture in HEC-RAS. This is a follow-up to How to put a background from AutoCAD into SWMMM or EPANET. Where that post showed how to import a vector file, this one shows how to import an image (raster) file.


  1. Decide on the desired background view extents in model space (the Model tab). For simplicity, choose even tens or hundreds for your corner coordinates. Note the corner coordinates of that view.

  2. In a Layout tab, create an mview with the corner coordinates from step 1. Zoom it in model space to the same coordinates, which puts the zoom factor of the viewport at 1

  3. Decide how many world units you want to print onto each image pixel. For simplicity, you probably will want to choose an even number and keep in mind that about 70 pixels make 1 inch of normal quality on-screen viewing, 150 pixels per inch is suitable for newspaper quality printing, and 300 ppi for magazine quality printing. For example, your view corner coordinates are 628000(x), 856900(y) to 630600(x), 858800(y). By subtracting the x's and the y's, you calculate view size is 2600(x), 1900(y). If you printed 100 units on every pixel, you would get a 26 pixel by 19 pixel image, which would not have near the required resolution. If you printed 10 units per pixel, you would get a 260x190 image, which would look good on-screen only as a 4" image. If you printed 1 unit per pixel, you get a 2600x1900 image, which would plot on-screen as large as 36 inches. You decide to use that even though it is on the big size, since it seems not too much larger than modern screen pixel sizes.

  4. Open the AutoCAD print dialog and choose the (Publish To Web) JPG (best for photographs) printer (HEC-RAS can't currently use PNG (best for line drawings)). Select the Properties button next to the printer. Select Custom Paper Sizes and Add or Edit a size with your resulting image size from step 3. Example: 2600 width, 1900 height. Close the properties, saving to the PC3 file.

  5. Select the paper size (image size) you just created. Print a Window using the corner coordinates from step 1. Change or note the name and location of the plotted image file AutoCAD creates. Check the finished plot by viewing it outside AutoCAD from Windows Explorer.


ESRI created the World File format to provide a way to reference image files to world coordinates. HEC-RAS uses that format.
To create a world file format, you need to know how to create and edit plain text files in Windows Explorer (the files and folders view of Windows). This is easiest if you use ALT+T (Tools menu) > Folder Options > View tab and uncheck the "Hide extensions for known file types" option.

  1. Use File > New or Right-click New to create a new Text Document file in the same folder with the background image file you plotted from AutoCAD.

  2. Open the New Text Document.txt and type into it on line 1 the width of a pixel in world units, on line two 0 rotation, on line 3 0 rotation, on line 4 the NEGATIVE height of a pixel in world units, on line 5 the x-coordinate of the center of upper left pixel, and on line 6 the y-coordinate of the center of upper left pixel. Don't forget to calculate the CENTER coordinates of the upper left pixel. Our example file is given below this list. Save and exit the file.

  3. Change the world file name to match the name of the background image file, but with the extension changed to these three characters: the same first letter, the same last letter, and a "w". For example, map.jpg uses map.jgw, map.tif uses map.tfw, and map.png uses map.pgw.

Example world file:


In the HEC-RAS Geometric Data window, follow this procedure from the HEC-RAS help file: Open the Geometric Data editor and create a New Geometry File. Add the background data by clicking on the Add Background Data button. If the image does not come in correctly, select the View, Set Schematic Plot Extents menu item and press the Set to Computed Plot Extents button in the Geometry Extents window. This will zoom out the bounds of the image.

If you have any trouble, just leave a comment below.


Noble said...

It worked just well. Thanks for the help...i've been struggling to find a solution to this problem for over 3days

Anonymous said...

thank you so much for your help..i've been struggling to do this for over a week.

Guillermo Velázquez said...

Thank u, man! U really help me with this blog!

Thomas Gail Haws said...

Heh. Yeah. It works! I just visited in need for help myself at least 4 years later. Hurrah!

Anonymous said...

That was easy! Thank you some much, Tom

garrett Hommy said...

i got my picture of the river put into HEC-RAS but the picture is way smaller than my reaches. how do i make my picture bigger?

Thomas Gail Haws said...

If you followed the instructions, your picture has "real world" scale and coordinates. The typical action after adding your background image would be to move your river reaches to match thalweg lines on your background image or to the approximate locations of rivers on your background image. If you do that and your reach distances between cross sections are proportionally correct, your cross sections should lie at approximately the right locations on your background image.

If you don't want to move your reaches for some good reason (though I can't fathom why), the way you move and scale your background image is to edit the world coordinates file.

Albert T. Dawson, PE said...

Hi Tom -

Thanks for your advice - I did run into a problem.
The background does not appear in the geometry window when I bring it into an existing geometry file of the same coordinates.
When I create a new project, the aerial image I created comes right in - no problem. Then when I import my geometry data into this new file, the aerial image disappears again.. Any clues as to why this happens?

Thomas Gail Haws said...

Sorry. This sounds like uncharted territory for me.

Anonymous said...

Tom, I have also run into a problem. I load the image as suggested, and it shows the correct coordinates, but all I see in the geometric data window is a white screen. I've tried changing the color on the image, and it doesn't do anything. I've tried this with both a USGS map, and an image printed from CAD. Thanks for any suggestions you might have!

Thomas Gail Haws said...

1. When you look at the JPG file, it looks fine?

2. Can you paste here your JGW file contents?

Anonymous said...

Yes, when I open up the .jpg and .tif file, both look fine. JGW is (based on approximate coordinates from CAD)

TFW coordinate are (for world coordinates) -

Thomas Gail Haws said...

I am concerned that you have both a JPG and a TIF file. Which one do you want for your background image?

Anonymous said...

Either. The TIF wasn't working, which is why I then tried the JPG. I only have 1 loaded at a time.

Anonymous said...

I guess the jpg would be preferred. Should I be able to see the image in the geometry window? Or a different window? Do I need to save the file first? Any suggestions for what I could try (or why it is not showing up) would be great!

Thomas Gail Haws said...

You should be able to see the image.

1. Try View, Set Schematic Plot Extents, Set to Computed Extents in the Geometry Editor.

Anonymous said...

I've tried that, and it still does not show up. Any other suggestions to try?

Thomas Gail Haws said...

I suggest starting a new model with no geometry, and adding the background JPG before you draw the schematic. See if you can get it to work in a new model. If you want, you can send me your JPG file. Go to and contact me.

Pran said...

Dude, you're lifesaver, thank you so much!!!

There was an error in this gadget