DWG, AutoCAD

AutoCAD .dwg format is a CAD format which is occasionally encountered in GIS use.  AutoCAD .dxf, also a CAD format, is usually more popular.  AutoCAD .dwg format has not been published by AutoCAD and thus any ability to read .dwg files comes from overall community experience and guesswork.  While not all .dwg files or all features they contain may be successfully read, in most cases remarkably good imports are possible.

 

AutoCAD .dwg format is a very poor format for GIS work because it fails to convey coordinate system information or DBMS data for objects.  After importing data we must manually specify the coordinate system by using the Assign Initial Coordinate System dialog.

 

ico_nb_arrow_blue.pngManifold connects to DWG 2018 and earlier versions of the format.  See comments in the Notes section at the end of this topic for a free Autodesk tool to convert between different versions of .dwg format.

New Source Dialog

A quick way to import a .dwg file into a project is to use File - Import.   For better control over the resulting import, most Manifold users will import a .dwg using File - Create - New Data Source, since the  New Data Source dialog provides a Merge layers option.

 

.dwg drawings will often include layers.  Each layer will be imported into Manifold as a separate drawing so that they can appear within a map as layers. A map component containing all the layers will also be created.   Some .dwg files may contain a bewildering number of layers that are best organized within a single drawing.   Checking the Merge layers option box in the New Data Source dialog will create a single drawing that contains all such layers.  Reading DWG files hides map layers that are marked as turned off.

 

To import from dwg format:

 

  1. Choose File - Create - New Data Source from the main menu.

  2. Choose File: dwg as the Type.

  3. In the Source box, use the [...] browse button to find and to open the .dwg file desired.

  4. Check the Merge layers box if desired (almost always).

  5. Press Create Data Source

  6. Expand the new data source hierarchy, highlight the linked components within, and choose Copy.

  7. Click into a blank part of the project outside of the data source hierarchy and choose Paste.

 

dlg_dwg_create_data_source01_01.png

 

Name

Name for the new data source, "Data Source" by default.  Specify a more  memorable name as desired.

Type

Choose File: dwg to connect to a .dwg file.

Source

The path to the .dwg file.  Use the [...] browse button to navigate to, and to open the desired .dwg file.

[...] Browse button

Click to populate the Source box.  Browse the Windows file system to locate and open the desired file using a Select File dialog modeled on the standard Windows File - Open dialog.  The type of file will be pre-loaded into the dialog depending on what was selected in the Type box

Open as read-only

Open the data source read-only.  Not checked by default so that if we want to open a .dwg file read/write we can do so.   .dwg format will lock out other users if we connect to a .dwg file read/write.  Therefore, if we would like to allow other users to be able to simultaneously connect to this same .dwg file and we do not need to write to it, we can check this box.  We can also check the read-only box if we would like to protect against accidental changes to the  .dwg file

Cache data

Create and utilize an accessory .MAPCACHE file for improved performance. Checked by default.

Save cached data between sessions

Save the cached data for the next time this project is opened, either within the .MAPCACHE file or within the .map project itself within a Cache subfolder within the System Data hierarchy.  Not checked, and not recommended for .dwg.

Cache only data that is expensive to compute dynamically

If there is significant overhead in computing data to be displayed, cache the results.  Uncheck this option.

Merge layers

Bring data from all layers within the .dwg into a single drawing and table. Add a field for each record in the table giving the name of the original layer.   Most Manifold users will check this option, since it is usually easier to manipulate data within a single drawing in tasks such as styling the data than it is to work with a large number of layers (the usual case with .dwg files).

Create Data Source

Create the new data source in the project pane and close the dialog.

Edit Query

Launch the Command Window loaded with a query that creates the data source using the given settings.  A great way to learn how to use SQL to create data sources.

Cancel

 Exit the dialog without doing anything.

Example

We will import a .dwg that shows the layout for a large theater.

 

eg_import_dwg01_01.png

 

Launch File - Create - New Data Source.  Enter MFC Auditorium as the name and for the Type choose File: dwg.  No need to cache, so we uncheck the sub-boxes under Cache data.   This particular .dwg uses a spectacularly messy set of layers, so we will check the Merge layers box to consolidate those many layers into a single drawing.  Click the [...] browse button

 

eg_import_dwg01_02.png

 

In the Select File dialog, navigate to the desired .dwg file, click on it, and choose Open.

 

eg_import_dwg01_03.png

 

Press Create Data Source.

 

eg_import_dwg01_04.png  eg_import_dwg01_05.png

 

In the Project pane we expand the new MFC Auditorium data source and we ctrl-click on the four components within to highlight them.   We press Ctrl-C to copy them.   We click into an empty part of the Project pane outside of the data source hierarchy and press Ctrl-V to paste.    We can now click on the MFC Auditorium data source and choose Delete to delete it.

 

eg_import_dwg01_06.png

 

What we have just done is to link to the .dwg file and to then copy the data in it and paste that into the local .map project.   That is the same as using File - Import, except that we accomplished the import using the New Data Source dialog that gave us the option of merging many sparse layers within the .dwg into a single drawing that is much easier to work with.

 

We double-click the Map component to open it.

 

eg_import_dwg01_07.png

 

The result is a typical CAD drawing, with a labels layer above, that is brought in from a .dwg.      We can clean it up using various Manifold facilities.  

 

We color the drawing layer with lighter colors using Style and then we choose yellow color for the labels to make them more visible.   We use the Layers pane to set a background color of black.   We use transparent color for points, to make anchor points for labels disappear.

 

eg_import_dwg01_08.png

 

The result is a much more comprehensible display, as seen above.    The formatting used for the drawing is shown below.

 

eg_import_dwg01_09.png

 

The Layer field in the table specifies the name of the layer from which a particular object was imported.  We can use that in a thematic format to color each object by the layer from which it originated, which usually results in a comprehensible display.   We have applied the CB Paired palette, using a method of unique values.

 

We have also set the foreground color for points to transparent color, which has the effect of making any points that are left in the drawing disappear.  Some  points are used as anchor locations for labels, but there is no need to show a point icon at the location to which the label is anchored.

 

eg_import_dwg01_10.png

 

Zooming into the map we see that no area objects are used: the drawing is created using line objects.  

Projections

.dwg files do not provide projection information.   They are CAD files, not geospatial files and thus are a really poor choice for the publication of spatial data.  In the above example we simply choose Pseudo-Mercator as the projection, since the drawing shown is not a geospatial drawing but simply a blueprint.

 

Assume that projection information will not be captured when importing a .dwg.  We should try to find any information that accompanied a .dwg file that may describe the intended projection so we can launch Assign Initial Coordinate System in the Contents pane to specify the intended projection.  

 

Managing Many Layers

DWG files often include dozens of layers.   If we do not check the Merge layers box, those many layers will be imported as separate drawings.   Although the map component created will automatically include all those layers, sorting out which ones we want can be tedious because the tab strip at the bottom of the map window will be too cluttered with too many tabs, each of which are too small to show the full name and most of which are not desired.   We can use Manifold facilities to create a simplified map as follows.

 

Simplifying a map with many layers to only a few layers:

 

  1. In the Project pane, Copy the map and Paste it.  This makes a backup of the map with all of the original layers.

  2. Open the copy and open the Layers panel in the Contents pane.  The following steps are done in the Layers panel.

  3. Select all of the layers and turn them all off.  Deselect all of the layers.

  4. One by one, double-click the layers to turn them on and off, to see which layers are desired.

  5. When the map has only those few layers desired that are turned on, select the layers that are on for display.

  6. Press Ctrl-I to invert the selection.  Now, those many layers which are not turned on are selected.

  7. Delete selected layers.  We now have a map with only those few layers of interest.

 

Notes

Supported Versions

 

ico_nb_arrow_blue.pngManifold connects to DWG 2018 and earlier versions of the format.  Autodesk, the makers of AutoCAD, provide a free program called DWG TrueView that may be used to convert between different versions of DWG.dlg_dwg_trueview_opt_out.png

   

Caution: The Autodesk 64-bit DWG TrueView installation package is over 800 MB in size, and expands during installation to over 2.1 gigabytes.  The installed version in C:\Program Files totals to approximately 1.4 gigabytes, so the total space required to install the DWG TruView "viewer" will be 3.5 gigabytes.

 

Autodesk DWG TrueView automatically collects information on our use of the program and reports that data back to Autodesk.  There is no option  during installation to disable such data collection and reporting.  To disable surveillance, open any .dwg file and then in the Help section of the toolbar ribbon click on Desktop Analytics.  In the resulting Data collection and use dialog, un-check the "I agree to data collection" box and press OK.

 

Block names - Reading DWG and DXF files creates a field for block names. If an object belongs to a sequence of nested blocks, the system uses the name of the top-level block.

 

DWG Import Options - .dwg is thinly documented and can include format variations that are not at all documented. Although the Manifold .dwg dataport works surprisingly well across a wide range of .dwg files it is always possible that a .dwg may be encountered that cannot be imported.

 

An option in such cases is to use Manifold's GDAL/OGR dataport to attempt to import the .dwg through GDAL using the File - Import command.   GDAL imports all layers merged together, but does not build a separate labels layer for text.   Differences in how different packages import a .dwg are very common, so having two options to import .dwg within Manifold can provide a second chance to extract all possible from a quirky .dwg.  

 

Unicode and codepage data - The DWG dataport maps character data to Unicode using codepage data in the DWG file.

 

Michael Fowler Center - The MFC Auditorium is a concert hall in Wellington, New Zealand, the Michael Fowler Centre.

See Also

Style

 

DXF, AutoCAD