[R-sig-Geo] Location estimation methods based on multiple surfaces?

Andy Bunn bunn@ @end|ng |rom wwu@edu
Thu Jun 27 22:59:48 CEST 2019


Hello all. I’m probably reinventing the wheel here and wonder if somebody can point me in a better direction.

I have about 10 surfaces of signal strength (z) received at a transmitter. Here I’ll provide an example with four surfaces `r1`, `r2`, `r3`, `r4`.

    library(raster)
    library(gstat)
    set.seed(3178)
    n <- 100
    r0 <- raster(nrows=n, ncols=n,xmn=1, xmx=n,ymn=1,ymx=n)
    r0 <- as(r0,"SpatialGrid")
    pts <- data.frame(x=c(10,20,60,80,1,1,n,n),y=c(10,80,70,40,1,n,1,n),
                      id=c(1:4,rep(0,4)), z=c(c(rep(1,4)),rep(0,4)))

    pts <- SpatialPointsDataFrame(pts[,1:2],data=pts[,3:4])


    r1 <- idw(z~1,pts[c(1,5:8),],newdata=r0)
    r2 <- idw(z~1,pts[c(2,5:8),],newdata=r0)
    r3 <- idw(z~1,pts[c(3,5:8),],newdata=r0)
    r4 <- idw(z~1,pts[c(4,5:8),],newdata=r0)

    r1 <- raster(r1)
    r2 <- raster(r2)
    r3 <- raster(r3)
    r4 <- raster(r4)

I also have a series of points with signal strengths that correspond to each surface. The locations of these points is unknown. The task is to determine a location for each point. E.g., for `unknownXY`:

    # Extract a point. For the real data I would have the z data but not x and y
    cell2get <- floor(runif(1,1,n^2))
    unknownXY <- c(extract(brick(r1,r2,r3,r4),cell2get))

In this case there is a four-way intersection of the contour lines that I could find suing some kind of intersection technique (e.g., `rgeos::gIntersection`).


    # Here is the the contour for the unknown point on each raster
    plot(r1,axes=F)
    contour(r1,levels=unknownXY[1],add=TRUE)

    plot(r2,axes=F)
    contour(r2,levels=unknownXY[2],add=TRUE)

    plot(r3,axes=F)
    contour(r3,levels=unknownXY[3],add=TRUE)

    plot(r4,axes=F)
    contour(r4,levels=unknownXY[4],add=TRUE)

    # here are all 4 contours
    plot(r0,axes=F,col="white")
    contour(r1,levels=unknownXY[1],add=TRUE,drawlabels=FALSE,col="red")
    contour(r2,levels=unknownXY[2],add=TRUE,drawlabels=FALSE,col="blue")
    contour(r3,levels=unknownXY[3],add=TRUE,drawlabels=FALSE,col="purple")
    contour(r4,levels=unknownXY[4],add=TRUE,drawlabels=FALSE,col="green")

But there are times when, I think, that there will not be a completely pure intersection (e.g., the contours will not exactly overlap). In that case I’m wondering about using a probabilistic method for finding x,y for a given vector of z.

One thing I was thinking was calculating distances. E.g.,

    # calc distances
    r1d <- sqrt((unknownXY[1] - r1)^2)
    r2d <- sqrt((unknownXY[2] - r2)^2)
    r3d <- sqrt((unknownXY[3] - r3)^2)
    r4d <- sqrt((unknownXY[4] - r4)^2)
    plot(brick(r1d,r2d,r3d,r4d))

And them summing them:

    # Straight sum? Should they be weighted in some manner?
    rdSum <- sum(brick(r1d,r2d,r3d,r4d))
    plot(rdSum)

I could find the min value to get the ``best'' point:

    # Use min to get possible location. Seems easy to get trapped.
    rdSumMin <- rdSum == minValue(rdSum)
    plot(rdSumMin)

Or use a threshold value to get a series of locations that are the most likely:

    # Or use quantile to get possible locations?
    thresh <- quantile(rdSum, probs = c(0.01))
    rdSum99 <- rdSum < thresh
    plot(rdSum99)

What I’m wondering it whether there is a way of finding a surface that is explicitly probabilistic. What I’d like to do is be able to determine possible location with x% likelihood.

Any ideas, tips, tricks, appreciated.











	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list