Search code examples
javascriptopenlayersarcgis

How can I convert my CAD (DWG) file to GeoJSON?


I'm working with OpenLayers and I need to convert DWG files to GeoJSON format. How can I do this?


Solution

  • Indeed, GDAL has the necessary tools to get this done. ogr2ogr is a program included with GDAL that can transform a variety of formats, including DWG. If you don't already have GDAL installed, here are good tutorials for windows and mac/linux. The following guide recommends converting to a DXF first, since the library for converting from DXF is included by default with GDAL. You will need to install some additional dependencies to convert directly from DWG. If you convert to DXF first, you can then use command line to convert to GeoJson:

    ogr2ogr -f GeoJSON ./mynewfile.geojson ./mycadfile.dxf
    

    If you are using ArcGIS Desktop there is a CAD to Geodatabase tool that you can use.