library(data.table)
library(raster)
library(rgeos)
library(maptools)
library(plotly)
setwd('~/Desktop/-skola-/vyuka/gis_r')
krovak <- '+init=epsg:5513'
wgs84 <- '+init=epsg:4326'
dmr <- raster(paste(getwd(), '/DMR3_wgs84_cr/DMR3_wgs84_cr.tif', sep = ''))
crs(dmr) = wgs84
povodi <- readShapePoly(paste(getwd(), '/dib_A11_Povodi_vodomer_stanic/A11_Povodi_vodomer_stanic', sep = ''))
povodi@proj4string = CRS(krovak)
stanice <- readShapePoints(paste(getwd(), '/dib_E04_Vodomerne_stanice/E04_Vodomerne_stanice', sep = ''))
stanice@proj4string = CRS(krovak)
povodi_wgs <- spTransform(povodi, CRS(wgs84))
stanice_wgs <- spTransform(stanice, CRS(wgs84))
vyber <- c('190100')
stanice_s <- stanice_wgs[stanice_wgs$DBCN %in% vyber,]
povodi_s <- gIntersects(povodi_wgs,stanice_s,byid=TRUE)[1,]
povodi_s <- povodi_wgs[povodi_s,]
pe_pov <- extent(povodi_s)
pe_pov <- 1.15*pe_pov
dmr_c <- crop(dmr,pe_pov)
dmr_s <- mask(dmr_c,povodi_s)
DMR <- as.matrix(dmr_s)
plot_ly(x = ~seq(from = extent(dmr_c)[1], to = extent(dmr_c)[2], length.out = dim(DMR)[2]), y = ~seq(from = extent(dmr_c)[4], to = extent(dmr_c)[3], length.out = dim(DMR)[1]), z = ~DMR, colors = colorRampPalette(c('green','yellow','darkred'))(300), type = 'heatmap') %>%
layout(title = '2d', xaxis = list(title = 'long'), yaxis = list(title = 'alt'), scene = list(aspectmode = 'manual', aspectratio = list(x = 1, y = 1)))
plot_ly(x = ~seq(from = extent(dmr_c)[1], to = extent(dmr_c)[2], length.out = dim(DMR)[2]), y = ~seq(from = extent(dmr_c)[4], to = extent(dmr_c)[3], length.out = dim(DMR)[1]), z = ~DMR, colors = colorRampPalette(c('green','yellow','darkred'))(300)) %>%
add_surface() %>%
layout(title = '3d', scene = list(xaxis = list(title = 'long'), yaxis = list(title = 'lat'), zaxis = list(title = 'alt',range = c(-250, 750))), scene = list(aspectmode = 'manual', aspectratio = list(x = 1, y = 1, z = 25)))