Skip to content

Commit 11d791c

Browse files
committed
Add metier renaming to comply with GRID when fit_to_GRID option at TRUE for regional shapefile fishing effort generation
1 parent 075bfd2 commit 11d791c

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

GenerateHarboursFiles.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ for (i in idx){
105105
}
106106

107107

108-
write.table(cbind(node=idx, name=sapply(rownames(port_names), function (x) paste(unlist(strsplit(x, " ")), collapse="_")) ),
108+
write.table(cbind(node=idx, name=sapply(as.character(port_names$port_name), function (x) paste(unlist(strsplit(x, " ")), collapse="_")) ),
109109
file= file.path(general$main.path.ibm, paste("harboursspe_", general$application, sep=''), "names_harbours.dat"), row.names=FALSE, col.names=TRUE, quote=FALSE)
110110

111111
cat(paste("Write names_harbours.dat in /harboursspe...done\n"))

GenerateVesselsFishingEffortGISLayers.R

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77

88
if (length(args) < 2) {
99
if(.Platform$OS.type == "windows") {
10-
general$application <- "testexample" # ...or myfish
11-
general$main_path_gis <- file.path("C:","Users","fbas","Documents","GitHub","DISPLACE_input_gis", general$application)
10+
general$application <- "balticRTI" # ...or myfish
11+
general$main_path_gis <- file.path("C:","Users","fbas","Documents","GitHub","DISPLACE_input_gis_all", general$application)
1212
general$main.path.ibm <- file.path("C:","Users","fbas","Documents","GitHub",paste("DISPLACE_input_", general$application, sep=''))
1313
general$igraph <- 56 # caution: should be consistent with existing objects already built upon a given graph
14-
14+
fit_to_GRID <- TRUE
1515
}
1616
} else {
1717
general$application <- args[1]
1818
general$main_path_gis <- args[2]
1919
general$main.path.ibm <- args[3]
2020
general$igraph <- args[4] # caution: should be consistent with existing vessels already built upon a given graph
21+
fit_to_GRID <- FALSE
2122
}
2223
cat(paste("START \n"))
2324

@@ -30,7 +31,7 @@
3031

3132
#!#!#!#!#!#
3233
#!#!#!#!#!#
33-
# choose your country
34+
# choose your country (and adapt below accordingly)
3435
ctry <- "DEN"
3536
#!#!#!#!#!#
3637
#!#!#!#!#!#
@@ -86,7 +87,15 @@
8687
}
8788

8889

89-
90+
# subset for the area of interest
91+
if(fit_to_GRID && general$application=="balticRTI"){
92+
library(maptools)
93+
handmade <- readShapePoly(file.path(general$main_path_gis, "MANAGEMENT", "wbaltic_wgs84")) # built in ArcGIS 10.1
94+
the_area <- sapply(slot(handmade, "polygons"), function(x) lapply(slot(x, "Polygons"), function(x) x@coords))
95+
in_area <- point.in.polygon(as.numeric(as.character(tacsatp[,'SI_LONG'])), as.numeric(as.character(tacsatp[,'SI_LATI'])), the_area[[1]][,1],the_area[[1]][,2])
96+
tacsatp <- tacsatp[in_area==1,]
97+
}
98+
9099

91100
xrange <- range(as.numeric(as.character(tacsatp$SI_LONG)), na.rm=TRUE)
92101
yrange <- range(as.numeric(as.character(tacsatp$SI_LATI)), na.rm=TRUE)
@@ -160,7 +169,12 @@
160169
levels(tacsatp$LE_MET_rough) [levels(tacsatp$LE_MET_rough) %in% c("OTB","OTT", "OTM", "PTB", "PTM" )] <- "Trawl"
161170
levels(tacsatp$LE_MET_rough) [levels(tacsatp$LE_MET_rough) %in% c("PS_", "SDN", "SSC")] <- "Seine"
162171

163-
172+
tacsatp$LE_MET_level6 <- factor(tacsatp$LE_MET_level6)
173+
if(fit_to_GRID){
174+
# alter the level 6 to fit the GRID fleet segment definition i.e. a combination of a gear and a target assemblage (!=level6)
175+
levels(tacsatp$LE_MET_level6) <- unlist(lapply(strsplit(as.character(levels(tacsatp$LE_MET_level6)), split="_"), function (x) paste(x[1], x[2], sep='_'))) # rename by simplifying for GRID
176+
}
177+
164178
# keep level 6 and built an OTHER metier
165179
levels(tacsatp$LE_MET_level6)
166180
agg_per_met <- tapply(tacsatp[tacsatp$SI_STATE==1, ]$LE_EFF_VMS, list(tacsatp[tacsatp$SI_STATE==1, ]$LE_MET_level6), sum, na.rm=TRUE)
@@ -200,7 +214,7 @@
200214

201215
# add midpoint of gridcell to dataset
202216
aggResult <- cbind(aggtacsatp, CELL_LONG=coordinates(grd)[aggtacsatp$grID,1], CELL_LATI=coordinates(grd)[aggtacsatp$grID,2])
203-
save(aggResult, file=file.path(general$main_path_gis, "FISHERIES", "SpatialLayers","2015_aggtacsatp.RData"))
217+
if(!fit_to_GRID) save(aggResult, file=file.path(general$main_path_gis, "FISHERIES", "SpatialLayers","2015_aggtacsatp.RData"))
204218

205219

206220
# loop over relevant activity/metier

0 commit comments

Comments
 (0)