Skip to content

Commit

Permalink
Merge pull request #21 from MGousseff/ForReview4
Browse files Browse the repository at this point in the history
For review4
  • Loading branch information
MGousseff authored Aug 22, 2023
2 parents fa35bd9 + 07ec2e2 commit c7f3c17
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
23 changes: 8 additions & 15 deletions R/fetchLCZ.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,13 @@ fetchLCZ<-function(location,outDir,wf="bdtopo_2_2",refYear="2022",
folderToken<-1
}

if(file.exists(destFile)){
message('The zip file already exists')
if (file.exists(destLCZfile)){
message(' and the unzipped rsu_lcz.geojson file already exists
for this location and workflow.')}
else{message('and will be unzipped now.')
if (file.exists(destLCZfile)){message(' An rsu_lcz.geojson already exists in this directory. \n If you think it is not the proper file
try deleting it and re-running the fetchLCZ function.')} else
{ if(file.exists(destFile)) {
message('The zip file already exists and will be unzipped now.')
unzip(destFile,exdir=folder)}
}
else {
message('The zip file doesn\'t exist in the directory')
if (file.exists(destLCZfile)){
message(' but an rsu_lcz.geojson already exists in this directory. \n If you think it is not the proper file
try deleting it and re-running the fetchLCZ function.')}
else{
message('\n it will be downloaded and unzipped.')
else {
message('The zip file doesn\'t exist in the directory \n it will be downloaded and unzipped.')
try_fetch<-try(download.file(url=url,method="auto",destfile=destFile))
if(is(try_fetch,"try-error")){
warning("The file couldn't be downloaded, maybe the location wasn't proceeded by the GeoClimate team ?")
Expand All @@ -69,8 +61,9 @@ fetchLCZ<-function(location,outDir,wf="bdtopo_2_2",refYear="2022",
download.file(url=url,destfile=destFile)
unzip(destFile,exdir=folder)}
}
}
}
}




22 changes: 13 additions & 9 deletions R/produceAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ produceAnalysis<-function(location="Redon",
str(typeLevels)
if(length(args2)!=length(typeLevels)) stop("You must specify as many colors as there are groups")

output<-list()

# Download and import the first/reference dataset
if (wf1=="bdtopo_2_2"){
Expand Down Expand Up @@ -108,20 +109,20 @@ if(repr=="standard"){
condition<-((wf1=="osm" | wf1=="bdtopo_2_2") & (wf2=="bdtopo_2_2" | wf2=="osm"))
if((wf1=="osm" | wf1=="bdtopo_2_2") & (wf2=="bdtopo_2_2" | wf2=="osm")){
print("compareLCZ called")
return(
compareLCZ(sf1=df1, geomID1="ID_RSU", confid1="LCZ_UNIQUENESS_VALUE",

output$compare<-compareLCZ(sf1=df1, geomID1="ID_RSU", confid1="LCZ_UNIQUENESS_VALUE",
column1="LCZ_PRIMARY", wf1=wf1,
sf2=df2,
column2="LCZ_PRIMARY", geomID2="ID_RSU", confid2="LCZ_UNIQUENESS_VALUE",wf2=wf2,
ref=1,
repr="standard", saveG=nameG, exwrite=TRUE,outDir=outDir,location=location)
)


}

if(wf1=="wudapt"&& (wf2=="osm"|wf2=="bdtopo_v2")){

compareLCZ(sf1=df1,
output$compare<-compareLCZ(sf1=df1,
column1="EU_LCZ_map",
sf2=df2,
column2='LCZ_PRIMARY',
Expand All @@ -130,7 +131,7 @@ if(repr=="standard"){

if(wf2=="wudapt"&& (wf1=="osm"|wf1=="bdtopo_v2")){

compareLCZ(sf1=df1,
output$compare<-compareLCZ(sf1=df1,
column1='LCZ_PRIMARY',
sf2=df2,
column2="EU_LCZ_map",
Expand All @@ -147,7 +148,7 @@ if(repr=="standard"){

df1<-groupLCZ(df1,column="LCZ_PRIMARY",...)
df2<-groupLCZ(df2,column="LCZ_PRIMARY",...)
compareLCZ(sf1=df1,
output$compare<-compareLCZ(sf1=df1,
column1='grouped',
sf2=df2,
column2='grouped',
Expand All @@ -157,7 +158,7 @@ if(repr=="standard"){
if(wf1=="wudapt"&(wf2=="osm"|wf2=="bdtopo_2_2")){
df1<-groupLCZ(df1,column="EU_LCZ_map",...)
df2<-groupLCZ(df2,column="LCZ_PRIMARY",...)
compareLCZ(sf1=df1,
output$compare<-compareLCZ(sf1=df1,
column1='grouped',
sf2=df2,
column2='grouped',
Expand All @@ -166,7 +167,7 @@ if(repr=="standard"){
if(wf2=="wudapt"&(wf1=="osm"|wf1=="bdtopo_2_2")){
df1<-groupLCZ(df1,column="LCZ_PRIMARY",...)
df2<-groupLCZ(df2,column="EU_LCZ_map",...)
compareLCZ(sf1=df1,
output$compare<-compareLCZ(sf1=df1,
column1='grouped',
sf2=df2,
column2='grouped',
Expand All @@ -175,4 +176,7 @@ if(repr=="standard"){

}
# setwd(wd)
}
output$df1<-df1
output$df2<-df2
return(output)
}
4 changes: 2 additions & 2 deletions inst/tinytest/test_fetchLCZ.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ expect_message(fetchLCZ(location="Redon",
wf="bdtopo_2_2"), "The folder already exists.")
expect_message(fetchLCZ(location="Redon",
outDir=system.file("extdata", package = "lczexplore"),
wf="bdtopo_2_2"), "The zip file doesn't exist in the directory")
wf="bdtopo_2_2"), "rsu_lcz.geojson already exists in this directory")
expect_message(fetchLCZ(location="Redon",
outDir=system.file("extdata", package = "lczexplore"),
wf="bdtopo_2_2"),
"but an rsu_lcz.geojson already exists in this directory.")
"The folder already exists")
expect_warning(fetchLCZ(location="Clohars-Carnoët",
outDir=system.file("extdata", package = "lczexplore"),
wf="bdtopo_2_2"),"The file couldn't be downloaded")
2 changes: 1 addition & 1 deletion inst/tinytest/test_produceAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ expect_message(produceAnalysis(location="Redon",
system.file(package="lczexplore"),"/tinytest"),
wf1="bdtopo_2_2",
wf2="osm",refYear1="2022",refYear2="2022",repr="standard",saveG=location),
" but an rsu_lcz.geojson already exists in this directory"
" rsu_lcz.geojson already exists in this directory"
)

file.remove(paste0(
Expand Down

0 comments on commit c7f3c17

Please sign in to comment.