-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a hgt Reader #548
Add a hgt Reader #548
Conversation
It's already possible to use hgt files using ConvertLidarTile. I don't think it's useful to have two implementations. Your implementation also uses GPL code which can't be included in a MIT licensend project. |
@zod |
public SrtmRaster getRasterDirect(File f, double lon, double lat) throws Exception { | ||
if (f.length() > ((SRTM3_ROW_LENGTH + 1) * (SRTM3_ROW_LENGTH + 1) * 2)) { | ||
ROW_LENGTH = SRTM1_ROW_LENGTH; | ||
} else { | ||
ROW_LENGTH = SRTM3_ROW_LENGTH; | ||
} | ||
System.out.println("read file " + f + " rl " + ROW_LENGTH); | ||
|
||
// stay a 1x1 raster | ||
NROWS = ROW_LENGTH + 1; | ||
NCOLS = ROW_LENGTH + 1; | ||
|
||
imagePixels = new short[NROWS * NCOLS]; // 650 MB ! | ||
|
||
// prefill as NODATA | ||
for (int row = 0; row < NROWS; row++) { | ||
for (int col = 0; col < NCOLS; col++) { | ||
imagePixels[row * NCOLS + col] = NODATA; | ||
} | ||
} | ||
|
||
readHgtFromFile(f, 0, 0); | ||
|
||
boolean halfCol5 = false; // no halfcol tiles in lidar data (?) | ||
|
||
SrtmRaster raster = new SrtmRaster(); | ||
raster.nrows = NROWS; | ||
raster.ncols = NCOLS; | ||
raster.halfcol = halfCol5; | ||
raster.noDataValue = NODATA; | ||
raster.cellsize = 1. / (double) ROW_LENGTH; | ||
raster.xllcorner = (int) (lon < 0 ? lon - 1 : lon); //onDegreeStart - raster.cellsize; | ||
raster.yllcorner = (int) (lat < 0 ? lat - 1 : lat); //latDegreeStart - raster.cellsize; | ||
raster.eval_array = imagePixels; | ||
|
||
return raster; | ||
} | ||
|
||
public SrtmRaster getRasterZip(File f, double lon, double lat) throws Exception { | ||
|
||
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(f))); | ||
try { | ||
for (; ; ) { | ||
ZipEntry ze = zis.getNextEntry(); | ||
if (ze.getName().toLowerCase().endsWith(".hgt")) { | ||
if (ze.getSize() > ((SRTM3_ROW_LENGTH + 1) * (SRTM3_ROW_LENGTH + 1) * 2)) { | ||
ROW_LENGTH = SRTM1_ROW_LENGTH; | ||
} else { | ||
ROW_LENGTH = SRTM3_ROW_LENGTH; | ||
} | ||
System.out.println("read file " + f + " rl " + ROW_LENGTH); | ||
// stay a 1x1 raster | ||
NROWS = ROW_LENGTH + 1; | ||
NCOLS = ROW_LENGTH + 1; | ||
|
||
imagePixels = new short[NROWS * NCOLS]; // 650 MB ! | ||
|
||
// prefill as NODATA | ||
for (int row = 0; row < NROWS; row++) { | ||
for (int col = 0; col < NCOLS; col++) { | ||
imagePixels[row * NCOLS + col] = NODATA; | ||
} | ||
} | ||
readHgtFromStream(zis, 0, 0, ROW_LENGTH); | ||
break; | ||
} | ||
} | ||
} finally { | ||
zis.close(); | ||
} | ||
|
||
|
||
boolean halfCol5 = false; // no halfcol tiles in lidar data (?) | ||
|
||
SrtmRaster raster = new SrtmRaster(); | ||
raster.nrows = NROWS; | ||
raster.ncols = NCOLS; | ||
raster.halfcol = halfCol5; | ||
raster.noDataValue = NODATA; | ||
raster.cellsize = 1. / (double) ROW_LENGTH; | ||
raster.xllcorner = (int) (lon < 0 ? lon - 1 : lon); //onDegreeStart - raster.cellsize; | ||
raster.yllcorner = (int) (lat < 0 ? lat - 1 : lat); //latDegreeStart - raster.cellsize; | ||
raster.eval_array = imagePixels; | ||
|
||
return raster; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication. Just write one method which reads from stream and call it either using a stream created from a file or from a zip.
According to the #539 idea here a first version of a hgt reader.
It uses plain hgt or zip with hgt inside.
The PosUnifier has a test routine for single elevations.
I tested with Iceland (is West and above 60 degree).