On Sun, 15 Nov 2009, Tom Sgouros wrote:


Hello all:

I'm trying to make some simple maps of election results and I am having
some trouble.  I'm hoping to use Grass (or QGis) to make the maps, but
apparently this requires getting my data into the shape files, and I
can't figure out how to do that.  I've found read.shape and that's

Please do not use read.shape(), it is deprecated, and will become unavailable at the user-visible level at the next maptools release.

Do use readShapeSpatial() (or better readOGR() in rgdal) to create a SpatialPolygonsDataFrame, paying attention to the ID= argument. Then use spCbind() and if necessary spChFIDs() to ensure that your data are being associated with the correct Polygons object inside the SpatialPolygonsDataFrame. Then use writeSpatialShape() (or writeOGR()) to write the shapefile.

great, and I thought that by editing the resulting att.data data frame I
could do what I need.  Unfortunatly, if I use merge to combine my data
with the existing data, the data frame comes out sorted by the join
column and the output dbf file (done with write.dbf) doesn't work
properly with the shapefile because it's no longer sorted the same as
the outlines.

Using merge() without reading the help file usually has this outcome - there are arguments controlling sorting.

Hope this helps,

Roger

PS. Did you read the Spatial task view on CRAN, or, say, the page on the R wiki entitled "Getting spatial data into and out of R":

http://wiki.r-project.org/rwiki/doku.php?id=tips:spatial-data:import_export



I tried preserving the original order of the data frame and re-sorting
the data frame before writing it out, and that worked, but the resulting
dbf file causes a seg fault in Grass when I try to read it with the rest
of the shape data.  Plus it seems a ridiculous amount of work for what
must be a fairly routine operation.

So here's my question: I have some data I want to add to a shape file
(the SHP, DBF, etc).  Can I use R maptools to do that easily, and if so,
how?

Many thanks in advance for the help,

-tom




--
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.biv...@nhh.no

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to