Hi Jose, If I understand correctly, some of the points lie outside of the polygons, but you want to pick up the information for the nearest associated polygon?
I think the easiest thing to do would be to put a buffer around each of the points (you could specify 50 m if it is in projected coordinates), converting them to polygons, and then your task becomes an intersection of two different polygon objects. I haven't done this type of operation in R, but I suspect you could find your answer with the following functions: library(sp) ?over library(rgeos) ?gBuffer ?gIntersects I suggest putting up a subset of your data illustrating the problem, and then maybe someone else who has a better idea on polygon to polygon intersects/overlays could suggest the method. Cheers, Lyndon On Tue, Jan 10, 2012 at 3:33 PM, Jose Bustos Melo <jbustosm...@yahoo.es>wrote: > Hi Lyndon, > > I really apreciate you help. Your function was very helpfull. However, in > this case polygons are block (block where many homes are). The avenue and > street aren't assigned at any polygon, so if a point is out of a polygon is > there any way to get it inside the nearest polygon?. For example, any point > near (50 meters) the polygon should correspond to that polygon. So, it this > way I could change the precision of the estimation, don't you? > > Than you in advance! > José > > ------------------------------ > *De:* Lyndon Estes <lyndon.es...@gmail.com> > *Para:* Jose Bustos Melo <jbustosm...@yahoo.es> > *CC:* "r-sig-geo@r-project.org" <r-sig-geo@r-project.org> > *Enviado:* martes 10 de enero de 2012 15:21 > *Asunto:* Re: [R-sig-Geo] Spatial join using shapefiles with R > > Hi Jose, > > This function might help with what you want to do. > > Cheers, Lyndon > > IntersectPtWithPoly <- function(x, y) { > # Extracts values from a SpatialPolygonDataFrame with > SpatialPointsDataFrame, and appends table (similar to > # ArcGIS intersect) > # Args: > # x: SpatialPoints*Frame > # y: SpatialPolygonsDataFrame > # Returns: > # SpatialPointsDataFrame with appended table of polygon attributes > > # Set up overlay with new column of join IDs in x > z <- overlay(y, x) > > # Bind captured data to points dataframe > x2 <- cbind(x, z) > > # Make it back into a SpatialPointsDataFrame > # Account for different coordinate variable names > if(("coords.x1" %in% colnames(x2)) & ("coords.x2" %in% colnames(x2))) { > coordinates(x2) <- ~coords.x1 + coords.x2 > } else if(("x" %in% colnames(x2)) & ("x" %in% colnames(x2))) { > coordinates(x2) <- ~x + y > } > > # Reassign its projection if it has one > if(is.na(CRSargs(x@proj4string)) == "FALSE") { > x2@proj4string <- x@proj4string > } > return(x2) > } > > > > > On Tue, Jan 10, 2012 at 1:06 PM, Jose Bustos Melo <jbustosm...@yahoo.es>wrote: > > Hi everyone, > > Its have been very difficult to do an spatial join with R and I couldn't > find any good manual about it. So, I will explain it if someone is willing > to help. > > I have one Shapefile with poligons (with its number) and another Shapefile > with xy points. My idea is to obtain the number of the polygons where the > points are found, in order to obtain their social data of those polygons. > > How can I do it? Is there any good way to do it? Where can I find > informationa bout it? Any function? > > Thanks in advance > José > > [[alternative HTML version deleted]] > > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > > > > [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo