Skip to content

Instantly share code, notes, and snippets.

@aolinto
Created August 27, 2018 13:04
Show Gist options
  • Save aolinto/ad9115bb4c4baa898f629be5a38fe0f1 to your computer and use it in GitHub Desktop.
Save aolinto/ad9115bb4c4baa898f629be5a38fe0f1 to your computer and use it in GitHub Desktop.
Create isobaths and smoothed isobaths based on Etopo1 data
# ====================================================================
# Create isobaths and smoothed isobaths based on Etopo1 data
# https://maps.ngdc.noaa.gov/viewers/wcs-client/
# author: Antônio Olinto Ávila da Silva
# creation: 2018-08-27
# last edition: 2018-08-27
# ====================================================================
# workspace
# ----------
library(raster)
library(ncdf4)
library(rgdal)
library(smoothr)
rm(list = ls())
# load and project Etopo1 file
# ----------------------------
ras.etopo1 <- raster("/home/antonio/Documentos/SIG/Etopo1/180825_Etopo1_SSE.nc")
proj4string(ras.etopo1) <- CRS("+proj=longlat +datum=WGS84")
# check imported file
# -------------------
res(ras.etopo1)
summary(ras.etopo1)
names(ras.etopo1)
plot(ras.etopo1,axes=TRUE)
# create contours
# ---------------
con.etopo1 <- rasterToContour(ras.etopo1,levels = c(seq(-10,-300,-10),seq(-350,-1000,-50)))
smo.etopo1 <- smoothr::smooth(con.etopo1, method = "ksmooth")
# plot contours
# -------------
split.screen(c(1,2))
screen(1)
plot(con.etopo1,xlim=c(-47,-46),ylim=c(-26,-25),col="red",main="contours")
screen(2)
plot(smo.etopo1,xlim=c(-47,-46),ylim=c(-26,-25),col="darkblue",main="smooth")
# write shapefile
# ---------------
writeOGR(smo.etopo1,dsn="/home/antonio/Documentos/SIG/Etopo1/",layer="Etopo1_SSE",overwrite_layer=TRUE,driver="ESRI Shapefile")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment