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

stefan lhachimi stefan.duke at gmail.com
Tue Jan 22 22:31:21 CET 2008


Thanks! That worked great.
 I am also able now to merge new data into the map with the merge
command (I went to great length to show data in a map, always fearing
that its not matched properly). I guess this is kind of trivial if you
know your way around. But I never got a introduction to spatial
methods in R. So I am bascially trying around. It is rather difficult
to distinguish between the different classes for spatial objects.
Thanks again,
Stefan


On Jan 12, 2008 9:27 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> 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