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 GDALDemProcessing, other cleanup #54

Merged
merged 4 commits into from
Oct 16, 2020

Conversation

ddohler
Copy link
Collaborator

@ddohler ddohler commented Oct 15, 2020

Overview

Primarily adds a wrapper for GDALDemProcessing, but also includes a fair bit of code cleanup; I've tried to break logically separate changes into separate commits as much as possible.

Demo

Here's a demo of the new function in action. The backing data is from the Wildfires application, which requires dynamic color relief shading of a raster representing modeled wildfire risk. I've converted the single GeoTIFF into a tile pyramid, but with each tile delivered in GeoTIFF format and then dynamically rendered on the frontend. Let me know if you want to play with a live link.
DynamicShade

Notes

I'm going to release Loam 1.0.0 after this is merged. I'm close to having a blog post and demo written up, and I'd like to move on to other things for the time being (although I have plenty more ideas for Loam!).

Testing Instructions

  • Run tests
  • Run gdaldem on the command-line with the test input file to confirm the byte counts are accurate
  • If you want, play with the relief shading demo

Checklist

  • Add entry to CHANGELOG.md
  • Update the README with any function signature changes

Lazy evaluation has made it more difficult to track down the source of
errors because all operations on a dataset are chained together and
executed at once. This adds a prefix to any errors emitted by GDAL that
explains where the error occurred.
Copy link

@CloudNiner CloudNiner left a comment

Choose a reason for hiding this comment

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

Really nice effort here 🎉. Code reads nicely, comments are descriptive about what and why things are happening without being duplicative, and function input limitations described by the README docs are checked in tests and code. Really appreciate splitting commits into logical chunks, made this PR easy to follow.

let filePath = directory + '/' + filename;

// And then we can kick off the actual processing.
// TODO: The last parameter is an int* that can be used to detect certain kinds of errors,

Choose a reason for hiding this comment

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

Should this TODO be an issue to investigate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call, I think this should more just not be a TODO at all -- I've been able to get pretty good error messages out of the CPLGetLastError* methods, so it hasn't felt necessary to dig into what this does so far.

import guessFileExtension from '../guessFileExtension.js';
import ParamParser from '../stringParamAllocator.js';

// TODO: This is a good reason to switch to Typescript

Choose a reason for hiding this comment

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

Could also make "Switch to Typescript" an issue or epic, remove this comment, and put it in the issue as an example of a "pro".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call, absolutely; I've had Typescript in my head for a while but it has never made it into a written issue. Just added #55 and will update this.

**Note**: This returns a new `GDALDataset` object but does not perform any immediate calculation. Instead, calls to `.render()` are evaluated lazily (as with `convert()` and `warp()`, above). The render operation is only evaluated when necessary in order to access some property of the dataset, such as its size, bytes, or band count. Successive calls to `.warp()` and `.convert()` can be lazily chained onto datasets produced by `.render()`, and vice-versa.
#### Parameters
- `mode`: One of ['hillshade', 'slope','aspect', 'color-relief', 'TRI', 'TPI', 'roughness']. See the [`gdaldem documentation`](https://gdal.org/programs/gdaldem.html#cmdoption-arg-mode) for an explanation of the function of each mode.
- `args`: An array of strings, each representing a single [command-line argument](https://gdal.org/programs/gdaldem.html#synopsis) accepted by the `gdaldem` command. The `inputdem` and `output_xxx_map` parameters should be omitted; these are handled by `GDALDataset`. Example: `ds.render('hillshade', ['-of', 'PNG'])`

Choose a reason for hiding this comment

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

Ensuring that inputdem and output aren't in this array when a user calls the function doesn't seem to really be a thing that could be validated in code, right? You'd just be looking for a string filename and presumably if you passed them in args the existing error handling would throw with a somewhat helpful error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a good question -- I don't know what will happen if the user erroneously puts in an input or output filename. I'll write a test for it and see what happens. But yeah, my hope is that the GDAL argument parsing will be able to provide helpful feedback in this case, because it would basically end up with two of them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like it says something along the lines of Too many command options 'input.tif', which is not totally clear about what's going on but at least identifies the problematic argument correctly. I think seeing that would drive most users to try removing the input.tif option as a first step, and that would be the right thing to do even though the explanation wouldn't have reinforced that the filenames are handled internally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As a note, I'm not including the test I wrote because all the relevant functionality is on the GDAL side so the test wouldn't exercise any Loam code that doesn't already have a test.

Choose a reason for hiding this comment

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

That error seems to be good enough for now. If this trips people up in the future, we could look for the "Too many command options" part of the error message and append something like "Be sure you're not including your input and output tif paths to args." to it. Otherwise, like you said, doesn't seem to be much can be done.

@ddohler ddohler force-pushed the feature/dpd/gdal-dem-processing branch from b54bd55 to e92502f Compare October 16, 2020 17:13
@ddohler
Copy link
Collaborator Author

ddohler commented Oct 16, 2020

Thanks for the review! I've updated based on the comments and I'm going to go ahead and merge.

@ddohler ddohler merged commit 4567840 into develop Oct 16, 2020
@ddohler ddohler deleted the feature/dpd/gdal-dem-processing branch October 16, 2020 17:21
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.

2 participants