88 | | Blog: http://gsoc2016gdaldwg.blogspot.ru |
| 88 | ==== Overview ==== |
| 89 | |
| 90 | Libopencad is a library written in C++11, which provides a way to read/write CAD (DWG/DXF/DXFB) files. It was designed to have a uniformal API to work with any CAD files. It has a base class - CADFile. Inheriting this class it’s possible to create a ‘driver’ for any CAD format, all you need to do - is to overwrite interface functions like ‘GetGeometry(index)’, and others. Now it has an implementation for DWG2000 (R15), but only for read. |
| 91 | Library comes with ‘cadinfo’ utility, which prints out everything library can get from file - header variables, CAD custom classes, presented layers and geometries with their attributes. |
| 92 | |
| 93 | ==== Internal structure ==== |
| 94 | |
| 95 | Library presents CAD objects in different ways - base class CADObject and other CAD...Object classes are exact analogues of how DWG format stores information about its objects. CADGeometry, and other classes which inherits it, are done for API access to CAD...Object classes. |
| 96 | Library supports 3 modes of reading - READ_ALL (means everything which can be extracted from CAD file will be read) READ_FAST (skipping some kind of meanless information - linetypes, CRC check, etc), READ_FASTEST (only geometries reading, additional info is skipped). |
| 97 | When parsing the file, library does not store any information it does not need. First, it reads file meta-information, and creates a file map. It only stores some info about presented layers, and header variables. Then, when calling application uses CADLayer.GetGeometry(index), it actually reads a geometry from file, using prepared file map. Sometimes it will be slower than having everything you have read in cache, but gives you more flexibility what you want to store in memory, and what you wont. |
| 98 | Library also has special classes which incapsulates I/O functions, so it’s possible to reimplement them for your needs - by default it uses std::fstream, but you can make it possible to work with network by make a class inherited from CADFileIO. |
| 99 | |
| 100 | Supported geometries list: |
| 101 | Point, Circle, Ellipse, Arc, Text, Solid, Spline, Line, Polyline 2D, Polyline 3D, LWPolyline, Ray, Raster (Images), MText, MLine, XLine, Polyface Mesh, 3DFace. |
| 102 | |
| 103 | === GDAL CAD Driver === |
| 104 | |
| 105 | ==== Overview ==== |
| 106 | |
| 107 | GDAL CAD Driver uses libopencad as a datasource. Not everything that libopencad can read from file is mapped into OGR infrastructure, but it will be done in near future. Current features are: |
| 108 | |
| 109 | 1. OpenOptions are presented with 2 options: |
| 110 | - MODE - READ_ALL/READ_FAST/READ_FASTEST (means the same as library OpenOptions). |
| 111 | - ADD_UNSUPPORTED_GEOMETRIES_DATA (YES/NO) - unstable feature, if some of the objects cannot be mapped into OGR representation (or its just not implemented yet), it will be presented as a CADUnknown object - OGRFeature without geometric representation, but with basic info - geometry type, some additional params. |
| 112 | 2. CAD header variables are mapped into metadata. |
| 113 | 3. Unlike DXF driver, CAD driver stores vector data in the appropriate layers (not all entities in single layer). |
| 114 | 4. Raster subdatasets are also supported. |
| 115 | 5. Coordinate system is extracted from DWG file (if it is presented in accordance with ESRI Docs for DWG files), or from %FILENAME%.prj file in the same directory. |
| 116 | 6. CAD Geometry attributes mapping is completely done into OGRLayerDefn. So, any ACAD BlockReference attributes will be seen in OGRLayerDefn. |
| 117 | |
| 118 | === Images === |
| 119 | |
| 120 | [[Image(https://pbs.twimg.com/media/Cm2N_-nVIAA8jBn.jpg, 320px)]] |
| 121 | |
| 122 | ''Raster and vector layers by the same driver (left - ArcGIS, right - QGIS).'' |
| 123 | |
| 124 | [[Image(https://pbs.twimg.com/media/CmwXIBnWcAAz22X.jpg, 320px)]] |
| 125 | |
| 126 | ''A little comparison between original data source (ACAD) and QGIS with new DWG driver.'' |
| 127 | |
| 128 | == Links == |
| 129 | |
| 130 | CAD support library: https://github.com/sandyre/libopencad |
| 131 | |
| 132 | Libopencad + GDAL fork: https://github.com/sandyre/gdal_libopencad |
| 133 | |
| 134 | Blog: http://gsoc2016gdaldwg.blogspot.ru/ |
| 135 | |
| 136 | Pull request: https://github.com/OSGeo/gdal/pull/145 |