I'm trying to take a bounding box, and crop only that section from whatever source amount of HGT files are needed. I see it should be possible from this. Using GDALWarp
with the following results in an error about sizing.
#include <cstddef>
#include <iostream>
#include <vector>
extern "C" {
#include "gdal.h"
#include "gdal_utils.h"
}
int main(int argc, char **argv) {
GDALAllRegister();
const char *hgts[] = {
"/tmp/icarus/lv8n/N41W121.hgt",
"/tmp/icarus/lv8n/N41W120.hgt",
"/tmp/icarus/lv8n/N41W119.hgt",
"/tmp/icarus/lv8n/N40W121.hgt",
"/tmp/icarus/lv8n/N40W120.hgt",
"/tmp/icarus/lv8n/N40W119.hgt",
"/tmp/icarus/lv8n/N39W121.hgt",
"/tmp/icarus/lv8n/N39W120.hgt",
"/tmp/icarus/lv8n/N39W119.hgt",
};
auto datasets = std::vector<GDALDatasetH>();
for (auto s : hgts) {
GDALDatasetH dataset = GDALOpen(s, GA_ReadOnly);
if (!dataset) {
std::cerr << "error reading: " << s << std::endl;
continue;
}
datasets.push_back(dataset);
}
GDALWarpAppOptions *opts = GDALWarpAppOptionsNew(NULL, NULL);
GDALWarpAppOptionsSetWarpOption(opts, "-te", "-120.5 39.2 -118.5 41.5");
GDALDatasetH cropped = GDALWarp("/tmp/output.hgt", NULL, 9, datasets.data(), opts, NULL);
GDALWarpAppOptionsFree(opts);
if (!cropped) {
return 1;
}
for (auto dataset : datasets) {
GDALClose(dataset);
}
GDALClose(cropped);
return 0;
}
ERROR 1: Image dimensions should be 1201x1201, 3601x3601 or 1801x3601.
Is it possible to crop out a different size for an HGT file and make a new one, or does the output crop have to be one of those sizes? If the output as an HGT needs to keep the size limits of an HGT file, is there another format this can be converted into so that elevations could be queried and only the section we care about can be kept in memory?