How to integrate DWG data in QGis

The DWG format is an Autocad proprietary binary
format. When we want to load layers in
QGis from this format, multiple problems arise.

QGis uses the GDAL library to read / write external formats ,
such as DWG.

Firstly a clarification: do not confuse the DWG format and
DXF format. Often references for DWG / DXF
format are found which is a misuse of language. Both
formats are different . The
DWG format is the native format for Autocad software.
It
is a proprietary format and, in theory,
subject to license. The DXF format is a data
export format for Autocad software.
It
is
public and not subject to license.

If you have at your disposal DXF
files none of the problems raised in
this
article applies.

DWG version

The first concern arises from the fact that several versions
of the DWG format exist.

The GDAL library used by QGis, is compiled
with the libopencad library that manages some of these versions, but
not all . You will get a
message such as the following

In the case where the version is
supported
by libopencad you will
get a window similar to:

Drawing
Software
/ GIS Software

In the previous window we can see the conceptual difference
between
CAD and GIS software. In the drawing software , the
objects are grouped in
“layers ” in this window
. We must not confuse the layer concept with the GIS layer.

GDAL tries to move from one notion to another and
that
is why you have in
this
window
a
proposal for GIS layers built from layers of the DWG drawing file.

The first line suggest a 0-FB1-archive
layer with 7 entities of linear type . It
corresponds to a layer of that name where the designer has placed just the
linear objects . For
this layer / layer there is, a priori, no
problem.

Nevertheless, a a little further down, we
have a “BORNES” layer with 39 entities but
with a “Geometry Collection” type geometry .
This, clearly, means that the objects
drawn
on this layer are of different types : lines , points, text , etc …

GDAL cannot create a single
GIS-type layer from the layer without losing, eventually, important information.
For the time being, QGis does not support layers with different
geometries (I believe, only
Geomedia
Intergraph
manages
multi-type geometries). If you select
TERMS and click OK, you will see
a
new layer in the layers panel , but of the DATASET type

You will not see any
entity
on your cartographic
window. Nevertheless,
if
you
open
the attribute table you can
see
the contents of this DATASET

You can see
that the original layer contained circles and
text. Nevertheless, this layer
is
unusable
in
QGis because no geometry is
associated
with the layer and, therefore, we cannot  display it on the map.

Entities
 Content

The other problem that arises but,
usually, when importing data from
the CAD software, is how to manage symbology entities. In
GIS,
the symbology is managed
outside
the entities data. It is not stored as data, at the
most it can be stored
in
separated files, such as QML or SLD.

In the list of layers shown above you can
see
a FAS-hatch- built layer that contains hatches of buildings .

These layers are useless during
the integration in a GIS.

A workaround

Until GDAL can solve all
these
drawbacks
here is a workaround.

You can install and use a free
program to turn DWG files into DXF, before loading them into QGIS.

ODA File Converter (Open Design Alliance) allows converting
the different versions of DWG to the DXF format.

You can download the following
link
.

Once installed , when running it,  you will get
the following window:

You can select
the most recent version of the DXF format as it does not pose any
integration problem with GDAL and QGIS.
The program converts all the DWG files of a
directory , and possibly subdirectories (if
you
check
the Recursive folders box ).

Besides, the fact of having a
file
in
a readable format by QGis, the program groups all
entities in three types of entities : points, lines and polygons
, plus one Geometry Collection class .

Unlike GDAL and Libopencad
, you will see a reduced number of Geometry Collections.
Only the collections that ODA cannot interpret (eg CADAttdef)
will remain as collections.

Others, such as the layer TERMINALS we have discussed above,
will be converted as points for the texts (with TEXT
attribute ) and lines for the circles .

The result , if you load
the three layers (Point, LineString and Polygon) will be of the
following type:   

A cleaning job to remove drawing artefacts will be
essential to retain only the data itself:

This can be easily done since the attribute table
generated
contains
the name of the original layer for each
entity
.

Si cet article vous a intéressé et que vous pensez qu'il pourrait bénéficier à d'autres personnes, n'hésitez pas à le partager sur vos réseaux sociaux en utilisant les boutons ci-dessous. Votre partage est apprécié !

Leave a Reply

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