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

Handle numerical metadata fields stored as strings in GeoTIFFS #311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mcvittal
Copy link
Contributor

This change allows for GeoTIFFS that have numerical metadata stored as string (and numerical arrays stored as space delimited strings) to be read in properly by SNAP.

@mcvittal mcvittal requested a review from marpet January 28, 2022 20:19
Copy link
Member

@marpet marpet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for PR Alex. But it seems that the files which shall be read are not following the GeoTIFF specification. Who is the provider of the data? Can these files be read in other applications?

double[] tiePoints;
try{
tiePoints = tiePointsField.getAsDoubles();
}catch (Exception e){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this should result in an IOException or IllegalFileFormatException. The specification requires Double values, not a String. The same for the other modifcation in this file and in TiffFileInfo.

If the changes are really necessary, these modifications can be extracted to a new method getAsDoubles(TIFFField).

try{
sb.append(tiffField.getValueAsString(i));
} catch (Exception e){
sb.append("99999");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theads provides wrong information to the user. Assuming that the value is 99999 when it could actually be anything.
Again, we have a format issue here and it might be better to throw an exception. If this is wrong, what else might be wrong with the file?
Instead, of "99999" something like "READERROR", OR "UNKNOWN" would be better.

@marpet
Copy link
Member

marpet commented Jan 31, 2022

Now, I have seen the issue in JIRA (https://senbox.atlassian.net/browse/SNAP-1500) and that it can be read by GDAL. But still, it doesn't follow the specs. Who is providing this data?
GDAL can read it because of the GDALMetadata tag contained in the attributes, I guess.

@marpet
Copy link
Member

marpet commented Jan 31, 2022

I've checked the file you have provided. I can read it without the modifications.
The GDAL GEoTiff reader is used in SNAP because it is a COG file.
Even when I explicitly used from code the GeoTiffReader it works.
When debugging I can see that the attribute fields are doubles, respectively ints.

@CLAassistant
Copy link

CLAassistant commented Jun 14, 2023

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants