Home > Uncategorized > Converting Autocad DWG files to ESRI Shapefiles

Converting Autocad DWG files to ESRI Shapefiles

There are plenty of tools that can convert DWG files to Shape files (FME, CAD2Shape etc) but most of them are not free. There are however, ways to do this for free – even though it might not be as convenient. One way is to use ODA Teigha File Converter to convert to an intermediate DXF file and then use OGR in FWTools to convert that into shape. I tested this approach using a sample file, gaston14.dwg, download from Geodetic Survey.

Alright, let’s see some code. Launching ODA Teigha File Converter  (EveryDWG.exe) from the command line can be accomplished by:

EveryDWG.exe C:\…\input C:\…\output ACAD2007 DXF 0 1

This assumes that input and output are folders that exists and that the input folder contains the dwg file to be converted which in this case is gaston14.dwg. Not that pretty, but it works. Now the output will contain a file called gaston14.dxf and we can use ogr2ogr to convert this into shape files. Since shape files can only one feature type we will create one for points, one for lines and one for polygons:

ogr2ogr gaston14_points.shp gaston14.dxf -where "ogr_geometry = ‘POINT’"
ogr2ogr gaston14_lines.shp gaston14.dxf -where "ogr_geometry = ‘LINESTRING’"
ogr2ogr gaston14_polygons.shp gaston14.dxf -where "ogr_geometry = ‘POLYGON’"

This assumes that current directory is the output folder.

Advertisements
Categories: Uncategorized
  1. user
    October 13, 2015 at 11:41 am

    Cool.

    New file name is C:\Program Files (x86)\ODA\Teigha File Converter 4.01.0\TeighaFileConverter.exe

    New URL is https://www.opendesign.com/guestfiles/TeighaFileConverter

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: