[R-sig-Geo] newbie questions

tom sgouros tomfool at as220.org
Mon Nov 16 01:05:42 CET 2009



Roger Bivand <Roger.Bivand at nhh.no> wrote:

> > 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.

Where is the introduction that explains all this?  Is there one
somewhere?   (And thank you for the assistance.)

> 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.

Thank you very much for all that, it gives me a lot to try.

> > 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.

Thank you for the help, but no thank you for the snide.  What the help
file says (on my system) is that if you do sort=FALSE, the output order
is unspecified, which is approximately zero help for someone trying to
figure out why the output map looks so funny.

> 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
> 

Yes.  I can't say I found those pages very helpful since they are mostly
written in a language I don't understand, and where I do understand what
they're saying, they're saying things like this: 

 "Use a GIS if you're trying to do the following:

    - specialized GIS tasks"

In the nicest and most constructive way I can think of, I have to say
that this isn't very helpful to the person who has data they want to map
and wants to get on with it.  I have been a R user (and fan) for years
and am more or less familiar with much of it, but I haven't used it for
spatial data, and I find the available documentation for people who are
starting from zero like me is fairly wanting.

Many thanks,

 -tom


> 
> >
> > 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
b> > 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.Bivand at nhh.no
> 


-- 
 --------------------------------------------------------
 Check out "Ten Things You Don't Know About Rhode Island"
     http://whatcheer.net      http://sgouros.com



More information about the R-sig-Geo mailing list