# NOT RUN {
library(spatstat)
library(rgdal)
library(sp)
proj4string(bndShp) # Current system
projUTM <- CRS("+proj=utm +zone=14 +units=m") # isotropic coordinate sytem
bndUTM <- spTransform(bndShp, projUTM) # Re-project boundary
storesUTM <- spTransform(foodStoresShp, projUTM) # Re-project points
storesDf <- as.data.frame(storesUTM) # Extract data-frame
storesPts <- as.ppp(storesUTM) # Convert to .ppp
storesPts$marks <- NULL # Clear marks
bndWin <- as.mask(as.owin(bndUTM), eps=200) # pixel window with 200 m resolution
unitname(bndWin) <- list("meter","meters") # set units
storesPts <- storesPts[bndWin] # assign window to pts
summary(storesPts)
## Evaluate weighted kernel density with bw=3000
allFoodIm <- density(storesPts, weights=storesDf$FOODSALES, sigma=3000)
plot(allFoodIm, main="All Stores Weighted Kernel Density\nbw = 3000 m")
plot(storesPts, cex=0.5, pch=16, col="green", add=TRUE)
box(); axis(1); axis(2)
# }
Run the code above in your browser using DataLab