Package {dwg2geo}


Title: Convert Engineering 'DWG' Drawings to Auditable 'GeoJSON'
Version: 0.2.5
Description: 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.'.
Copyright: The R interface and the 'dwg2geo' conversion core are copyright of the package authors. The bundled 'acadrust' crate, which reads the 'DWG' format, is copyright of Hakan AK and distributed under the Mozilla Public License 2.0; its source is included in src/rust/vendor.tar.xz and the license text in inst/COPYRIGHTS. See inst/AUTHORS for the copyright holders and licenses of all bundled 'Rust' crates.
License: MIT + file LICENSE
URL: https://milkway.github.io/dwg2geo-r/, https://github.com/milkway/dwg2geo-r
BugReports: https://github.com/milkway/dwg2geo-r/issues
Depends: R (≥ 4.2)
Imports: cli, jsonlite, rlang, tibble
Suggests: sf, testthat (≥ 3.0.0), withr
Config/testthat/edition: 3
Encoding: UTF-8
SystemRequirements: Cargo (Rust's package manager), rustc (>= 1.85)
NeedsCompilation: yes
Config/roxygen2/version: 8.0.0
Packaged: 2026-11-30 15:14:48 UTC; leite
Author: André Leite ORCID iD [aut, cre], Raydonal Ospina ORCID iD [aut], Hugo Vasconcelos ORCID iD [aut], Diogo Bezerra ORCID iD [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)
Maintainer: André Leite <leite@castlab.org>
Repository: CRAN
Date/Publication: 2026-11-30 16:00:33 UTC

dwg2geo: Convert Engineering 'DWG' Drawings to Auditable 'GeoJSON'

Description

logo

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.'.

Author(s)

Maintainer: André Leite leite@castlab.org (ORCID)

Authors:

Other contributors:

See Also

Useful links:


Read a conversion result as an sf object

Description

Parses the GeoJSON produced by dwg_convert() into an sf data frame. The geometry keeps the drawing's local coordinates and carries no CRS; set the known one explicitly with sf::st_set_crs() before any reprojection.

Usage

dwg_as_sf(result, quiet = TRUE)

Arguments

result

A "dwg2geo_result" object from dwg_convert().

quiet

Suppress the reading message. Defaults to TRUE.

Value

An sf object with one row per feature and the CAD style metadata as columns.

Examples

## Not run: 
shapes <- dwg_convert("drawing.dwg") |>
  dwg_as_sf() |>
  sf::st_set_crs(31983)

## End(Not run)


Convert a DWG drawing to GeoJSON

Description

Reads an AutoCAD 2013+ (AC1027) DWG file and converts its model-space entities to a GeoJSON FeatureCollection, entirely in-process, with no CAD software, LibreDWG, or GDAL required. Every feature carries resolved CAD style metadata (layer, color_rgb, color_index, linetype, lineweight_mm, text properties), and skipped or failed entities are reported with reasons.

Usage

dwg_convert(
  path,
  polygonize_closed = FALSE,
  curve_tolerance = NULL,
  quiet = FALSE
)

Arguments

path

Path to a .dwg file.

polygonize_closed

Convert closed polylines to polygons instead of line strings. Defaults to FALSE.

curve_tolerance

Maximum sagitta error, in drawing units, allowed when tessellating arcs, circles, ellipses, and splines. NULL (the default) uses the converter's default of 0.05.

quiet

Suppress progress messages. Defaults to FALSE.

Details

Coordinates are kept in the drawing's local system: dwg2geo never guesses a coordinate reference system. Georeference the result yourself: e.g. read it with dwg_as_sf(), set the known CRS with sf::st_set_crs(), and reproject with sf::st_transform().

The conversion is deterministic: the same bytes always produce byte-identical GeoJSON on a given platform.

Value

A list of class "dwg2geo_result" with elements:

geojson

The FeatureCollection as a JSON string (local drawing coordinates).

feature_count, model_space_entities

Totals.

converted, skipped, failed

Tibbles of per-entity-type outcomes; skipped/failed include a reason column.

warnings

Character vector of conversion warnings.

bbox

Numeric c(xmin, ymin, xmax, ymax) in drawing units, or NULL.

source_sha256

SHA-256 of the input bytes (audit trail).

Examples

## Not run: 
result <- dwg_convert("drawing.dwg")
result$feature_count
result$converted

# to sf, with an explicitly known CRS:
shapes <- dwg_as_sf(result) |>
  sf::st_set_crs(31983) |>
  sf::st_transform(4326)

## End(Not run)


Version of the embedded conversion core

Description

Version of the embedded conversion core

Usage

dwg_core_version()

Value

A string: the version of the Rust dwg2geo crate compiled into this package.

Examples

dwg_core_version()