Skip to content

Commit

Permalink
Add support for 30 SRTM tiles.
Browse files Browse the repository at this point in the history
The flag is -f SRTM30.
  • Loading branch information
akirmse committed Jul 5, 2024
1 parent e528c4f commit f924fb3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
13 changes: 10 additions & 3 deletions code/file_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int FileFormat::rawSamplesAcross() const {
case Value::NED1_ZIP: return 3612;
case Value::NED19: return 8112;
case Value::HGT: return 1201;
case Value::HGT30: return 3601;
case Value::THREEDEP_1M: return 10012;
case Value::LIDAR: return 10000;
default:
Expand All @@ -57,7 +58,9 @@ int FileFormat::inMemorySamplesAcross() const {
return 10801;
case Value::NED1_ZIP: return 3601;
case Value::NED19: return 8101;
case Value::HGT: return 1201;
case Value::HGT: // fall through
case Value::HGT30:
return rawSamplesAcross();
case Value::THREEDEP_1M: return 10001;
case Value::GLO30: // Fall through
case Value::FABDEM:
Expand All @@ -77,7 +80,9 @@ double FileFormat::degreesAcross() const {
return 1.0;
case Value::NED1_ZIP: return 1.0;
case Value::NED19: return 0.25;
case Value::HGT: return 1.0;
case Value::HGT: // fall through
case Value::HGT30:
return 1.0;
case Value::GLO30: // Fall through
case Value::FABDEM:
return 1.0;
Expand All @@ -102,7 +107,8 @@ CoordinateSystem *FileFormat::coordinateSystemForOrigin(double lat, double lng,
case Value::NED13:
case Value::NED1_ZIP:
case Value::NED19:
case Value::HGT:
case Value::HGT:
case Value::HGT30:
case Value::GLO30:
case Value::FABDEM: {
// The -1 removes overlap with neighbors
Expand Down Expand Up @@ -143,6 +149,7 @@ CoordinateSystem *FileFormat::coordinateSystemForOrigin(double lat, double lng,
FileFormat *FileFormat::fromName(const string &name) {
const std::map<string, FileFormat> fileFormatNames = {
{ "SRTM", Value::HGT, },
{ "SRTM30", Value::HGT30, },
{ "NED1-ZIP", Value::NED1_ZIP, },
{ "NED13", Value::NED13, },
{ "NED13-ZIP", Value::NED13_ZIP, },
Expand Down
3 changes: 2 additions & 1 deletion code/file_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class Tile;
class FileFormat {
public:
enum class Value {
HGT, // SRTM (90m, 3 arcsecond)
HGT, // SRTM (90m, 3 arcsecond)
HGT30, // SRTM (30m, 1 arcsecond)
NED19, // FLT file containing NED 1/9 arcsecond data
NED13, // FLT file containing NED 1/3 arcsecond data
NED13_ZIP, // ZIP file containing FLT NED 1/3 arcsecond data
Expand Down
21 changes: 18 additions & 3 deletions code/hgt_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,28 @@

using std::string;

static const int HGT_TILE_SIZE = 1201;
static const int16 HGT_NODATA_ELEVATION = -32768;

static uint16 swapByteOrder16(uint16 us) {
return (us >> 8) | (us << 8);
}

HgtLoader::HgtLoader(FileFormat fileFormat) {
switch (fileFormat.value()) {
case FileFormat::Value::HGT:
mTileSize = 1201;
break;

case FileFormat::Value::HGT30:
mTileSize = 3601;
break;

default:
LOG(ERROR) << "Tried to load HGT file from unknown file format " << static_cast<int>(fileFormat.value());
break;
}
}

Tile *HgtLoader::loadTile(const std::string &directory, double minLat, double minLng) {
char buf[100];
snprintf(buf, sizeof(buf), "%c%02d%c%03d.hgt",
Expand All @@ -57,7 +72,7 @@ Tile *HgtLoader::loadTile(const std::string &directory, double minLat, double mi
return nullptr;
}

int num_samples = HGT_TILE_SIZE * HGT_TILE_SIZE;
int num_samples = mTileSize * mTileSize;

int16 *inbuf = (int16 *) malloc(sizeof(int16) * num_samples);

Expand All @@ -80,7 +95,7 @@ Tile *HgtLoader::loadTile(const std::string &directory, double minLat, double mi
}
}

retval = new Tile(HGT_TILE_SIZE, HGT_TILE_SIZE, samples);
retval = new Tile(mTileSize, mTileSize, samples);
}

free(inbuf);
Expand Down
7 changes: 6 additions & 1 deletion code/hgt_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@
#define _HGT_LOADER_H_

#include "tile_loader.h"

#include "file_format.h"

// Load a .hgt tile. This is the format used by SRTM data.

class HgtLoader : public TileLoader {
public:
explicit HgtLoader(FileFormat fileFormat);

// minLat and minLng name the SW corner of the tile, in degrees
virtual Tile *loadTile(const std::string &directory, double minLat, double minLng);

private:
int mTileSize;
};

#endif // _HGT_LOADER_H_
2 changes: 1 addition & 1 deletion code/prominence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void usage() {
printf(" Options:\n");
printf(" -i directory Directory with terrain data\n");
printf(" -o directory Directory for output data\n");
printf(" -f format \"SRTM\", \"NED13\", \"NED1-ZIP\", \"NED19\", \"3DEP-1M\", \"GLO30\" input files\n");
printf(" -f format \"SRTM\", \"SRTM30\", \"NED13\", \"NED1-ZIP\", \"NED19\", \"3DEP-1M\", \"GLO30\", \"LIDAR\"\n");
printf(" -k filename File with KML polygon to filter input tiles\n");
printf(" -m min_prominence Minimum prominence threshold for output\n");
printf(" in same units as terrain data, default = 100\n");
Expand Down
4 changes: 3 additions & 1 deletion code/tile_loading_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Tile *BasicTileLoadingPolicy::loadTile(double minLat, double minLng) const {
if (mNeighborEdgeLoadingEnabled) {
switch (mFileFormat.value()) {
case FileFormat::Value::HGT: // Fall through
case FileFormat::Value::HGT30:
case FileFormat::Value::NED19:
case FileFormat::Value::NED13:
case FileFormat::Value::NED13_ZIP:
Expand Down Expand Up @@ -116,7 +117,8 @@ Tile *BasicTileLoadingPolicy::loadInternal(double minLat, double minLng) const {

switch (mFileFormat.value()) {
case FileFormat::Value::HGT:
loader = new HgtLoader();
case FileFormat::Value::HGT30:
loader = new HgtLoader(mFileFormat);
break;

case FileFormat::Value::NED13_ZIP: // fall through
Expand Down

0 comments on commit f924fb3

Please sign in to comment.