Skip to content
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

Merged
merged 3 commits into from
May 15, 2023
Merged

Add a hgt Reader #548

merged 3 commits into from
May 15, 2023

Conversation

afischerdev
Copy link
Collaborator

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).

@afischerdev afischerdev temporarily deployed to BRouter May 6, 2023 15:54 — with GitHub Actions Inactive
@zod
Copy link
Collaborator

zod commented May 7, 2023

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.

@afischerdev
Copy link
Collaborator Author

@zod
You are right, I missed that. Was only looking in PosUnifier what is used.
And I remember now I have used that class before for an Iceland map creation . But it was only partly usable.
I'll switch to ConvertLidarTile class and do a little rework for direct use.
And it works only with SRTM3 files.

@afischerdev afischerdev temporarily deployed to BRouter May 8, 2023 14:18 — with GitHub Actions Inactive
Comment on lines 220 to 306
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;

}
Copy link
Collaborator

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.

@afischerdev afischerdev temporarily deployed to BRouter May 10, 2023 10:56 — with GitHub Actions Inactive
@afischerdev afischerdev merged commit b21ca10 into abrensch:master May 15, 2023
@afischerdev afischerdev deleted the elev-source branch May 15, 2023 16:27
This was referenced May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants