Convert Engineering 'DWG' Drawings to Auditable 'GeoJSON'

Converts engineering 'DWG' drawings ('AutoCAD' 2013+ format) to 'GeoJSON' entirely in-process, with no 'CAD' software, 'LibreDWG', or 'GDAL' required. Wraps the pure-Rust 'dwg2geo' conversion core < https://github.com/milkway/dwg2geo>, which reads the 'DWG' format with the third-party 'acadrust' library by Hakan AK < https://github.com/hakanaktt/acadrust> (Mozilla Public License 2.0), bundled with the package: every feature carries resolved 'CAD' style metadata (layer, colour, line weight, text), skipped and failed entities are reported with reasons, and the output is deterministic: the same bytes always produce byte-identical 'GeoJSON'. Coordinates are kept in the drawing's local system; the package never guesses a coordinate reference system. Not affiliated with 'Autodesk'; 'DWG' and 'AutoCAD' are trademarks of 'Autodesk, Inc.'.


dwg2geo dwg2geo hex logo

R-CMD-check License: MIT Website

Convert engineering DWG drawings to auditable GeoJSON from R, with no CAD software, LibreDWG, or GDAL required. dwg2geo wraps the pure-Rust dwg2geo conversion core as a native extension. The DWG file format itself is read by acadrust, a third-party Rust library by Hakan AK (MPL-2.0) that dwg2geo builds on; see License and credits.

What dwg2geo adds on top:

  • every feature carries resolved CAD style metadata (layer, color_rgb, color_index, linetype, lineweight_mm, text properties);
  • skipped and failed entities are reported with reasons; nothing is silently dropped;
  • the output is deterministic: the same bytes always produce byte-identical GeoJSON on a given platform;
  • coordinates stay in the drawing's local system, and the package never guesses a CRS. Georeferencing is explicit and in your hands.

Installation

# install.packages("dwg2geo")  # once on CRAN

# development version (needs Rust >= 1.85: https://rustup.rs)
pak::pak("milkway/dwg2geo-r")

Usage

library(dwg2geo)

result <- dwg_convert("drawing.dwg")
#> ℹ Converting 'drawing.dwg' (9.0 MB)...
#> ✔ Converted 11781 features from 2793 model-space entities.
#> ! Skipped 145 entities; see `$skipped` for reasons.

result
#> ── dwg2geo conversion ──────────────────────────────
#> • 11781 features from 2793 model-space entities
#> • source SHA-256: "1b8555f87365"…
#> • bbox (local units): [247024.4, 7398959] – [248911, 7400880]
#> ── Converted ──
#> # A tibble: 11 × 3
#>    entity_type count reason
#>    <chr>       <int> <chr>
#>  1 ARC          1839 <NA>
#>  2 CIRCLE        937 <NA>
#> # …

result$skipped
#> # A tibble: 4 × 4
#>   entity_type reason                              count sample_handles
#>   <chr>       <chr>                               <int> <list>
#> 1 ATTDEF      attribute definition template; …       46 <chr [10]>
#> # …

Georeference with sf

The GeoJSON keeps the drawing's local coordinates. Read it as an sf object, set the CRS you know the drawing uses, and reproject:

library(sf)

shapes <- dwg_convert("drawing.dwg") |>
  dwg_as_sf() |>
  st_set_crs(31983) |>       # SIRGAS 2000 / UTM 23S: you must know this
  st_transform(4326)

plot(shapes["layer"])

Why fail closed on CRS?

A DWG can be drawn in SIRGAS 2000 / UTM, a local engineering grid, millimetres, or arbitrary coordinates. GeoJSON that merely copies CAD coordinates can be syntactically valid while geographically wrong, so dwg2geo always returns local coordinates and leaves the CRS decision to you, explicitly.

The dwg2geo family

The same audited core is available everywhere: CLI + Rust crate · npm (WebAssembly) · PyPI · browser app (upload a DWG and see it on a map, entirely client-side).

License and credits

MIT © André Leite (see LICENSE). The bundled dwg2geo conversion core is MIT, by the same authors.

The package bundles and statically links third-party code, which remains the copyright of its authors:

  • acadrust by Hakan AK reads the DWG format. It is distributed under the Mozilla Public License 2.0 and used unmodified; its source is included in the source package (vendor/acadrust inside src/rust/vendor.tar.xz) and available from crates.io and its repository.
  • The other Rust crates the core depends on are vendored in the same archive. Most are used under the MIT license; a few are available only under Apache-2.0, BSD-3-Clause or Unicode-3.0.

inst/AUTHORS lists every bundled crate with its version, license and copyright holders, and inst/COPYRIGHTS reproduces the MPL-2.0 text and the notices of the crates that are not under MIT.

dwg2geo is not affiliated with, sponsored by or endorsed by Autodesk, Inc. or by the acadrust project. DWG and AutoCAD are trademarks of Autodesk, Inc.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("dwg2geo")

0.2.5 by André Leite, 3 days ago


https://milkway.github.io/dwg2geo-r/, https://github.com/milkway/dwg2geo-r


Report a bug at https://github.com/milkway/dwg2geo-r/issues


Browse source code at https://github.com/cran/dwg2geo


Authors: André Leite [aut, cre] , Raydonal Ospina [aut] , Hugo Vasconcelos [aut] , Diogo Bezerra [aut] , Hakan AK [cph] (Author of the bundled 'acadrust' Rust crate , which reads the 'DWG' format (MPL-2.0)) , Authors of the vendored Rust crates [cph] (see inst/AUTHORS)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports cli, jsonlite, rlang, tibble

Suggests sf, testthat, withr

System requirements: Cargo (Rust's package manager), rustc (>= 1.85)


See at CRAN