[R-sig-Geo] save SpatialPolygonsDataFrame as dxf file
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Tue Dec 1 19:54:39 CET 2015
ogr2ogr on the command line does a better job. Having saved the square
as a shapefile I can do this:
$ ogr2ogr -f "DXF" output.dxf foo.shp
ERROR 1: DXF layer does not support arbitrary field creation, field
'Foo' not created.
- an error, but a file is created with features in it... ogrinfo tells me:
$ ogrinfo -al output.dxf
INFO: Open of `output.dxf'
using driver `DXF' successful.
Layer name: entities
Geometry: Unknown (any)
Feature Count: 1
Extent: (1.000000, 1.000000) - (2.000000, 2.000000)
Layer SRS WKT:
(unknown)
Layer: String (0.0)
SubClasses: String (0.0)
ExtendedEntity: String (0.0)
Linetype: String (0.0)
EntityHandle: String (0.0)
Text: String (0.0)
OGRFeature(entities):0
Layer (String) = 0
SubClasses (String) = AcDbEntity:AcDbHatch
ExtendedEntity (String) = (null)
Linetype (String) = (null)
EntityHandle (String) = 20000
Text (String) = SOLID
Style = BRUSH(fc:#000000)
POLYGON ((1 1,1 2,2 2,2 1,1 1))
It even reads back into R successfully:
> dx = readOGR("output.dxf","entities")
OGR data source with driver: DXF
Source: "output.dxf", layer: "entities"
with 1 features
It has 6 fields
there may be some magic incantation to writeOGR to do this, but until
a wizard appears you might be able to get by by saving as shapefile
(or other) and converting on the command line.
Barry
On Tue, Dec 1, 2015 at 5:41 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> On Tue, 1 Dec 2015, Milan Cisty wrote:
>
>> Hello,
>> I would like to save SpatialPolygonsDataFrame as dxf file. Sorry if I am
>> doing trivial mistake, but please what is wrong on this:
>>
>> p = Polygon(coords = matrix(c(1,2,2,1,1,1,2,2), ncol = 2)) #this is
>> square 1x1
>> p1= Polygons(list(p), ID=1)
>> p2=SpatialPolygons(list(p1))
>> p3=SpatialPolygonsDataFrame(p2, data = as.data.frame("1"))
>> writeOGR(p3, dsn = "square.dxf", layer = "entities", driver="DXF")
>>
>> and last command gave me following message:
>> Error in writeOGR(p3, dsn = "square.dxf", layer = "entities", driver =
>> "DXF") :
>> Creating Name field failed
>> (some dxf file was produced, but it has nothing drawn in it)
>
>
> No idea, nor can I find any example of how to use the file creation driver.
> This isn't a driver in active use anywhere really. I think that the issue is
> that DXF doesn't want attributes associated with geometries - to judge from
> copying p3 to GRASS and writing with v.out.dxf. writeOGR needs attributes.
>
> Roger
>
>> Thanks,
>> Milan
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> --
> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list