2

I want to read a DXF in R using RGDAL package. DXF is supported by RGDAL, but I am not able to read the file and I don't find information about this topic. With shapefiles I do not have any problems.

Here is my source-code:

library(rgdal)
library("rgeos")
library(RPostgreSQL)
my.layer <- readOGR(dsn = "./IN/Gear Sample-iss4.DXF", layer = "0")

Output:

Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open layer

Psidom
  • 209,562
  • 33
  • 339
  • 356
Raúl
  • 43
  • 2
  • 4
  • Try setting your directory path via "dsn = " and your layer name separately via "layer = ". This is the default behaviour for shapefiles. In your example you have a whitespace in your directory path in combination with the file name, which will cause trouble. Note also that the `readOGR` documentation states: "interpretation varies by driver — for some drivers, dsn is a file name, but may also be a folder". This means, that the procedure for shapefiles MAY not work for .dxf files. – pat-s Jul 07 '16 at 17:45
  • The space in the name is not the problem. I have found that the entire contents of the .dwg file is represented as a single layer named "entities". ` my.layer <- readOGR(dsn ="./IN/GearSampleiss4.DXF", layer ="entities")` – Raúl Jul 08 '16 at 10:57
  • More info: http://www.gdal.org/drv_dxf.html – Raúl Jul 08 '16 at 11:00

1 Answers1

0

The error is pretty straightforward: there is no layer named "0" in the file. For DXF, the layer name is set in the file... It would seem like yours uses a different name than the default "0".

Try listing the layers to confirm the name:

ogrListLayers("./IN/Gear Sample-iss4.DXF")
Benjamin
  • 11,560
  • 13
  • 70
  • 119