Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm working on openlayers and need to change the format of dwg to GeoJSON with ArcGIS. how can i do this?

like image 404
Mahdi Nazari Avatar asked Aug 29 '16 20:08

Mahdi Nazari


People also ask

Can Autodesk viewer convert files?

View or convert with DWG TrueView View DWG files or convert them to work with older versions of AutoCAD software. Add Design Review to mark up 2D and 3D files without the original design software. For greater flexibility consider Autodesk Viewer or AutoCAD web app.

Can you convert a DWG to a 3D model?

SOLIDWORKS includes an Import Wizard to allow DWG/DXF files to be imported directly into the sketcher – from there it can easily be turned into a 3D model.


3 Answers

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.

like image 137
jOshT Avatar answered Oct 08 '22 21:10

jOshT


Even if GDAL is a good and working solution for DXF file (which are CAD files too)

Since the OOP asks about DWG file, I would suggest to use the LibreDWG library that support conversion from DWG to GeoJSON files and has very good performance.

You can use it like so :

dwgread <input_file_path> -O GeoJSON -o <output_file_path>

There are also many other commands provided by this fantastic library. I am also currently work on an open source project Geofiles-convertor Rest API which is a REST API that aims to make popular geofiles format conversion easier. It is also based on both GDAL and LibreDWG and there is a Docker image ready to run.

Windows Users

For Windows users, you can download the latest release from GitHub (win32.zip or win64.zip), which has dwgread.exe file.

You can then open a terminal in the downloaded folder location and run the command dwgread.exe "D:\path\to\file.dwg" -O GeoJSON -o "D:\path\to\output.json"

like image 38
jossefaz Avatar answered Oct 08 '22 22:10

jossefaz


GDAL can be used to do this, and I want to say ogr2ogr too, but not 100%.

like image 26
albert Avatar answered Oct 08 '22 23:10

albert