Skip to content
Prev 2929 / 29559 Next

point.in.polygon() on massive datasets

On Thu, 13 Dec 2007, Edzer Pebesma wrote:

            
That's right - as it is there is an lapply() on the Polygon objects in 
each Polygons object with hole handling inside an lapply() on the Polygons 
objects in the SpatialPolygons object.

res <- lapply(slot(xx, "polygons"), bbox)

gets the bbox'es of the xx SpatialPolygons* object, and you could build a 
fast searcher in C with code in spdep/src/insiders.c:

int between(double x, double low, double up) {
 	if (x >= low && x <= up) return(1);
 	else return(0);
}

int pipbb(double pt1, double pt2, double *bbs) {
 	if ((between(pt1, bbs[0], bbs[2]) == 1) &&
 		(between(pt2, bbs[1], bbs[3]) == 1)) return(1);
 	else return(0);
}

in a compiled loop. You'd look to get a list 50M long with integer vectors 
for candidate members, then only do p-in-p for the candidate Polygons 
objects.

Roger