R 从传单地图创建GeoTiff

R 从传单地图创建GeoTiff,r,leaflet,rstudio,tiff,geotiff,R,Leaflet,Rstudio,Tiff,Geotiff,我正在尝试从传单地图创建一个GeoTiff。我试图在网上找到答案,但似乎没有一个对我有用。我对使用R很陌生。 地理数据是一个2000*10的矩阵,其中包含标题、长度和纬度。 这是我的密码: install.packages('leaflet') install.packages('rgdal') install.packages('raster') install.packages('sp') library(leaflet) library(raster) library(rgdal) l

我正在尝试从传单地图创建一个GeoTiff。我试图在网上找到答案,但似乎没有一个对我有用。我对使用R很陌生。 地理数据是一个2000*10的矩阵,其中包含标题、长度和纬度。 这是我的密码:

install.packages('leaflet')
install.packages('rgdal')
install.packages('raster')
install.packages('sp')


library(leaflet)
library(raster)
library(rgdal)
library(raster)
library(sp)


sites <- data.frame(Name=(geodata[,2]),Long=(geodata[,10]),Lati=(geodata[,9]))

ma <- leaflet()
ma <- addTiles(ma)
ma <- addMarkers(ma, lng=sites$Long, lat=sites$Lati, popup=sites$Name)
ma

rast <- writeRaster(ma, filename="Worldmap.tif", format="GTiff")

知道错误可能在哪里吗

传单基于JavaScript库并生成动态web地图

没有直接的方法将动态地图保存为静态地图,如geotiff或png。如果您不必自动执行此操作,您只需在RStudio中导出图像,这将为您提供保存为PNG、JPEG或BMP的选项

另外,还有一些解决方法,您可以将传单地图保存为html文件,然后使用库
webshot
mapview
刮取信息,例如创建一个图像文件,如png。Webshot和mapview允许您将文件保存为PNG、PDF或JPEG格式

library(leaflet)
rand_lng = function(n = 10) rnorm(n, -93.65, .01)
rand_lat = function(n = 10) rnorm(n, 42.0285, .01)
ma <- addMarkers(ma, lng=rand_lng(50), lat=rand_lat(50), popup="a")

## With webshot and htmlwidgets:    
library(webshot)
saveWidget(ma, "temp.html", selfcontained = FALSE)
webshot("temp.html", file = "Rplot.png", cliprect = "viewport")

## With mapview
library(mapview)
mapshot(ma, file = "Rplot.png", remove_url = TRUE)
图书馆(传单)
兰德=函数(n=10)形式(n,-93.65,.01)
rand_lat=函数(n=10)rnorm(n,42.0285,.01)
文科硕士
library(leaflet)
rand_lng = function(n = 10) rnorm(n, -93.65, .01)
rand_lat = function(n = 10) rnorm(n, 42.0285, .01)
ma <- addMarkers(ma, lng=rand_lng(50), lat=rand_lat(50), popup="a")

## With webshot and htmlwidgets:    
library(webshot)
saveWidget(ma, "temp.html", selfcontained = FALSE)
webshot("temp.html", file = "Rplot.png", cliprect = "viewport")

## With mapview
library(mapview)
mapshot(ma, file = "Rplot.png", remove_url = TRUE)
library(png)
library(raster)
img <- readPNG("pathto/staticImage.png")

img[img==1]=NA
ar2mat <- matrix(img, nrow = nrow(img), ncol = ncol(img))
## Define the extent
rast = raster(ar2mat, xmn=0, xmx=1, ymn=0, ymx=1)
## Define the spatial reference system
proj4string(rast) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")

plot(rast); extent(rast)
writeRaster(rast, "pathto/png2tif.tif", format="GTiff", overwrite=TRUE)