knitr::opts_chunk$set(echo = TRUE)

# PAQUETES
  #require(xtable)
library(sf)
#library(raster)
library(dplyr)
library(spData)
library(spDataLarge)
library(tmap)    # for static and interactive maps
library(leaflet) # for interactive maps
library(mapview) # for interactive maps
library(ggplot2) # tidyverse vis package
#library(shiny)   # for web applications
library(sp)    # distancia costa
library(rgeos) # distancia costa
library(dplyr) # manejos de datos
#library(nnet)  # red neuronal
library(shape) # mapa_vms
library(lubridate) # manejo de fechas
#library(ineq)
library(DT) # reporte
library(maps) # mapa
library(mapdata) # mapa
library(rgdal) # sh map peru
library(data.table) # formato tm

#source("funciones.R")
  #load("C:/Users/fenix/Documents/sisesat/output.RData")
  datos_vms$Name_Vessel <- datos_vms$Name_vessel
  index1 <- indicadores1(data = datos_vms)
  index2 <- indicadores2(data = datos_vms)
  #index_totales <- merge(index1, index2, by = "fecha")

  # cargamos el shapefile de peru


  # generamos los puntos de pesca en formato tm
  datos_plot <- datos_vms[!is.na(datos_vms$Lon_calas), c("Name_Vessel",  "Date", "Lon_calas",                                                               "Lat_calas", "dist_costa")]
  datos_plot$fecha <- format(datos_plot$Date, format = "%Y-%m-%d")
  datos_plot$lance <- 1
  datos_plot$Name_Vessel <- paste0(datos_plot$Name_Vessel, " ",datos_plot$Date," (", ... =   round(datos_plot$Lon_calas,3),";", round(datos_plot$Lat_calas,3),")")
  datos_plot <- datos_plot[, c("Name_Vessel",  "fecha", "lance","Lon_calas",                                                               "Lat_calas", "dist_costa")]
  DT <- data.table(datos_plot)
  DT_sf = st_as_sf(DT, coords = c("Lon_calas", "Lat_calas"), 
                 crs = 4326, agr = "constant")

  # generamos el mapa en formato tm
  map_per = tm_shape(shape) + 
  tm_borders(col = "gray", lwd = 3) +
  tm_shape(DT_sf) +
  tm_bubbles("lance", col = "grey30", scale=.05) 

   # generamos segundo mapa areas iso
  # area <- area_isoparalitoral(dist_costa = datos_plot$dist_costa, latitude = datos_plot$Lat)
  # area_iso   <- area$area[!is.na(area$area)]
  # datos_plot <- datos_plot[!is.na(area$area),]

  # centro_areaIso <- centroidAssigner(code = area_iso, what = "isoparalitoral")
  # datos_plot$areaIso <- centro_areaIso$code
  # datos_plot$Lon_areaIso <- centro_areaIso$lon
  # datos_plot$Lat_areaIso <- centro_areaIso$lat


  # areaIso_lonlat      <- lapply(split(datos_plot, datos_plot$areaIso, drop = TRUE),function(x){
  #   areaIso <- x$areaIso
  #   lon     <- x$Lon_areaIso
  #   lat     <- x$Lat_areaIso
  #   num_lances <- length(x$areaIso)
  #   
  #   cbind.data.frame(areaIso, lon, lat, num_lances)
  # })

  # areaIso_lonlat <- areaIso_lonlat %>% lapply(data.frame) %>% bind_rows()

  # DT2 <- data.table(areaIso_lonlat)
  # DT_sf2 = st_as_sf(DT2, coords = c("lon", "lat"), 
  #                crs = 4326, agr = "constant")

  #map_per2 = tm_shape(shape) + 
  #tm_borders(col = "gray", lwd = 2) +
  #tm_shape(DT_sf2) + 
  #tm_symbols(size = "num_lances", title.col="Numero de lances",  col="num_lances", #shape="num_lances"
  #legend.format = list(text.align="right", text.to.columns = TRUE)) +
  #tm_legend(outside = TRUE, outside.position = "bottom", stack = "horizontal")
  1. Esfuerzo pesquero
datatable(index1, extensions = 'Buttons', options = list(
    dom = 'Bfrtip',
    buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
  )
  )%>% 
    formatStyle('n_lances', fontWeight = styleInterval(3, c('normal', 'bold'))) %>%
    formatStyle(
      'dur',
      color = styleInterval(24, c('black', 'black')),
      backgroundColor = styleInterval(24, c('gray', 'yellow'))
    )  %>%
    formatStyle(
      'rec_mean',fontWeight = styleInterval(200, c('normal', 'bold')))
  1. Indicadores espaciales de la flota
datatable(index2, extensions = 'Buttons', options = list(
    dom = 'Bfrtip',
    buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
  )
  )%>% 
    formatStyle('dc_mean', fontWeight = styleInterval(30, c('normal', 'bold'))) %>%
    formatStyle(
      'area',
      color = styleInterval(1000, c('black', 'black')),
      backgroundColor = styleInterval(1000, c('gray', 'yellow'))
    ) 
  1. Lances de pesca
tmap_mode("view")
map_per 


PabloMBooster/vmsR documentation built on June 29, 2023, 11:16 a.m.