Skip to contents

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.

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

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.

Examples

if (FALSE) { # \dontrun{
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)
} # }