Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
70d067a
try catch debug
andreapago Mar 20, 2017
7f953d1
debug of tiles not available
andreapago Mar 20, 2017
5abd690
looking to solve bug "subscript out of bounds"
andreapago Mar 20, 2017
e390af5
test to find the remaining bug(s)
andreapago Mar 22, 2017
0f1f6b4
-Seperate folder with all functions
Mar 22, 2017
61e4bdf
test with unique tiles
andreapago Mar 23, 2017
21b7156
changes to have it running properly
andreapago Mar 23, 2017
c11d2b5
with bug
Mar 23, 2017
2b8f564
several bugs corrected, more might need to be fixed...but on the way ;-)
andreapago Mar 23, 2017
54bc6a2
restored working neighbouring cropping
andreapago Mar 24, 2017
1022784
re-added check of presence of files to avoid stuck laszip
andreapago Mar 24, 2017
dd8d484
clened up some un-necessary files anymore+added garbace collection wh…
andreapago Mar 24, 2017
2f43186
maybe an option to solve the bug...
andreapago Mar 25, 2017
d3edfeb
last comment/de-comment
andreapago Mar 27, 2017
9641060
bug of merging solved with tolerance setting in merge
andreapago Mar 28, 2017
ff5240a
reintroduced parallel
andreapago Mar 28, 2017
e2445fb
bux fix extension
andreapago Apr 5, 2017
6965ff4
solved bug induced by fix_extent
andreapago Apr 5, 2017
85cea59
added check of extension of tiles that have to be valid in x and y di…
andreapago Apr 10, 2017
1337703
bug free (?)
andreapago Apr 10, 2017
47a3020
Merge branch 'marieke' into devel
andreapago Apr 10, 2017
1475cbe
functions to deal with the whole NL SVf computations, modified the pr…
andreapago Apr 14, 2017
ddc3340
added a check to avoid compute again SVF for the tiles that are split…
andreapago Apr 14, 2017
6d3c496
little improvement
andreapago Apr 14, 2017
8ec6aba
check of the extension of the main tile added
andreapago Apr 15, 2017
2dcb8f3
bug in merging due to crop that brings some files having just one dim…
andreapago Apr 18, 2017
e0f2c0f
latest changes to solve bug xmin xmax not available
andreapago Apr 18, 2017
98eb433
further bug fixed
andreapago May 11, 2017
010b239
added file to extract relevant tiles
andreapago May 18, 2017
eddcc76
copy and extraction of the relevant tiles for GMS
andreapago May 18, 2017
176ff12
few adapted function to work with files already in LAS format
andreapago May 18, 2017
66bd779
point computation SVF
andreapago May 23, 2017
5bbdee1
single point SVF computation + profiling
andreapago May 24, 2017
ffa20ea
Update README.md
andreapago May 24, 2017
5d2a305
Update README.md
andreapago May 24, 2017
1a5c430
added circular buffer
May 24, 2017
cf0f76e
chnages to the all tiles computation to handle bug of tile with no ne…
andreapago May 29, 2017
01175bb
Merge branch 'SanderPoint' of https://github.com/KNMI-DataLab/SkyView…
andreapago May 29, 2017
667de9f
progress bar( not worksing, but it should have https://stackoverflow.…
andreapago May 29, 2017
59089a8
extract line values
May 29, 2017
859b084
Merge branch 'SanderPoint' of https://github.com/KNMI-DataLab/SkyView…
May 29, 2017
2580968
height in the radius distance from a point at a given angle: working
andreapago May 31, 2017
e682577
forgot zero! ;-)
andreapago May 31, 2017
99aff4b
rm shadow package
Jun 1, 2017
827aa5c
Merge branch 'SanderPoint' of https://github.com/KNMI-DataLab/SkyView…
Jun 1, 2017
476f085
-Added functions to calculate line paths from tiles
Jun 1, 2017
df4dd33
-Added warning functions to calculate_path and lines_from_las
Jun 1, 2017
8a66d41
Added points Nadir
MariekeDirk Jun 6, 2017
3e70edc
SVF for the research of Nadir
Jun 6, 2017
011a4cb
example documentation function
Jun 7, 2017
76962e7
documentation functions SVF calculate path and lines from las
Jun 7, 2017
9b55bbd
function to extract point data from grids, uses over and extract (add…
Jun 7, 2017
9bf908d
Find all the tiles in bounding box, solved top row tiles
Jun 8, 2017
ae95765
function bounding box reinder returns all grid file names
Jun 8, 2017
eba479a
added functions to function folder
Jun 8, 2017
77fdbe7
added a first quick check if files are already computed. Have still …
andreapago Jun 8, 2017
40db959
code to check if the computed tiles are in the list of the Hague and …
andreapago Jun 12, 2017
4ad6d36
added RCurl
Jun 13, 2017
c445ff9
re organized some parts of the code computing missing tiles to compute
andreapago Jun 13, 2017
a95422a
small changes to adapt the SVF for computing left tiles in Eindhoven
andreapago Jun 14, 2017
853558c
Package structure with development documentation
Jun 15, 2017
50623e0
fixed error in a data file, now package is running withour errors
Jun 15, 2017
ae0ffb4
added Rd documentation for all functions, not fully complete (no cros…
Jun 15, 2017
3f5b15a
added part to handle Eindhoven export when all tiles are computed
andreapago Jun 15, 2017
2bebcb7
Package without errors, didnt add description file to data so tempora…
Jun 27, 2017
69845fe
With working shiny app example (leaflet + DT interaction)
Jun 29, 2017
0a4d725
added some fancy stuff to the shiny app
Jun 29, 2017
a7f5011
version for 200m max view SVF. Corrected the removal of temp (UUID) d…
andreapago Jul 6, 2017
81f83c9
Merge branch 'Reinder' into MakeAPackageR
andreapago Jul 7, 2017
841d6b3
added documentation of the SVF function
andreapago Jul 7, 2017
58596ba
minor changes, same error "cannot open connection"
Jul 7, 2017
50a5ce9
added .travis.yml
Jul 11, 2017
b13e309
Package without errors. To do: add description to data files in data …
Jul 18, 2017
a14bab8
master merged with MakeAPackageR
Jul 18, 2017
459762b
added travis Icon
Jul 18, 2017
8fe6767
added config file
Aug 14, 2017
e36def8
testing function to explore svf function
Mar 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache: packages
28 changes: 28 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Package: svfAHN2point
Type: Package
Title: Calculate the Sky view factor from las files
Version: 1.0
Date: 2017-06-15
Authors@R:person("Marieke", "Dirksen", email = "marieke.dirksen@knmi.nl",
role = c("aut", "cre"))
Maintainer: Who to complain to <marieke.dirksen@knmi.nl>
Description: More about what it does (maybe more than one line)
License: What license is it under?
Imports: data.table,
doParallel,
horizon,
leaflet,
magrittr,
methods,
raster,
RCurl,
rgdal,
rgeos,
rLiDAR,
R.utils,
shiny,
sp,
stringr,
stringi
RoxygenNote: 6.0.1

79 changes: 0 additions & 79 deletions GMS_SVF.Rmd

This file was deleted.

7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exportPattern("^[[:alpha:]]+")
importFrom("methods", "as")
importFrom("stats", "df")
importFrom("utils", "write.table")
importFrom("stringr","str_pad")
importFrom("raster","crop","extent","rasterize","res","crs","mask")
importFrom("rgeos","gBuffer")
File renamed without changes.
69 changes: 69 additions & 0 deletions R/SVF.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#' Sky view factor
#'
#' \code{SVF} Calculates the sky view factor from las point data and save raster files.
#' @description calculates the SVF
#'
#'
#' @param pointX x-coordinates
#' @param pointY y-coordinates
#' @param maxView viewing distance of the sky view factor
#' @param proj projection
#'
#' @seealso This function calls upon the following functions \code{\link{loadTile}}, \code{\link{makeSpatialDF}},
#' \code{\link{mergeNeighborTiles}}, \code{\link{makeRaster}},and from the horizon package \code{\link{svf}}.

SVF<-function(pointX, pointY, maxView, proj){


#tileNumberXCoord<-str_pad(as.integer(floor(pointX/1000)*1000), 6, pad = "0")
#tileNumberYCoord<-str_pad(as.integer(floor(pointY/1000)*1000), 6, pad = "0")

tileNumberXCoord<-pointX
tileNumberYCoord<-pointY

mainTile<-loadTile(lazFolder, as.integer(tileNumberXCoord), as.integer(tileNumberYCoord))
mainTile<-makeSpatialDF(mainTile,projection = pro)
extensionMainTile<-extent(mainTile)

neighbors<-mergeNeighborTiles(lazFolder, as.integer(tileNumberXCoord), as.integer(tileNumberYCoord), extensionMainTile, maxView, pro)

rasterizedNeighbors<-lapply(neighbors, makeRaster, Xres, Yres, pro)
mergedNeighbors<-do.call(merge, c(rasterizedNeighbors, tolerance =10))
rm(neighbors)
rm(rasterizedNeighbors)
rasterizedMainTile<-makeRaster(mainTile,Xres,Yres,pro)
rm(mainTile)
#rasterOptions(tolerance = 0.1)
fullRaster<-merge(rasterizedMainTile, mergedNeighbors, tolerance = 10)
rm(mergedNeighbors)
gc()

r.svf<-svf(fullRaster, nAngles=16, maxDist= maxView, ll=F)
out<-crop(r.svf,extent(rasterizedMainTile))

#to fix the small inconsistencies in the extention (sometimes small approx are introduced in the extent)
out<-fix_extent(rasterizedMainTile,out)

r.b<-brick(rasterizedMainTile,out[[1]])
names(r.b)<-c("Z","SVF")
r.df<-as.data.frame(r.b,xy=TRUE)

##############################################
###############SAVE FUNCTION##################
##############################################

#Writing the raster file with tile names
writeRaster(r.b,filename=paste0(output_dir,
str_pad(as.integer(floor(tileNumberXCoord/1000)*1000), 6, pad = "0"), "_",
str_pad(as.integer(floor(tileNumberYCoord/1000)*1000), 6, pad = "0"),".grd"),
format="raster",
overwrite=TRUE)

#Writing a table which will be appended if exists
write.table(r.df,file="NLSVF.txt",sep=",",row.names = FALSE, append = TRUE, col.names = !file.exists("NLSVF.txt"))
##############################################
##############################################
##############################################
rm(r.svf,r.b,r.df)
gc()
}
64 changes: 64 additions & 0 deletions R/SVFGMStest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#' Test function
#' @title Test function for a point dataset of the GMS
#' @description test function for the GMS dataset to calculate the SVF
#' @param pointX x-coordinates of the point in RD coordinates
#' @param pointY y-coordinates of the point in RD coordinates
#' @param proj projection
#' @param maxView maximum viewing distance of the svf calculation
#' @export

SVFGMSTest<-function(pointX, pointY, maxView, proj){


#tileNumberXCoord<-str_pad(as.integer(floor(pointX/1000)*1000), 6, pad = "0")
#tileNumberYCoord<-str_pad(as.integer(floor(pointY/1000)*1000), 6, pad = "0")

tileNumberXCoord<-pointX
tileNumberYCoord<-pointY

mainTile<-loadTileGMSFromLas(lazFolder, as.integer(tileNumberXCoord), as.integer(tileNumberYCoord))
mainTile<-makeSpatialDF(mainTile,projection = pro)
extensionMainTile<-extent(mainTile)

neighbors<-mergeNeighborTilesGSMTest(lazFolder, as.integer(tileNumberXCoord), as.integer(tileNumberYCoord), extensionMainTile, maxView, pro)

rasterizedNeighbors<-lapply(neighbors, makeRaster, Xres, Yres, pro)
mergedNeighbors<-do.call(merge, c(rasterizedNeighbors, tolerance =10))
rm(neighbors)
rm(rasterizedNeighbors)
rasterizedMainTile<-makeRaster(mainTile,Xres,Yres,pro)
rm(mainTile)
#rasterOptions(tolerance = 0.1)
fullRaster<-merge(rasterizedMainTile, mergedNeighbors, tolerance = 10)
rm(mergedNeighbors)
gc()

r.svf<-svf(fullRaster, nAngles=16, maxDist= maxView, ll=F)
out<-crop(r.svf,extent(rasterizedMainTile))

#to fix the small inconsistencies in the extention (sometimes small approx are introduced in the extent)
out<-fix_extent(rasterizedMainTile,out)

r.b<-brick(rasterizedMainTile,out[[1]])
names(r.b)<-c("Z","SVF")
r.df<-as.data.frame(r.b,xy=TRUE)

##############################################
###############SAVE FUNCTION##################
##############################################

#Writing the raster file with tile names
writeRaster(r.b,filename=paste0(output_dir,
str_pad(as.integer(floor(tileNumberXCoord/1000)*1000), 6, pad = "0"), "_",
str_pad(as.integer(floor(tileNumberYCoord/1000)*1000), 6, pad = "0"),"-GMS.grd"),
format="raster",
overwrite=TRUE)

#Writing a table which will be appended if exists
write.table(r.df,file="NLSVFGMS.txt",sep=",",row.names = FALSE, append = TRUE, col.names = !file.exists("NLSVFGMS.txt"))
##############################################
##############################################
##############################################
rm(r.svf,r.b,r.df)
gc()
}
79 changes: 79 additions & 0 deletions R/SVFWholeNL.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#' Calculate the SVF for the whole Netherlands
#' @title SVF Netherlands
#' @param filepath path to the LAS files
#' @param maxView maximum viewing distance for the sky view factor calculations
#' @export

SVFWholeNL<-function(filepath, maxView){
file<-basename(filepath)
splits<-unlist(strsplit(file, c("\\.")))
splits<-unlist(strsplit(splits[[1]], "_"))

tileNumberXCoord<-as.integer(splits[[2]])
tileNumberYCoord<-as.integer(splits[[3]])

mainTile<-loadTileWholeNL(filepath)
mainTile<-makeSpatialDF(mainTile,projection = pro)
extensionMainTile<-extent(mainTile)

if(xmax(extensionMainTile)!=xmin(extensionMainTile) & ymax(extensionMainTile)!=ymin(extensionMainTile))
{

neighbors<-mergeNeighborTiles(lazFolder, tileNumberXCoord, tileNumberYCoord, extensionMainTile, maxView, pro)

#neighbors<-lapply(neighbors,checkCoordinates)

rasterizedNeighbors<-lapply(neighbors, makeRaster, Xres, Yres, pro)
if(length(rasterizedNeighbors)==1){
mergedNeighbors<-rasterizedNeighbors[[1]]
}
else if (length(rasterizedNeighbors)==0){
return(-1)
}
else{
mergedNeighbors<-do.call(merge, c(rasterizedNeighbors, tolerance =10))
}
rm(neighbors)
rm(rasterizedNeighbors)
rasterizedMainTile<-makeRaster(mainTile,Xres,Yres,pro)
rm(mainTile)
#rasterOptions(tolerance = 0.1)
fullRaster<-merge(rasterizedMainTile, mergedNeighbors, tolerance = 10)
rm(mergedNeighbors)
gc()

r.svf<-svf(fullRaster, nAngles=16, maxDist= maxView, ll=F)
out<-crop(r.svf,extent(rasterizedMainTile))

#to fix the small inconsistencies in the extention (sometimes small approx are introduced in the extent)
out<-fix_extent(rasterizedMainTile,out)

r.b<-brick(rasterizedMainTile,out[[1]])
names(r.b)<-c("Z","SVF")
r.df<-as.data.frame(r.b,xy=TRUE)

##############################################
###############SAVE FUNCTION##################
##############################################

#Writing the raster file with tile names
writeRaster(r.b,filename=paste0(output_dir,
str_pad(as.integer(floor(tileNumberXCoord/1000)*1000), 6, pad = "0"), "_",
str_pad(as.integer(floor(tileNumberYCoord/1000)*1000), 6, pad = "0"),".grd"),
format="raster",
overwrite=TRUE)

#Writing a table which will be appended if exists
write.table(r.df,file="NLSVF.txt",sep=",",row.names = FALSE, append = TRUE, col.names = !file.exists("NLSVF.txt"))

}
else {
print(paste0("tile ", filepath, " with odd extention: ", as.character(extensionMainTile)))
}
##############################################
##############################################
##############################################
rm(r.svf,r.b,r.df,splits,file)
gc()
}

38 changes: 38 additions & 0 deletions R/calculate_path.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#' Calculate paths from a raster
#'
#' @title Calculate Path
#' \code{calculate_path} calculates the path for given distance, angles and coordinates from a raster file.
#'
#' @description calculates the path for different angles
#' @seealso This function is called in \code{\link{lines_from_las}}
#' @param theta angle or angles in degrees
#' @param x x-coordinates in meters (RDcoordinates)
#' @param y y-coordinates in meters (RDcoordinates)
#' @param distance distance for which the path should be calculated
#' @param rbuffer raster which is masked in \code{\link{lines_from_las}}
#'
#'
#' @export

calculate_path<-function(theta,x=x,y=y,distance,rbuffer){
dx<-cos(theta)*distance
dy<-sin(theta)*distance

x1<-x+dx
y1<-y+dy

xy1<-data.frame(x1,y1)

if(length(xy1$x1)!=length(distance)){
warning('Your vectors have different lengths, returning NULL')
return(NULL)
}
#XY<-rbind(c(x,y),xy1) #Bug!
XY<-cbind(xy1,distance)
XY<-data.frame(XY)

values<-raster::extract(rbuffer,XY[1:2],buffer=3,fun=mean,na.rm=TRUE)
XY<-cbind(XY,values)
names(XY)<-c("x","y","distance","height")
return(XY)
}
Loading