Share via

GIS from type DWS to GEOJSON

Dani_S 5,581 Reputation points
2025-10-30T12:54:34.8333333+00:00

Hi,

Can you please tell me how to convert this file to GEOJSON? שכבות מידע (AutoCAD).7z

Thanks

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


Answer accepted by question author

Gade Harika (INFOSYS LIMITED) 2,850 Reputation points Microsoft External Staff
2025-10-31T04:23:50.76+00:00

Thanks for reaching out.

To convert your AutoCAD .dwg file (inside the .7z archive) to GeoJSON, you have two main options:

Option 1: Using QGIS (Free & GUI-based)

  1. Download and install QGIS: https://qgis.org.
  2. Extract your .7z file to access the .dwg.
  3. Open QGIS → Layer → Add Layer → Add Vector Layer → select your .dwg.
  4. Once the DWG layers load, right-click the layer → Export → Save Features As.
  5. In the dialog:
    • Format: GeoJSON
      • File name: output.geojson
        • CRS: Choose the correct coordinate system.
        1. Click OK to export.

Option 2: Using GDAL (Command-line or C#)

Install GDAL: https://gdal.org.

Command-line example

 

ogr2ogr -f "GeoJSON" output.geojson input.dwg

C# example using GDAL bindings



using OSGeo.OGR;
using OSGeo.GDAL;

class DWGToGeoJSON
{
    static void Main(string[] args)
    {
        Gdal.AllRegister();
        Ogr.RegisterAll();

        string inputFile = @"C:\path\to\input.dwg";
        string outputFile = @"C:\path\to\output.geojson";

        DataSource ds = Ogr.Open(inputFile, 0);
        if (ds == null)
        {
            Console.WriteLine("Failed to open DWG file.");
            return;
        }

        Driver geoJsonDriver = Ogr.GetDriverByName("GeoJSON");
        if (geoJsonDriver == null)
        {
            Console.WriteLine("GeoJSON driver not available.");
            return;
        }

        DataSource outDs = geoJsonDriver.CreateDataSource(outputFile, null);
        for (int i = 0; i < ds.GetLayerCount(); i++)
        {
            Layer layer = ds.GetLayerByIndex(i);
            outDs.CopyLayer(layer, layer.GetName(), null);
        }

        Console.WriteLine("Conversion completed: " + outputFile);
    }
}

 

Tip: If your DWG has multiple layers, you may need to export each layer separately.

Let me know if the issue persists after following these steps. I’ll be happy to assist further if needed. If the issue has been resolved, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

 

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.