下面给出的代码是将二进制文件从float32转换为16b,比例因子为10.我得到%d无效的错误.
setwd("C:\\2001")
for (b in paste("data", 1:365, ".flt", sep="")) {
conne <- file(b, "rb")
file1<- readBin(conne, double(), size=4, n=360*720, signed=TRUE)
file1[file1 != -9999] <- file1[file1 != -9999]*10
close(conne)
fileName <- sprintf("C:\\New folder (11)\\NewFile%d.bin", b)
writeBin(as.integer(file1), fileName, size = 2)
}
Run Code Online (Sandbox Code Playgroud)
结果:
Error in sprintf("C:\\New folder (11)\\NewFile%d.bin", :
invalid format '%d'; use format %s for character objects
Run Code Online (Sandbox Code Playgroud)
我%s按照R.But的建议使用 了1:365的文件完全是空的
我有一个文本文件包含如下信息:
Grid Point Index, Latitude, Longitude, Cell
167, 0.000000, 9.432301, 1350
169, 0.000000, 9.544590, 1350
171, 0.000000, 9.656878, 1350
173, 0.000000, 9.769168, 1350
175, 0.000000, 9.881457, 1350
177, 0.000000, 9.993747, 1350
179, 0.000000, 10.106036, 1386
181, 0.000000, 10.218326, 1386
Run Code Online (Sandbox Code Playgroud)
我想找出这个lat和long的相应网格点和单元格:0.000000,11.902665.好吧,我可以手动完成,但这需要花费很多时间.可以确定没有与我的输入相对应的精确坐标,所以我希望文件中最接近的坐标与输入相对应.任何人都可以帮我构建这个功能
insert lat and long
Run Code Online (Sandbox Code Playgroud)
然后将在文件中找到最接近的lat-long以及相应的网格点索引和单元格
阅读文件
das= read.table("C:\\Users\\lonlatnter.txt", sep=",",header=TRUE)
Run Code Online (Sandbox Code Playgroud) 我.img在一个名为的文件夹中有数千个不同的文件(具有相同的扩展名)data.如果我用这个:
dir<- list.files ("C:\\Users\\data", "*.img", full.names = TRUE)
Run Code Online (Sandbox Code Playgroud)
它将列出我在该文件夹中的所有文件data.
我需要的只是列出名为的文件:
File_yyyymmdd_data.img (in which yyyymmdd varies for 10 years)
Run Code Online (Sandbox Code Playgroud)
任何想法或提示表示赞赏!
下面给出的代码段将读取并显示带有图例的文件图像.如何告诉R在绘制图例时不考虑例如-9999的值或任何其他值.
conne <- file("C:\\DEM.bin", "rb")
image(t(t(y)),ylim=c(1,0))
image.plot(t(t(y)), add = FALSE, legend.shrink = 0.9,legend.width = 1.2,
legend.mar = NULL, graphics.reset = FALSE, horizontal = FALSE, bigplot = NULL,
smallplot = NULL,legend.only = FALSE,lab.breaks=NULL, axis.args=NULL))
Run Code Online (Sandbox Code Playgroud) 我有几个具有 tif 格式的文件。我想将它们转换为 ENVI 格式。我对一个文件成功了,但我想对目录中的其余文件执行此操作。
the first file in the directory is:Ser_W55_20100101_A.tif.
the second file in the directory is:Ser_W55_20100102_A.tif and so on .....
Run Code Online (Sandbox Code Playgroud)
我在 Windows 上工作,所以我只需启动 cmd,然后编写命令:
C:\Users>gdal_translate -of "ENVI" D:\Ser_W55_20100101_A.tif D:\Ser_W55_20100101_A.img
Run Code Online (Sandbox Code Playgroud)
这很有效。关于如何对所有文件执行此操作并返回相同名称(从 (tif) 更改为 ENVI)的任何想法
m=c(1,2,5,4,6,8)
h=c(1,2,9,8,7,3)
cor(m,h)
#[1] 0.4093729
Run Code Online (Sandbox Code Playgroud)
如果你估计相关系数(R),那么你也可以估计95%相关系数(R)的置信区间,导致例如像
R = 0.40 [0.33 0.56]
Run Code Online (Sandbox Code Playgroud)
对R的"最佳"估计是真正的R在和之间0.40的95%可能性.(请注意,这些数字是完全组成的.)0.30.56
我正在寻找一个函数,它将分别提供R的下限和上限.有类似的东西:
R = 0.40
upper [0.33]
lower [0.56]
Run Code Online (Sandbox Code Playgroud)
类似于此的东西MATLAB:
[R,P,RLO,RUP]=corrcoef(...) also returns matrices RLO and RUP, of the same size as R,
containing lower and upper bounds for a 95% confidence interval for each coefficient.
Run Code Online (Sandbox Code Playgroud) 我想绘制一个光栅文件。
library(colorRamps)
library(raster)
r <- raster(nrows=5, ncols=5, vals=1:25)
plot(r, col = matlab.like(8))
Run Code Online (Sandbox Code Playgroud)
这产生

