[R-sig-Geo] [Qgis-user] spatial join, many to 1

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Oct 23 08:14:52 CEST 2012



On 10/22/2012 10:54 PM, Frazier, Tyler James wrote:
> Hi Barry,
> 
> Really what I am trying to do is link raw census DATA to an enumeration area MAP, which spatially represents different aggregations of those observations.  In order to do so, on the MAP side, I first want to join a point shape file which has all of the town names to an enumeration area shape file, which is missing those names.
> 
> Previously, when I did this on the DATA side I used the following command ---
> 
> enum_areas <- aggregate(localities_region1,by=list(localities_region1$ea_code), FUN=unique)
> 
> and when an enumeration area had more then one town located within it, R created a field within a row as follows ---
> 
> c("NEW-TOWN WHARF", "BALIBANGARA", "BOLENWO").

I don't think R can hold such a structure in a data.frame. Of course,
with lists it can do any nesting, but they are not tables.

> 
> On the MAP side, it appears when I use the over() command, like so ---
> 
> spatial_join <- over(ea_map, towns)
> 
> over() supplies only the name of the first town listed within that enumeration area and ignores/omits the remainder.  If over() created all of the names in a similar manner as aggregate(), couldn't I then use

As I mentioned before, when you supply over with the returnList = TRUE
argument, it will return all matches, just not in a table (as a table is
not very useful in this case).

> 
> map <- SpatialPolygonsDataFrame(ea_map,spatial_join)
> 
> in order to create my map?  What do you think?

Which property of towns do you want in ea_map? If, for instance, you
want the population of towns in ea_map, you could do (untested, we don't
have your data):

pop = aggregate(towns["population"], ea_map, sum)

> 
> I suppose it would be possible to achieve the same using postGIS and some commands there, but would rather take a route within R.  I haven't thought about how to use tapply() yet.

Showing us the PostGIS route might help us (and maybe yourself)
understand what you want.

> 
> Thanks!
> Ty
> 
> 
> On Oct 22, 2012, at 10:02 PM, Barry Rowlingson wrote:
> 
> On Mon, Oct 22, 2012 at 7:52 PM, Frazier, Tyler James
> <tyler.j.frazier at tu-berlin.de<mailto:tyler.j.frazier at tu-berlin.de>> wrote:
> Hi Edzer and list,
> 
> Thanks for the package, the command over() essentially achieves my intended result, which is to overlay a set of (2500) points onto a set of (1000) polygons where each polygon receives all of the attribute data from each of the points located within its boundary.
> 
> Each polygon can't [easily] 'receive' the attributes from a differing
> number of points. The SpatialPolygonsDataFrame has one polygonal
> feature related to one row in the data frame. You could have one
> polygonal feature for each point, but that would end up as a massive
> duplication of the polygonal data.
> 
> It would seem to be better to create a new *point* data set, where
> each row of the point data frame is augmented with the information
> from the polygon in which it resides. This gives you something like an
> ID variable that relates the points to the polygons in the manner of a
> database id field.
> 
> Overall, it really depends on what you want to do. If you want to
> draw maps of polygons based on some aggregate function of the points
> within, then that's a question of doing something like a 'tapply' on
> the points using the polygons each point is in as a factor.
> 
> Barry
> 
> -----
> Tyler Frazier
> Department of Transportation Planning and Telematics
> Technical University Berlin
> http://www.vsp.tu-berlin.de/
> 
> 
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list