I'm working on openlayers and need to change the format of dwg to GeoJSON with ArcGIS. how can i do this?
4 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.

- 21,988
- 13
- 81
- 109

- 1,525
- 1
- 11
- 15
-
Thank u so much. It was great.I have a problem to install GDAL and i am doing what you said and when i get it i'll say u what happend. – Mahdi Nazari Ashani Sep 03 '16 at 08:15
-
There is a problem in install GDAL i'have installed GDAL Proportionate my system(Windows)and python 2.7 after that i define my variable in advance setting but when i type 'gdalinfo-version' in cmd it seems that it have not installed i'm checking other ways if u know what is problem please say me.thank u – Mahdi Nazari Ashani Sep 04 '16 at 07:14
-
i found how to do that with autoCAD and [this website.][1] first i got .dgn Export from autoCAD an after that use above Website to change that to geoJSON and use that in my Map with [openlayers][2]. [1]: http://2geojson.com/ [2]: http://openlayers.org – Mahdi Nazari Ashani Oct 19 '16 at 10:05
-
but i gonna make an online web page that do this convert how can i do? – Mahdi Nazari Ashani Oct 19 '16 at 10:08
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"
-
for windows user, you can download the [latest release from GitHub](https://github.com/LibreDWG/libredwg/releases), 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"` – Gangula Sep 13 '22 at 10:09
-
@Gangula : great point thanks ! If you want you can edit my answer and add this point to it... – jossefaz Sep 13 '22 at 11:34
-
thanks for answer but I need to solve this problem with openlayers and arcGIS. i dont know GDAL and ogr2ogr and i'll check it – Mahdi Nazari Ashani Aug 29 '16 at 20:31
-
gdla/ogr2ogr will convert the dwg into geojson for openlayers/arcgis consumption. i'm not aware of any arcgis or openlayers specific converters, sorry. – albert Aug 29 '16 at 22:28
-
I think i get answer but there was a problem. I should get coordinates from auto cad or civil 3d and import to the arcgis but it is just for point .i need to change format of polygons to JSON – Mahdi Nazari Ashani Aug 30 '16 at 05:29
-
Can U help me to use GDAL. Im am biginner and dont know anything about GDAL .I Know javascript , openlayers .even i need to learn arcGIS – Mahdi Nazari Ashani Aug 30 '16 at 05:33
-
-
It dosen't matter to me i just wanna do this for knowing . I don't focus on a spicific file. – Mahdi Nazari Ashani Aug 31 '16 at 04:11
-
-
I have a file but i want to learn this and there s not any different to me – Mahdi Nazari Ashani Sep 03 '16 at 05:50
-
i'm confused here. if share the file, and i help you convert it, how will you not be learning? i'm going tot tell you what i did exactly. and i've seen the comments in the post below this, i know gdal is a pain to install. especially on windows. happy to help, just confused. – albert Sep 04 '16 at 01:34
-
i'm sorry. I am a geomatics eng student and i want to improve my web-gis Knowledge. So i started learning openlayers 3(a javascript library for mapping). Now i want to show an aouto cad file in the web pages by openlayers 3. openlayers dosen't support dwg ,... (auto cad files)and i have to use a format like 'geojson' I said "it is not important which auto cad file because i'm learning just. it can be each file". – Mahdi Nazari Ashani Sep 04 '16 at 07:29
-
i'm guessing you meant it can be any file. and in that case give me one. i don't have any laying around. – albert Sep 04 '16 at 14:59
-
exactly. maybe in future i gonna make a web application that can export ESRI or DWG to each other and it dosen't rely on a Specific file. – Mahdi Nazari Ashani Sep 04 '16 at 16:40
Possible that you also need to make match your coordinates from AutoCAD (if meter unit) to geojson (GPS coordinates).
- First: lambert 93 to select part of world area you aim.
- Second: 3 points to focus on affine transformations to adapt AutoCAD geometries (rotation, translation, scale).
You could have a look at this doc: https://github.com/open-indoor/openindoor6/blob/main/AUTOCAD.md
Also, a solution for DWG to DXF (ODAFileConverter in unattended Docker): https://github.com/open-indoor/dwg-to-dxf

- 91
- 1
- 4