r 从Gebco到栅格线和多边形
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 从Gebco到栅格线和多边形相关的知识,希望对你有一定的参考价值。
library(raster)
library(rgdal)
library(SDMTools)
library(marmap)
library(maptools)
library(cluster)
library(snow)
library(parallel)
library(doParallel)
setwd("/Volumes/Trieste/Dropbox/Manuscripts/Ilustrating the Last Glacial Maximum")
# ---------------------------------------------------------------------------------------------
xmin <- -180 ; xmax <- 180 ; ymax <- 90 ; ymin <- -90
resolution <- 0.1
lons <- seq(from=xmin, to=xmax, by=resolution)
lats <- seq(from=ymin, to=ymax, by=resolution)
shape <- raster(ncol=length(lons)-1,nrow=length(lats)-1)
extent(shape) <- extent(xmin,xmax,ymin,ymax)
resolution <- 0.008
lons <- seq(from=xmin, to=xmax, by=resolution)
lats <- seq(from=ymin, to=ymax, by=resolution)
shape.hd <- raster(ncol=length(lons)-1,nrow=length(lats)-1)
extent(shape.hd) <- extent(xmin,xmax,ymin,ymax)
# ---------------------------------------------------------------------------------------------
bathymetry <- readGEBCO.bathy("../../../Dropbox/Raw Data/Rasters/Bathymetry/gebco_08.nc", db="GEBCO_08")
bathymetry <- as.raster(bathymetry)
plot(bathymetry)
writeRaster(bathymetry, file="Data/Spatial 2/Bathymetry.tif",format="GTiff", overwrite=TRUE)
bathymetry <- raster("../../../Dropbox/Raw Data/Rasters/Bathymetry/Global Bathymetry.tif")
bathymetry <- raster("/Volumes/home/Manuscripts/Modelling Past Distribution of Paramuricea clavata/Data/Spatial/Bathymetry N Atlantic.tif")
# ---------------------------------------------------------------------------------------------
# Use Smaller Extent
bathymetry <- crop(bathymetry,shape.hd)
# ----------------
Contour <- rasterToContour(bathymetry, levels=0 , maxpixels=5000000)
writeOGR(Contour, "Data", "LandMass GLobal Line", driver="ESRI Shapefile" , overwrite_layer=TRUE)
Contour.poly <- SpatialLines2PolySet( Contour )
Contour.poly <- PolySet2SpatialPolygons( Contour.poly )
Contour.poly.spatial <- SpatialPolygonsDataFrame(Contour.poly,data=as.data.frame("LandMass"))
writeOGR(Contour.poly.spatial, "Data", "LandMass GLobal Polygon", driver="ESRI Shapefile")
# ---------------------------------------------------------------------------------------------
以上是关于r 从Gebco到栅格线和多边形的主要内容,如果未能解决你的问题,请参考以下文章
r 将栅格裁剪为复杂多边形
将栅格裁剪为 sf 集合中的多边形 [R sf]
PIE SDK矢量数据的创建
PIE SDK内存矢量数据的创建
Canvas:绘制线和填充多边形
从坐标参考系中的多边形边界获取栅格中的像素坐标