Assign Elevations to Contours from an ESRI Shape File

Shape files (.shp) are a common file format in the GIS world, the file format is often used to exchange data between ESRI software and AutoCAD.  Because each software package structures data differently, translating it into something useful can be challenging.  For example, shape file vectors are always 2D.  Though if they are contours, they should have an attribute that represents their elevation.  In this post, I’ll go through importing an ESRI shape file containing contours, and moving those contours up to the appropriate elevation.

AutoCAD Map, Civil 3D, Land Desktop, and Topobase all have the ability to import a shape file.  You’ll need the .shp, .shx, and .dbf files in order to import and perform the translation.

Part A – Import  the Shape File:

  1. Start a new drawing.
  2. Type MAPIMPORT at the command line.
  3. Make sure Files of type is set to ESRI Shapefile, select the file, and click Open.
  4. In the Import dialog, select Import polygons as closed polylines.
  5. Click inside the cell under Data:
  6. Click Create object data.
  7. Click OK to close the Attribute Data dialog.
  8. Click OK to close the Import dialog.

When the file is done importing, zoom extents to see the results.  Select a contour line and look at the Properties Palette.  Notice that the AutoCAD Elevation property is 0, but that we also have an “OD” category in Properties.  This is the object data that we brought in with file.  Note which field contains your elevation data, then save and close the file.

Part B – Connect to the Imported DWG

  1. Start another new drawing.
  2. If the Map Task Pane is not currently showing, type MAPWSPACE at the command line and select On.
  3. In the Map Explorer tab, right-click Drawings and click Attach.
  4. Click the Create/Edit Aliases button, ,  if the drawing is not on the C drive.  Otherwise, skip to step 11.
  5. Enter a name for the Drive Alias.  Note that it can be multiple characters, but no spaces are allowed.
  6. In the Drive Alias Administration dialog, click Browse.
  7. In the Choose Directory dialog, select the location where you saved the dwg in Part A.
  8. Click OK.
  9. In the Drive Alias Administration dialog, click Add.and then click Close.
  10. In the Select drawings to attach dialog, for Look in, select the Alias that you just created.
  11. Select the drawing previously created in Part A, click Add.
  12. Click OK.

Part C – Query to Assign Elevations.

  1. In the Task Pane on the Map Explorer tab, expand Query Library, right-click Current Query and click Define.
  2. Click the Location button.  Select All
  3. Click OK.
  4. For the Query Mode, select Draw.
  5. Click Alter Properties.
  6. Select Elevation and click Expression.
  7. In the Property Alteration Expression dialog, expand Object Data, expand the object data table and select the field that contains the elevation data
  8. Click OK.
  9. In the Set Property Alterations dialog, click Add
  10. Click OK.
  11. Click Execute Query.

Zoom extents, and there you have it, your contours in the drawing with the proper elevations assigned.  Save the new drawing and then detatch the first drawing.  (On the Map Explorer tab of the Task Pane right-click your drawing and click Detatch).  You may discard it if you like.  Be careful using this technique with live data as it is possible to modify the attached drawings.  If you think that other GIS tools such as this would be helpful, consider Map 3D training to take full advantage of your software.

30 Comments
    1. Hi Kevin. Did you do a Zoom Extents after importing the shape file? The command line will report the number of objects imported, does it list an appropriate number of objects or does it report an error?

  1. The OD property that contains the elevation data does not appear in the Property Alteration Expression dialog box. Any suggestions?

    1. Are you sure there is object data associated with the objects? If you select one of the objects in the drawing you imported them into and look at Properties, do you see the elevation object data listed?

    1. In the Define Query dialog box, the toggle for Query Mode is in the middle of the bottom half of the dialog. Change it from Preview to Draw.

  2. Never mind, I got it figured out by adding a path to the Map Support folder to get the dialog box up. Once the dialog is up, the rest is pretty much straight forward like your instructions. The only thing I’d to add is when clicking Alter Properties, the redraw button needs to be clicked before execute the query. Otherwise the contour lines will still have elevation 0. Anyway, your instructions are the most thorough I can find on the Internet. Your post was from 2011, but still works like a charm. Appreciated.

  3. I did all the steps, but when i got into the last step which is executing the query, there is a notification at the bottom of the dialog box stating that the query cannot be performed and its empty.

    What could be the possible reason behind this error?

    Thank you..

    1. It could be that the first drawing was not attached properly at the beginning of Part B, or that there are no valid objects in the first drawing.

    1. Its in the Define Query dialog box. First right click on Current Query and choose Define, as described in step 1 of Part C.

  4. Hi Neil, one step that I had to do which wasn’t mentioned was right click on the drawing name at the end of part A, then click Activate. Otherwise I would get the error after doing part C that stated “query source is not available or empty”

  5. Thank you Neil! I am using your approach for few years now. And it worked perfectly in previous AutoCAD versions (for example 2016), but it doesn’t in Civil 3D 2019. But – Audrey’s solution mentioned above helped! I would just say that you have to activate the 1st drawing at the beginning of Part C, not at the end of part A (since you don’t have Task Pane open yet during Part A). Thank you Neil and Audrey!

  6. When I go click on Expression, I do not get an object data option. It only give a Properties folder option (and object data is not listed under that). What am I doing wrong?

    thanks!

    1. Hi Alice. That means there is no object data associated with the lines. Either there is really no data, or we skipped associating it to the objects in step 5 & 6 of part A.

    1. That likely means you have no object data assigned to the objects. Either we skipped step 6 in Part A to create the object data, or there’s none to begin with. If there’s none to begin with, there’s not much we can do except go back to the original source and ask them to make sure they include it.

  7. I completed these steps but still get an elevation value = 0. I think it has to do with the fact that the elevations in the object data are expressed in numbers & text (for example, elevation data is shown as “1000 ft” instead of “1000”. I’m guessing that is why I’m not get the correct result. Is there any way to define the query so that it ignores the “ft” in the elevation object data and just pull the number. Thanks.

    1. You are correct, it has to be a valid number, a mix of numbers and text isn’t valid. You can edit the .dbf (the file containing the attribute date) associated with the shape file in Excel and do a find and replace to remove the ‘ft’. Do a Find for ‘ft’, and leave the Replace empty.

  8. Thanks a bunch Neil. I was able to edit the database file associated with the shapefile by removing the “ft” text from the elevations. I had to do this in Microsoft Access as Excel was not allowing me to save back to a database file. I then followed the same steps in your post and was able to get the elevation object data to convert to actual elevations. Thanks again!

Leave a Reply

Your email address will not be published.

Back to blog

Copyright ©2017, CAD Masters, Inc.. All Rights Reserved.