Skip to content

save SpatialPolygonsDataFrame as dxf file

1 message · Milan Cisty

#
Thank for help. I did only one small correction, because solution from Roger
produce so called hatch objects in dxf. I used nlt = "MULTILINESTRING"
switch to prevent it. Final code is:

library(sp)
p = Polygon(coords = matrix(c(1,2,2,1,1,1,1,2,2,1), ncol = 2))
p1= Polygons(list(p), ID=1)
p2=SpatialPolygons(list(p1))
p3=SpatialPolygonsDataFrame(p2, data = as.data.frame("1"))
library(rgdal)
library(gdalUtils)
writeOGR(p3, dsn = "square1", layer = "entities", driver="GMT")  #layer MUST
be entities and final GMT is then called entities
ogr2ogr("entities.gmt", "square.dxf", "entities", "DXF", nlt =
"MULTILINESTRING")

Ends with error message but square.dxf is possible to open in AutoCAD, it is
dxf 2004 file. Only little beauty bug is that polygon is not closed. And of
course, only geometry is in final dxf file.
Thanks,
Milan

-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Tuesday, December 01, 2015 8:22 PM
To: Barry Rowlingson <b.rowlingson at lancaster.ac.uk>
Cc: Milan Cisty <milan.cisty at stuba.sk>; r-sig-geo <r-sig-geo at r-project.org>
Subject: Re: [R-sig-Geo] save SpatialPolygonsDataFrame as dxf file
On Tue, 1 Dec 2015, Barry Rowlingson wrote:

            
Right, thanks! Maybe gdalUtils::ogr2ogr? I got this far, but didn't check to
see whether a file was there. So I guess writeOGR is receiving an error
internally from the compiled code and gives up, while ogr2ogr creates the
file and reports an error later on.
works, with the error, but the DXF file can be read by OGR - but by other
software?

Roger
driver.
needs attributes.
--
Roger Bivand
Department of Economics, Norwegian School of Economics, Helleveien 30,
N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no