
########### PLOT THE REGION BOUNDARIES AS PLOT  
# Natural Earth shape files -- global (Robinson) projections
# get shapefiles from http://www.naturalearthdata.com

INPUT <-"/home/karger/Documents/bio/Bio_Backup/TIN R Skripte/GIT/cloudforests/data/"
pp    <- read.table(paste0(INPUT,"pp.txt"),header=T)
coordinates(pp)<-~x+y
coords<- coordinates(pp)
pp    <- pp[,1:2]

shape_path       <- "/mnt/lud11/karger/natural_earth_vector/50m_physical/"
shape_path2      <- "/mnt/lud11/karger/natural_earth_vector/50m_cultural/"
tcf              <- shapefile(paste0(INPUT,"cf1.shp"))



coast_shapefile  <- shapefile(paste0(shape_path, "/ne_50m_coastline.shp"))
ocean_shapefile  <- shapefile(paste0(shape_path, "/ne_50m_ocean.shp"))
admin0_shapefile <- shapefile(paste0(shape_path2,"/ne_50m_admin_0_countries.shp"))
admin1_shapefile <- shapefile(paste0(shape_path2,"/ne_50m_admin_1_states_provinces_lakes.shp"))
lakes_shapefile  <- shapefile(paste0(shape_path, "/ne_50m_lakes.shp"))
bb_shapefile     <- shapefile(paste0(shape_path, "ne_50m_graticules_all/ne_50m_wgs84_bounding_box.shp"))
grat30_shapefile <- shapefile(paste0(shape_path, "ne_50m_graticules_all/ne_50m_graticules_30.shp"))

unproj_crs         <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
robin_crs          <- CRS("+proj=robin +lon_0=0w")
pp@proj4string@projargs<-"+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"

bb_poly_proj       <- spTransform(bb_shapefile, robin_crs)
coast_lines_proj   <- spTransform(coast_shapefile, robin_crs)
admin0_poly_proj   <- spTransform(admin0_shapefile, robin_crs)
admin1_poly_proj   <- spTransform(admin1_shapefile, robin_crs)
lakes_poly_proj    <- spTransform(lakes_shapefile, robin_crs)
grat30_lines_proj  <- spTransform(grat30_shapefile, robin_crs)
ocean_proj         <- spTransform(ocean_shapefile, robin_crs)
pp_proj            <- spTransform(pp,robin_crs)
tcf_proj           <- spTransform(tcf,robin_crs)

cf_id_new<-read.csv("/home/karger/Documents/bio/Bio_Backup/TIN R Skripte/GIT/cloudforests/data/cf_id_new.txt",sep="\t")
tcf_regions <- shapefile("/mnt/lud11/karger/cloudforest_loss/tcf_region_boundaries.shp")
line_numbers<- shapefile("/mnt/lud11/karger/cloudforest_loss/lines_numbers.shp")
line_numbers<- spTransform(line_numbers,robin_crs)
tcf_regions <- merge(tcf_regions,cf_id_new,by.x="ID",by.y="cf_id")
tcf_proj    <- spTransform(tcf_regions,robin_crs)
tcf         <- spTransform(tcf,robin_crs)
### plot the map
pdf("/home/karger/Documents/bio/Bio_Backup/TIN R Skripte/GIT/cloudforests/output/Supplement_Region_boundaries.pdf",height=18,width=22)

  plot(bb_poly_proj)
  plot(ocean_proj,col="lightblue",add=T)
  plot(admin0_poly_proj, border="grey80",add=T)
  #plot(tcf,col="black",add=T)
  plot(grat30_lines_proj,add=T,col="grey50",lty="dotted")
  plot(tcf_proj,add=T,border="darkred")
  plot(bb_poly_proj,add=T)
  label<-as.character(seq(1,60,1))
  text(pp_proj,labels=label,cex=1.4)
  plot(line_numbers,add=T)
  text(x=0,y=9200000,  "TCF region polygons",cex=3)

dev.off()

