creating polygons
On Thu, 23 Apr 2009, Alina Sheyman wrote:
I went back to the help page, but it still didn't clarify it for me. Yes, the two files are different length, but both have a zip variable that they can match on and then keep only those records that match. Or do I need to additionally create an index for the match to occur? I am understanding it that unionSpatialPolygons functions works very much in the same way as merge, except with geographical data. Am I wrong in this assumption?
Wrong, as you can see. That isn't how it works. As input, you have n Polygons objects in a SpatialPolygons object (with no variables at all, no data slot), as output m Polygons objects in a SpatialPolygons object. The IDs argument assigns the (possibly multiple) n input Polygons objects to the m output Polygons object, which means that IDs must be of length n, and express which j=1,m each i=1,n belongs to. So if you do length(IDs), it must equal n, and length(unique(IDs)) will equal m. Not complicated, not merge, but hard work if you don't have a list of zips broken down by districts that lets you create the IDs easily. Hope this helps, Roger
On Wed, Apr 22, 2009 at 3:09 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
On Tue, 21 Apr 2009, Alina Sheyman wrote: Hi Roger,
Alina, Don't take this offlist, summarise to the list when done so that others can learn from your experiences. when I follow the example in maptools
coordinates(mass) <- c("lat", "long")
reg4 <- unionSpatialPolygons(zipmaps3, mass$center_id)
Right, you have not read the unionSpatialPolygons help page carefully, have you? Do: length(mass$center_id) length(slot(zipmaps3, "polygons") They differ - your mass are the districts, zipmaps3 are the zips. zipmaps3 has a variable giving the district IDs, what is it called? If you do table(zipmaps3$district_IDs) you see the numbers of zips in each district. This is your second argument to unionSpatialPolygons; it tells the functions which zips belong to each district. If you don't have such a variable, you'll have to make it. This is all explained on the help page, and in the example. It is very much like the other tapply(), by() and aggregate() functions, but only returns the geometries. Hope this helps, Roger
I get the following error message Error in unionSpatialPolygons(zipmaps3, mass$center_id) : input lengths differ Do you know why that is? Do I in fact need to have two files of identical length in order for the function to work? thank you On Tue, Apr 21, 2009 at 3:17 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote: On Tue, 21 Apr 2009, Alina Sheyman wrote:
To rephrase my question and explain my problem further
I have already created a map for revenue by zip code, in the state of Massachusetts. To accomplish that I used a shapefile for Massachusetts and a dataframe with my revenue/zip codes. What I am trying to do now is to have the same map done not by zip code, but rather by districts, as defined by zip codes. Basically what I've done was to introduce a new variable "district" into my dataset along with a zip code. At the same time my basic state map (by zip) still comes from a shape file and I can't introduce a new variable into the shape file. Does anyone know if there's any way I can accomplish what I'm trying to do or do I basically need to create a new shapefile with districts already in the file?
OK, that wasn't too clear before. Look at unionSpatialPolygons() in maptools - it will take a vector of districts matching all your zip codes, and join together the geometries belonging to each district, dropping internal boundaries. The district IDs become the Polygons object IDs. There is no data frame in the object, because it isn't obvious how you might want to aggregate it. Hope this helps, Roger On Mon, Apr 20, 2009 at 5:53 PM, Don MacQueen <macq at llnl.gov> wrote:
This is a pretty general question, and there are potentially many ways to
do it. One way to get started would be to follow the example(s) in the help page for the overlay() function in the sp package. -Don At 1:26 PM -0400 4/20/09, Alina Sheyman wrote: I have a list of made-up districts and corresponding zip codes. Based
on
that I want to define my own polygons (for each district) and then use
them
to create a map. Does anyone know how I would go about defining these?
thank you
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https:// stat.ethz.ch/mailman/listinfo/r-sig-geo
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
--------------------------------------
[[alternative HTML version deleted]]
_______________________________________________ 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
-- 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
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