On Sun, 15 Nov 2009, tom sgouros wrote:



Roger Bivand <roger.biv...@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.

OK. Once you've tried this - there are at least two pitfalls, one that the shapes (features) occur multiple times for each district that you have data for (districcts with multiple islands or parts), the other that the polygons/features do not match the data by ID for other reasons. This is never simple, never automatic, and rarely obvious.

In GIScience one uses the term "ontology" for different people's views of the world, in particular the data and data objects that they use. If you are combining boundaries (for a given date) from one source with its implicit "view of the world", and election data of different provenance, with a different "view of the world", say different IDs for the same units, you will always need to spend time working out how to match the data to the boundaries. The tools are there, but it isn't going to get automatic, and you'll have the same problems matching in a database or a GIS. The only exceptions are the trite ones, where the same organisation with the same view of the world is the source of the boundaries, the IDs, and the data to be assigned.


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.


With merge(), you always have to try things out until they come right. Perhaps reshape() is harder to use, but not by much. Both are powerful, but without experimenting, tough.

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.


OK, so perhaps improve the wiki?

Including a code snippet demonstrating your problem and posting a link to a simple data set (shape file plus election data) would be a more constructive way to proceed, no? The code in Ch 5 in our book on www.asdar.org covers a very similar case, and uses the functions and methods I suggested. Without your code, it is hard to be more specific than pointing you to the tools you need.

Roger

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





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