Add external DEM as elevation band


#1

Dear developers,

I have a question regarding the AddElevationOp of the snap-engine. When I want to add a external DEM (geotiff-file) it gives me an error (nullpointer). The nullpointer occurs during initialize when the target file is created.

        if (externalDEM != null && !externalDEM.trim().isEmpty()) {

            fileElevationModel = new FileElevationModel(new File(externalDEM), resamplingMethod, null);
            noDataValue = fileElevationModel.getNoDataValue();
        } else {

            dem = DEMFactory.createElevationModel(demName, resamplingMethod);
            noDataValue = dem.getDescriptor().getNoDataValue();
        }

        createTargetProduct();

When debugging I found that this line in createTargetProduct() causes the problem:

    elevationBand.setDescription(dem.getDescriptor().getName());

When using an external DEM, the dem-variable is still empty. I think that fileElevationModel should be dem? What do you think?

Kind regards,

Reinier


#2

Yes, this is a bug. The dem variable is not correctly initialised inelevationBand.setDescription(dem.getDescriptor().getName())
@JunLu I’ve send a pull request, which should fix this problem.


#3

Hi Marco, the modified code has been merged into master. Thanks. Jun


#4

Hi Guys,

Thanks for your quick replies and fixes, but I still got errors when adding an external DEM. I went into the code and found that there are more bugs.

In createTargetProduct() this line still causes problems with an external DEM:

elevationBand.setDescription(dem.getDescriptor().getName());

Because the dem.getDescriptor() does not exist for a external DEM…

When I comment this out and re-run the operator, a new error occurs in computeTile() at this line:

final double demNoDataValue = dem.getDescriptor().getNoDataValue();

This happens because of the same reason.

Maybe as a suggestion, I looked into the InterferogramOp and there you have to provide a the no-data value of the external dem yourself (“externalDemNoDataValue”) and they use the filename as name for the DEM. Would this a solution to fix these bugs?

Kind regards,
Reinier


#5

I think you don’t have the latest sources yet. There were more updates yesterday evening. Please update and try again. Thanks for your effort. It’s much appreciated.


#6

Ah I see the new commits now. Probably the where added about the time I replied to this post. Thanks a lot, these fixes are also much appreciated!