[R-sig-Geo] save polygon as a shape file

Roger Bivand Roger.Bivand at nhh.no
Sat Jan 12 21:27:09 CET 2008


On Sat, 12 Jan 2008, stefan lhachimi wrote:

> Hello,
>
> I loaded a .shp-file and used a subset command while converting it
> into a polygon to eliminate certain regions:
>
> map.kreise<-readShapePoly("vg250krs",IDvar="KRS_ID",verbos=TRUE)
> map.kreise.boden <-polygons(map.kreise)[x$BODENSEE==0]

Why polygons()? It returns a SpatialPolygons object. To select the 
polygons and the data frame rows, you need:

map.kreise.boden <- map.kreise[x$BODENSEE==0,]

(note the extra comma) where:

writePolyShape(map.kreise.boden, "mapohnebodensee")

will just work. A shapefile cannot only have geometries, it must have 
attribute data. The documentation does say that the first argument to 
writePolyShape should be a SpatialPolygonsDataFrame, and you can check 
with:

class(map.kreise.boden)

Roger

>
> Now I want to save the new object map.kreise.boden as a shp-file again
> (I want to usethe new shp-file without certain regions into GEODA).
> The writePolyShape-command does not work. It gives me the following
> error message:
>
> writePolyShape(map.kreise.boden, "mapohnebodensee")
> Fehler in as(x, "data.frame") :
>  no method or default for coercing "SpatialPolygons" to "data.frame"
>
> Any help is appreciated.
> Best,
> Stefan
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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