如您所见,图例的编号从5到25。这些数字不太清楚,因此我想增加它们的大小以使其清晰并使其变粗。谢谢
我正在使用可从此处下载的气候变量:
ftp://sidads.colorado.edu/pub/DATASETS/nsidc0301_amsre_ease_grid_tbs/global/
Run Code Online (Sandbox Code Playgroud)
此文件是带有586 lines and 1383 columns(全局映射)的二进制(矩阵)文件.我想知道一个像素(单元格)的4个坐标(lat-long).
有关该文件的更多信息:
These data are provided in EASE-Grid projections global cylindricalat 25 km resolution, are two-
byte
Spatial Coordinates:
N: 90° S: -90° E: 180° W: -180°
Run Code Online (Sandbox Code Playgroud)
使用栅格包并将数据转换为栅格对象:
file<- readBin("ID2r1-AMSRE-ML2010001A.v03.06H", integer(), size=2, n=586*1383, signed=T)
m = matrix(data=file,ncol=1383,nrow=586,byrow=TRUE)
r = raster(m, xmn=-180, xmx=180, ymn=-90, ymx=90)
Run Code Online (Sandbox Code Playgroud)
现在该文件是一个空间正确引用的对象,但如果没有使用圆柱投影的完整规范,则无法返回到lat-long坐标.
这里有更多信息http://nsidc.org/data/ease/tools.html包括一些网格的链接,这些网格具有该网格系统的lat-long网格单元格:
ftp://sidads.colorado.edu/pub/tools/easegrid/lowres_latlon/
MLLATLSB "latitude"
MLLonLSB "longitude"
Run Code Online (Sandbox Code Playgroud)
例如,我们可以为数据网格中的单元格创建一个纬度栅格:
> lat <- readBin("MLLATLSB",integer(), size=4, n=586*1383, endian="little")/100000
> latm = matrix(data=lat,ncol=1383,nrow=586,byrow=TRUE)
> latr = raster(latm, xmn=-180, xmx=180, ymn=-90, …Run Code Online (Sandbox Code Playgroud) 我希望情节中的图例是水平的(每个都彼此并排,而不是一个在另一个之上)
有没有办法从垂直变为水平?例子:
mtcars$cyl <- factor(mtcars$cyl, labels=c("four","six","eight"))
ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) +
opts(legend.position = c(0, 1), title="Legend placement makes me sad")
Run Code Online (Sandbox Code Playgroud) library(data.table)
Run Code Online (Sandbox Code Playgroud)
我正在尝试这样做。
wd <- structure(list(Year = c(2006L, 2006L, 2006L), day = c(361L, 361L,
360L), hour = c(14L, 8L, 8L), mint = c(30L, 0L, 30L), valu1 = c(0.5,
0.3, 0.4), Date = structure(c(1167229800, 1167206400, 1167121800
), class = c("POSIXct", "POSIXt"), tzone = "UTC")), .Names = c("Year",
"day", "hour", "mint", "valu1", "Date"), row.names = c(NA, -3L
), class = "data.frame")
wg <- c("2006/12/27 14:23:59", "2006/12/27 16:47:59", "2006/12/27 19:12:00")
w <- c("0.4", "0.2", "0.5")
wf=data.frame(wg,w)
wg <- as.POSIXct(wf$wg, format = "%Y/%m/%d %T", tz …Run Code Online (Sandbox Code Playgroud) r ×9
raster ×2
correlation ×1
data.table ×1
gdal ×1
geolocation ×1
ggplot2 ×1
gis ×1
legend ×1
plot ×1