update to one routine
This commit is contained in:
parent
a2c5ed68fc
commit
c20b2ba686
2 changed files with 61 additions and 97 deletions
|
@ -29,6 +29,7 @@ public class ConvertLidarTile {
|
|||
try {
|
||||
for (; ; ) {
|
||||
ZipEntry ze = zis.getNextEntry();
|
||||
if (ze == null) break;
|
||||
if (ze.getName().endsWith(".hgt")) {
|
||||
readHgtFromStream(zis, rowOffset, colOffset, 1200);
|
||||
return;
|
||||
|
@ -65,34 +66,6 @@ public class ConvertLidarTile {
|
|||
}
|
||||
}
|
||||
|
||||
private static void readHgtFromFile(File f, int rowOffset, int colOffset)
|
||||
throws Exception {
|
||||
DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(f)));
|
||||
|
||||
for (int ir = 0; ir < ROW_LENGTH + 1; ir++) {
|
||||
int row = rowOffset + ir;
|
||||
|
||||
for (int ic = 0; ic < ROW_LENGTH + 1; ic++) {
|
||||
int col = colOffset + ic;
|
||||
|
||||
int i1 = dis.read(); // msb first!
|
||||
int i0 = dis.read();
|
||||
|
||||
if (i0 == -1 || i1 == -1)
|
||||
throw new RuntimeException("unexcepted end of file reading hgt entry!");
|
||||
|
||||
short val = (short) ((i1 << 8) | i0);
|
||||
|
||||
if (val == NODATA2) {
|
||||
val = NODATA;
|
||||
}
|
||||
|
||||
setPixel(row, col, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void setPixel(int row, int col, short val) {
|
||||
if (row >= 0 && row < NROWS && col >= 0 && col < NCOLS) {
|
||||
imagePixels[row * NCOLS + col] = val;
|
||||
|
@ -217,57 +190,20 @@ public class ConvertLidarTile {
|
|||
doConvert(args[1], ilon_base, ilat_base, filename30);
|
||||
}
|
||||
|
||||
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 {
|
||||
public SrtmRaster getRaster(File f, double lon, double lat) throws Exception {
|
||||
|
||||
if (f.getName().toLowerCase().endsWith(".zip")) {
|
||||
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(f)));
|
||||
try {
|
||||
for (; ; ) {
|
||||
ZipEntry ze = zis.getNextEntry();
|
||||
if (ze == null) break;
|
||||
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;
|
||||
|
@ -287,7 +223,33 @@ public class ConvertLidarTile {
|
|||
} finally {
|
||||
zis.close();
|
||||
}
|
||||
} else {
|
||||
if (f.length() > ((SRTM3_ROW_LENGTH + 1) * (SRTM3_ROW_LENGTH + 1) * 2)) {
|
||||
ROW_LENGTH = SRTM1_ROW_LENGTH;
|
||||
} else {
|
||||
ROW_LENGTH = SRTM3_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;
|
||||
}
|
||||
}
|
||||
FileInputStream dis = new FileInputStream(f);
|
||||
try {
|
||||
readHgtFromStream(dis, 0, 0, ROW_LENGTH);
|
||||
} finally {
|
||||
dis.close();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("read file " + f + " rl " + ROW_LENGTH);
|
||||
|
||||
boolean halfCol5 = false; // no halfcol tiles in lidar data (?)
|
||||
|
||||
|
@ -304,4 +266,5 @@ public class ConvertLidarTile {
|
|||
return raster;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import btools.util.CompactLongSet;
|
||||
|
@ -217,13 +218,13 @@ public class PosUnifier extends MapCreatorBase {
|
|||
if (lastSrtmRaster == null) {
|
||||
File f = new File(new File(srtmdir), filename + ".hgt");
|
||||
if (f.exists()) {
|
||||
lastSrtmRaster = new ConvertLidarTile().getRasterDirect(f, lon, lat);
|
||||
lastSrtmRaster = new ConvertLidarTile().getRaster(f, lon, lat);
|
||||
srtmmap.put(filename, lastSrtmRaster);
|
||||
return lastSrtmRaster;
|
||||
}
|
||||
f = new File(new File(srtmdir), filename + ".zip");
|
||||
if (f.exists()) {
|
||||
lastSrtmRaster = new ConvertLidarTile().getRasterZip(f, lon, lat);
|
||||
lastSrtmRaster = new ConvertLidarTile().getRaster(f, lon, lat);
|
||||
srtmmap.put(filename, lastSrtmRaster);
|
||||
return lastSrtmRaster;
|
||||
}
|
||||
|
@ -246,11 +247,11 @@ public class PosUnifier extends MapCreatorBase {
|
|||
lon = -lon + 1;
|
||||
}
|
||||
|
||||
return String.format("%s%02d%s%03d", latPref, lat, lonPref, lon);
|
||||
return String.format(Locale.US, "%s%02d%s%03d", latPref, lat, lonPref, lon);
|
||||
}
|
||||
|
||||
private void resetSrtm() {
|
||||
srtmmap = new HashMap<String, SrtmRaster>();
|
||||
srtmmap = new HashMap<>();
|
||||
lastSrtmLonIdx = -1;
|
||||
lastSrtmLatIdx = -1;
|
||||
lastSrtmRaster = null;
|
||||
|
|
Loading…
Reference in a new issue