Using the Transform dialog with an image, which contains a single data channel for terrain elevation data for land together bathymetry data for oceans, we use the Expression tab of the Transform dialog to reset all pixel values less than zero to zero. This takes all below-zero elevations and sets them to zero, in effect removing bathymetry effects so that ocean areas are represented with zero elevation.
The data set we will use is US government space shuttle SRTM data that was combined with bathymetry data to show terrain elevations as well as ocean depths. The data uses sea level as the zero mark so terrain elevations are positive numbers while negative numbers represent depths. The data imports into Manifold as an image that is made up of a single data channel. SRTM data is published as rectangles that tile the Earth. The particular data set we use shows a region centered approximately on the Red Sea.
We open the image and use Edit - Style to color it with a palette as seen below.
Using the Full Range button we see the data ranges from -5868 to 5778. For this particular example we would like to replace all the negative number, that is, all depths with a value of 0, thus removing all relief below sea level.
The task is a common one in spatial engineering and occurs for various reasons. For example, we might need to use this data with a GIS or other package, such as a 3D modeling package, that cannot work with negative numbers for terrain elevations. Or we might be creating a data set for use in a modelling show that will use a 3D printer to create a tabletop model of the terrain but which requires ocean regions to be flat. For whatever reason, our task is to replace all negative numbers, that is, depths, with a value of 0.
An experienced Manifold operator would just do that in a single step using a single expression. Since this is a tutorial example we will do the job the way a beginner might approach the task, taking it in a few simple steps that allow checking the workflow along the way.
We begin by zooming in to a region right off the tip of the Horn of Africa, with the Gulf of Aden seen at the top and the Arabian Sea to the right and lower right. We also draw a selection box with a Ctrl-Shift-click and drag to Select the tiles in the center of the view. The rectangular region of the selected tiles is shown by a red selection border and translucent fill.
Why did we zoom in and why did we select some tiles? There are two reasons:
We choose Edit - Transform to launch the Transform dialog.
The dialog launches with the Tile field for the image already the Target by default. We click the Expression tab and we check the Restrict to selection box.
The expression we use is a trivial expression that uses a single Manifold SQL function for tiles, TileMax. If we forget the exact name of the function or we would like to construct the expression by double-clicking a sample in the query builder pane, we enter Tile into the filter box so that out of the zillions of operators and functions Manifold offers the pane only shows those with Tile in their names. We scroll down to where TileMax is found, double-click it to enter the function into the expression pane without risk of keyboarding errors in the name of the function and then we fill it in to form the expression
TileMax([Tile], 0)
The TileMax function takes two values and returns a pixel value that is the larger, that is, the maximum, of the two. The expression says to take whatever is in the pixel value for the tile, compare it to 0 and use whichever is bigger. For all negative pixel values obviously 0 will be the greater of the two. For all pixel values over land which have an elevation value greater than zero, the value of whatever is already in the tile will be the larger, since any positive number is greater than 0, so all positive pixel values will be left unchanged.
Manifold shows a preview as soon as we write enough of an expression for it to be an executable expression.
Since we checked the Restrict to Selection box the preview for what the expression does will be shown only within the selected region. The preview is shown using blue preview color for the box border and a dotted fill that allows the preview within the the box to be seen more clearly.
We can see that regions where elevation values were negative, that is, depths in ocean regions, have indeed been all set to the same value as shown by the palette color, the color assigned to 0 channel values. At the same time, elevation values over land have not been changed. That is expected since all the elevation values over land are greater than zero.
Since we want to apply the transform to the entire image we will uncheck the Restrict to selection box.
Right away the preview is now applied to the entire view and not just to the selected region.
To apply the transforming expression we press the Update Field button and then we press the Close button.
Back in the image window we see the transform has been applied. We also see the selection box again, which we can get rid of by choosing Edit - Select None in the main menu.
We also see a message
icon in the lower right corner. That is because the modification
to the data requires an update to intermediate image levels. We
choose View - Messages in
the main menu and then press the button to update levels.
With that we now have a clean display that shows all ocean areas with an elevation of 0, exactly as we expect of sea level.
Zooming out to see the entire data set we see the transform has indeed been applied to all the data and has left all land regions, that is, all regions where elevations were already above zero, unmodified.
In the above sequence we applied the transform expression to the image by pressing the Update Field button in the Transform dialog. As an alternative we could have pressed the Edit Query button to launch the Command Window with a query automatically generated by Manifold that executes the expression and updates the image.
Doing so is a great way to learn SQL and how to utilize various functions. The query generated is:
PRAGMA ('progress.percentnext' = '100');
UPDATE (
SELECT [Y], [X],
[Tile],
CASTV ((TileMax([Tile], 0)) AS INT16) AS [n_Tile]
FROM [e020n40.Bathymetry.srtm]
THREADS SystemCpuCount()
) SET [Tile] = [n_Tile];
The PRAGMA and THREADS statements are routine housekeeping statements, with PRAGMA setting up the progress bar and THREADS the usual default of using all available CPU cores.
Example: Zoom In to See Transform Previews for Big Images - A short example showing how previews for the Transform Dialog will appear in large images only when zoomed in far enough so computation of the preview does not cause objectionable delays.
Example: Parallel Speed Increase in an Image Transform - A short example illustrating how checking the Allow parallel execution option (on by default) increases speed by a factor of four in a simple use of the Transform dialog to modify an image.
Example: Use a Transform Dialog Expression to Create Buffers in a Drawing