[R-sig-Geo] Fwd: Divide Voronoi cell using azimuth in R
Zhang Jiaqiang
zhangjiaqiang at gmail.com
Wed Sep 9 03:46:28 CEST 2015
Hi All,
The previous mail size exceeds the max size of the mailist. So I attached
my code here.
######## Here begin the R code ###########
set.seed(2014)
siteNum <- 24
# site, lng, lat
clat <- 1.29212
clng <- 103.83470
siteDF <- data.frame(letters[1:siteNum], clng + runif(siteNum, 0.01, 0.03),
clat + runif(siteNum, 0.01, 0.03))
colnames(siteDF) <- c('site', 'lng', 'lat')
head(siteDF)
# site, sector, azimuth, data
sectorDF <- data.frame(site = rep(letters[1:siteNum], each=3))
sectorDF$sector <- paste0(sectorDF$site, rep(1:3, siteNum))
sectorDF$azimuth <- c(0, 120, 240, 50, 190, 320, 30, 150, 270)
sectorDF$kpiA <- sapply(1:nrow(sectorDF), function(i) i * 10)
head(sectorDF)
data <- merge(siteDF, sectorDF)
head(data)
library(deldir)
voronoi <- deldir(siteDF$lng, siteDF$lat)
ggplot(data=siteDF, aes(x=lng,y=lat)) +
geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2),size = 2,data =
voronoi$dirsgs,linetype = 1,color= "#419AB0") +
geom_point(fill="#EACA3E",pch=21,size = 4,color="white") +
geom_text(aes(label=site),hjust=0, vjust=0)
######## Here end the R code ###########
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list