L3DB6H

Lloyd Bosworth : archaeologist | human | beard

Why a 3D Topographic Model?

dem created in arcgis from contour dataI’ve been asked to produce a walk-through animation of a reconstructed archaeological site that shows the landscape setting of important buildings, and how these buildings constrained the movement of people. Reconstructing the buildings is pretty simple, with lots of reference material available. However, the 3D topographical model of the landscape is much trickier, made worse by not having any digital elevation data, only paper maps with contours.

Drawing contours with height attributes is easy in ArcGIS, but when I was asked to create an animation, I had no idea how to get the GIS shapefile data into my 3d software for animating. I figured there must be a way, and sure enough, ArcGIS has all the tools for converting and exporting a shapefile that can then be opened in pretty much any 3d software package.

What we’ll be doing

For this exercise I will be using ArcGIS, Excel and MeshLab. The 3d mesh that we’ll create in MeshLab will be exported in a file format that can be imported straight into Autodesk’s 3dsMax, where it will be used to create the final animation.

By the end of this you’ll be able to:

  1. Convert a vector contour layer to a raster DEM layer using the vector layer’s height field
  2. Convert a raster DEM to a point cloud in ASCII text file format
  3. Import an ASCII text point cloud file into MeshLab and create a mesh that can be used in most 3d software packages

Drawing in ArcGIS is a pretty basic skill that I won’t go into here, but I will say that your contour lines should be drawn as polylines, not polygons. As the end result will be a 3d model from 2d map data, make sure you have added a height field (z, height, or whatever you want to call it) to your contour layer’s attribute table.

Now, spend the next however many hours of your life robotically drawing contour lines. This is going to be unbelievably tedious, so put some music on and get comfortable. Remember, after you finish drawing each contour line, add its height value to the height field in the layer’s attribute table. Also, save your edits and map regularly.

Now that you have traced all the contours on your map and added each line’s height value to the height field in the layer’s attribute table, you’re ready to crack open your ArcToolbox and dust off two rarely (for me!) used tools: 3D analyst Tools > Raster Interpolation > Topo to Raster and Spatial Analyst > Extraction > Sample. These two tools have very few parameters that need to change and are pretty much ‘wash and go’.

Convert a contour polyline to raster DEM

  1. ArcToolbox > 3D analyst Tools > Raster Interpolation > Topo to Raster
  2. Select you contour layer as the input feature
  3. Under ‘Field’, select the field that contains your height data
  4. Enter a name and save location for your raster under ‘Output surface raster
  5. Leave everything else as default
  6. Click OK
Image of a raster DEM created in ArcGIS using height data stored in a vector contour layer.

Raster DEM created in ArcGIS using height data stored in a vector contour layer.

Isn’t that a beautiful DEM? If all you’re after is a DEM for your map, have a play with the symbology settings until you’re happy, then you’re done. However, this is only a step along the way to creating a 3d model, so onto the next step.

Convert a raster DEM to ASCII text

  1. ArcToolbox > Spatial Analyst > Extraction > Sample
  2. Select your DEM from the ‘Input rasters’ dropdown
  3. Select your DEM as ‘Input location raster or point features
  4. Select save location and file name, adding .dbf to file name
  5. Set resampling technique to ‘Bilinear
  6. Under Environments > Processing Extent, set input raster as ‘Snap Raster
  7. Click OK
Image: Converting a raster DEM to ASCII text format using ArcGIS.

Converting a raster DEM to ASCII text format using ArcGIS.

Now you should have a .dbf and an .xml file in your chosen save location. We’re only interested in the .dbf file, but don’t delete the .xml file, as ArcGIS will be sad without it.

Editing the ASCII text file

The export to text we did in the last step will usually create extra columns and give our height column an unusual name, so now we need to do a little bit of editing in Excel.

  1. Open the dbf file in Excel
  2. Column ‘contour_ra’ is essentially the same as column ‘contour__1’ only rounded. Rename ‘contour_ra’ as ‘z’ and delete column D
  3. Reorder the columns to x, y, z
  4. Save as MS DOS .txt
Image: Column A and D are your height data and are essentially the same. Rename one column to 'Z' and delete the other.

Column A and D are your height data and are essentially the same. Rename ‘contour_ra’ to ‘Z’ and delete the other. reorder the columns to x, y, z.

Creating a mesh from point data in MeshLab

I wouldn’t normally use MeshLab for this step, preferring other point cloud tools, but MeshLab is free and available to everyone.

  1. Open up MeshLab and import the text file you created in the last step
  2. In the Open Options dialogue box, select the parameters for your file. Usually this just means changing ‘separator between’ to SPACE.
  3. You should see a point cloud that (hopefully!) resembles the surface of the map you spent all that time drawing.
  4. Hit CTRL + L to show the layers panel
  5. Right click the point layer and select ‘Duplicate Current Layer
  6. Hide the original layer and change the duplicate layer display to points
  7. Go to Filters > Normals, Curvatures and Orientation > Compute normals for point sets
  8. Change ‘Neighbour num’ to 1000. Leave all other parameters at default
  9. Click Apply then Close
  10. Go to Filters > Point Set > Surface Reconstruction: Poisson
  11. Change ‘Octree Depth’ to 11
  12. Click Apply then Close
  13. This will create a new layer containing the new mesh
  14. Go to File > Export Mesh As… and choose a name and save location for your new mesh
Image: Creating a mesh from point data in MeshLab

Creating a mesh from point data in MeshLab

That’s all there is to it. You’ve used ArcGIS to convert a vector contour layer to a raster DEM layer using the vector layer’s height field and converted that raster DEM to a point cloud in ASCII text file format. You’ve imported that point cloud into MeshLab to create a mesh that can be used in most 3d software packages.

In this example I exported to .ply format, but MeshLab will export to many other file types, so that whatever the final destination for the 3d model, there should be a compatible option for you.

I hope you found this pretty easy to follow, and if you have any questions, drop them in the comments box below.

Google Earth Pro now Free! arrow-right
Next post

arrow-left 3D model of Roman Tile with Graffiti
Previous post

  • txin

    July 27, 2015 at 7:50 am | Reply

    It doesn’t work for me when importing XYZ data into meshlab. I can’t see flat surface just like you. I would like to know why it’s doesn’t for me? Explain me details please!!

    • Lloyd

      July 31, 2015 at 10:42 am | Reply

      Hi! Without more detail it’s difficult to say why it’s not working for you at the import step. I’ve checked through the instructions and it should work, so maybe you’ve missed a step. If you’ve got as far as importing to MeshLab, you should have a txt file with three columns labeled x, y and z. Double-check that they are in that order and try importing again. Let me know how you get on!

      • Txin

        September 11, 2015 at 2:34 am | Reply

        How can I send my result to you?
        I wanna show you my result terrain photo.

        • Lloyd

          September 14, 2015 at 9:27 am | Reply

          Hi, there are many 3D publishing services that allow you to upload your models so that you can easily share with others. Two leading publishers are Sketchfab and p3d.in, both of which require you register before using their services. I would be interested to see your results, so if you do upload your model to either of these services, post a link to it here in the comments.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.