[R-sig-Geo] problems creating shapefile

Roger Bivand Roger.Bivand at nhh.no
Tue Feb 18 14:37:49 CET 2014


On Tue, 18 Feb 2014, Gustavo Dalposso wrote:

> 1. I created a raster in R
> require(raster)raster<-rasterFromXYZ(dados)
> 2. I converted the raster into polygons
> pol <- rasterToPolygons(raster)
> 3. I want to export to shapefile.
> shapefile('polygon.shp',pol)
> Error: file.exists(extension(x, ".shp")) is not TRUE
> Can anyone tell me what happens. Some time I used this command and it created the shapefile


library(raster)
?shapefile

If you get confused by the reversed arguments in the method, do use 
rgdal::readOGR() and rgdal::writeOGR() directly, rather than from the 
raster::shapefile() method wrapper. Probably:

shapefile(x=pol, filename='polygon.shp') # Spatial method

not

shapefile(x='polygon.shp', stringsAsFactors=pol) # character method

Roger

> 	[[alternative HTML version deleted]]

Please do not post in HTML, only plain text.

>
> _______________________________________________
> 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 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list