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.
Arguments
- path
Path to a
.dwgfile.- 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 of0.05.- quiet
Suppress progress messages. Defaults to
FALSE.
Value
A list of class "dwg2geo_result" with elements:
geojsonThe
FeatureCollectionas a JSON string (local drawing coordinates).feature_count,model_space_entitiesTotals.
converted,skipped,failedTibbles of per-entity-type outcomes;
skipped/failedinclude areasoncolumn.warningsCharacter vector of conversion warnings.
bboxNumeric
c(xmin, ymin, xmax, ymax)in drawing units, orNULL.source_sha256SHA-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)
} # }