【问题标题】:How to write a random array (with no spatial reference) to geotiff format?如何将随机数组(没有空间参考)写入 geotiff 格式?
【发布时间】:2014-02-06 17:30:58
【问题描述】:

以下 MATLAB 脚本会在 300x400 数组中生成随机位置,并使用 1-12 的值对这些位置进行编码。 如何将此非空间数组转换为 geotiff? 我希望使用 geotiff 输出来执行一些试验分析。任何投影坐标系(例如 UTM)都可以用于此分析。

我曾尝试使用geotiffwrite(),但未成功使用以下实现:

out = geotiffwrite('C:\path\to\file\test.tif', m)

这会产生以下错误:

>> test
Error using geotiffwrite
Too many output arguments.

编辑:

我遇到的主要问题是geotiffwrite() 函数缺少输入。我不确定如何处理这个问题。例如,我没有 AR 变量,因为数组没有空间参考。只要每个像素都在某处进行地理参考,我不在乎空间参考是什么。这样做的目的是创建一个示例数据集,我可以使用 MATLAB 空间函数进行试验。


% Generate a totally black image to start with.
m = zeros(300, 400, 'uint8');

% Generate 1000 random locations.
numRandom = 1000;
linearIndices = randi(numel(m), 1, numRandom);

% Set those locations to be "white".
m(linearIndices) = randi(12, [numel(linearIndices) 1]);

% Display it.  Random locations will appear white.
image(m);
colormap(gray);  

【问题讨论】:

    标签: arrays matlab geospatial geotiff


    【解决方案1】:

    我相信您的问题有一个非常简单的答案。调用geotiffwrite 时跳过out 变量。也就是说,使用:

    geotiffwrite('C:\path\to\file\test.tif', m)
    

    代替

    out = geotiffwrite('C:\path\to\file\test.tif', m)
    

    这是使用geotiffwrite 的工作代码示例,取自documentation。如您所见,那里没有输出变量:

    basename = 'boston_ovr';
    imagefile = [basename '.jpg'];
    RGB = imread(imagefile);
    worldfile = getworldfilename(imagefile);
    R = worldfileread(worldfile, 'geographic', size(RGB));
    filename = [basename '.tif'];
    geotiffwrite(filename, RGB, R)
    figure
    usamap(RGB, R)
    geoshow(filename)
    

    更新:

    根据文档,您至少需要 3 个输入参数。正确的语法是:

    geotiffwrite(filename,A,R)
    geotiffwrite(filename,X,cmap,R)
    geotiffwrite(...,Name,Value)
    

    来自文档:

    geotiffwrite(filename,A,R) 写入地理参考图像或数据网格, A,空间上由R 引用,输出文件filename

    请访问this link了解如何使用该功能。

    【讨论】:

    • 当我省略 out 变量时,我收到“输入参数不足”错误。
    • 太好了,感谢您的意见。不幸的是,geotiffwrite() 指令没有提供太多关于如何将数组(没有空间参考)写入 geotiff 格式的信息。
    • @Aaron,你为什么要这么做?你确定geotiff是你想要的吗?
    • 请查看问题更新。这样做的目的是创建一个示例数据集,我可以使用 Matlab 空间函数进行试验。
    猜你喜欢
    • 2018-02-23
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    相关资源
    最近更新 更多