Package {dwg2geo}


Title: Convert Engineering 'DWG' Drawings to Auditable 'GeoJSON'
Version: 0.2.4
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: 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.
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
RoxygenNote: 7.3.3
SystemRequirements: Cargo (Rust's package manager), rustc (>= 1.85)
NeedsCompilation: yes
Packaged: 2026-08-04 22:43:28 UTC; leite
Author: André Leite [aut, cre]
Maintainer: André Leite <leite@castlab.org>
Repository: CRAN
Date/Publication: 2026-08-05 08:20:28 UTC

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

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

Author(s)

Maintainer: André Leite leite@castlab.org

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()