# Raster Extensions

A raster data set is one in which data is stored as pixels arranged in rows of specified width. Images and Surfaces are raster data sets within Manifold System. Manifold SQL provides functions for analyzing and manipulating raster data in images and surfaces. Note that some functions are available only if the optional Surface Tools extension is installed.

The following table lists available raster functions. Functions are often employed with data in tables of type Geometry, Geometry (SHP) or Geometry (WKB). See the Geometry in Tables and the Queries and Geoms topics for additional information on storing and using geometry in tables.

In the following functions, p is either an image or surface (a raster data set consisting of pixels). s is a surface. i is an image. g is a geom.

 Function Comments AspectHeight(s, g) AspectHeight(s, x, y) AspectHeight(s, x, y, w) Returns the aspect of s at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Passing the w parameter computes aspect over a window of specified size (1 for 3x3, 2 for 5x5, etc). Surface Tools only. Blur(p, g) Blur(p, x, y) BlurHeight(s, g) BlurHeight(s, x, y) Returns the value of the Blur filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. DifferenceE(p, g) DifferenceE(p, x, y) DifferenceEHeight(s, g) DifferenceEHeight(s, x, y) Returns the value of the DifferenceE filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. DifferenceN(p, g) DifferenceN(p, x, y) DifferenceNHeight(s, g) DifferenceNHeight(s, x, y) Returns the value of the DifferenceN filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. DifferenceNE(p, g) DifferenceNE(p, x, y) DifferenceNEHeight(s, g) DifferenceNEHeight(s, x, y) Returns the value of the DifferenceNE filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. DifferenceNW(p, g) DifferenceNW(p, x, y) DifferenceNWHeight(s, g) DifferenceNWHeight(s, x, y) Returns the value of the DifferenceNW filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. DifferenceS(p, g) DifferenceS(p, x, y) DifferenceSHeight(s, g) DifferenceSHeight(s, x, y) Returns the value of the DifferenceS filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. DifferenceSE(p, g) DifferenceSE(p, x, y) DifferenceSEHeight(s, g) DifferenceSEHeight(s, x, y) Returns the value of the DifferenceSE filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. DifferenceSW(p, g) DifferenceSW(p, x, y) DifferenceSWHeight(s, g) DifferenceSWHeight(s, x, y) Returns the value of the DifferenceSW filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. DifferenceW(p, g) DifferenceW(p, x, y) DifferenceWHeight(s, g) DifferenceWHeight(s, x, y) Returns the value of the DifferenceW filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Gravity(drawing, column, neighbors, g) Gravity(drawing, column, neighbors, x, y) Returns the value of the surface interpolated using gravity interpolation method at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. The surface is built from the specified drawing using the specified column as the height. Setting the number of neighbors to -1 will use the default number of neighbors. Surface Tools only. HasPixel(p, g) HasPixel(p, x, y) Returns True if s has a visible pixel at the specified location and False otherwise. The location is either the centroid of a geom or a pair of XY coordinates. Height(s, g) Height(s, x, y) Returns average height of pixels covered by a geom or height of a pixel at an XY location in the given surface. HeightAvg(s, g) HeightAvg(s, g, w) HeightAvg(s, x, y, w) Returns average height of pixels covered by a geom or average height of pixels in a window of specified size (1 for 3x3, 2 for 5x5, etc) centered at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Window computations are available in Surface Tools only. HeightCurvMean(s, g) HeightCurvMean(s, x, y) HeightCurvMean(s, x, y, w) Returns the mean curvature of s at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Passing the w parameter computes curvature over a window of specified size (1 for 3x3, 2 for 5x5, etc). Surface Tools only. HeightCurvPlan(s, g) HeightCurvPlan(s, x, y) HeightCurvPlan(s, x, y, w) Returns the plan curvature of s at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Passing the w parameter computes curvature over a window of specified size (1 for 3x3, 2 for 5x5, etc). Surface Tools only. HeightCurvProfile(s, g) HeightCurvProfile(s, x, y) HeightCurvProfile(s, x, y, w) Returns the profile curvature of s at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Passing the w parameter computes curvature over a window of specified size (1 for 3x3, 2 for 5x5, etc). Surface Tools only. HeightDiversity(s, g) HeightDiversity(s, g, w) HeightDiversity(s, x, y, w) Returns the number of different height values in pixels covered by a geom or the number of different height values in pixels in a window of specified size (1 for 3x3, 2 for 5x5, etc) centered at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Window computations are available in Surface Tools only. HeightDiversityIndex(s, g) HeightDiversityIndex(s, g, w) HeightDiversityIndex(s, x, y, w) Returns the diversity index of height values in pixels covered by a geom or the diversity index of height values in pixels in a window of specified size (1 for 3x3, 2 for 5x5, etc) centered at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. The diversity index is a value from 0 to 1. The greater the value of the diversity index, the less similar the height values. Window computations are available in Surface Tools only. HeightMaj(s, g) HeightMaj(s, g, w) HeightMaj(s, x, y, w) Returns the most frequently occurring height of pixels covered by a geom or the most frequently occurring height of pixels in a window of specified size (1 for 3x3, 2 for 5x5, etc) centered at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Window computations are available in Surface Tools only. HeightMax(s) HeightMax(s, g) HeightMax(s, g, w) HeightMax(s, x, y, w) Returns maximum height of pixels covered by a geom or maximum height of pixels in a window of specified size (1 for 3x3, 2 for 5x5, etc) centered at the specified location or maximum height of all pixels. The location is either the centroid of a geom or a pair of XY coordinates. Window computations are available in Surface Tools only. HeightMed(s, g) HeightMed(s, g, w) HeightMed(s, x, y, w) Returns median (mean) height of pixels covered by a geom or median height of pixels in a window of specified size (1 for 3x3, 2 for 5x5, etc) centered at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Window computations are available in Surface Tools only. HeightMin(s) HeightMin(s, g) HeightMin(s, g, w) HeightMin(s, x, y, w) Returns minimum height of pixels covered by a geom or minimum height of pixels in a window of specified size (1 for 3x3, 2 for 5x5, etc) centered at the specified location or minimum height of all pixels. The location is either the centroid of a geom or a pair of XY coordinates. Window computations are available in Surface Tools only. HeightSum(s, g) HeightSum(s, g, w) HeightSum(s, x, y, w) Returns summed height of pixels covered by a geom or summed height of pixels in a window of specified size (1 for 3x3, 2 for 5x5, etc) centered at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Used to compute cumulative figures such as population in a given region or to compute the volume of a surface (the HeightSum value multiplied by the size of a pixel). Window computations are available in Surface Tools only. HighPass1(p, g) HighPass1(p, x, y) HighPass1Height(s, g) HighPass1Height(s, x, y) Returns the value of the HighPass1 filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. HighPass2(p, g) HighPass2(p, x, y) HighPass2Height(s, g) HighPass2Height(s, x, y) Returns the value of the HighPass2 filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. HighPass3(p, g) HighPass3(p, x, y) HighPass3Height(s, g) HighPass3Height(s, x, y) Returns the value of the HighPass3 filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. InterpolateHeight(s, g, radius) InterpolateHeight(s, x, y, radius) Returns the value of s at the specified location if it is visible and the interpolated value if it is invisible. The location is either the centroid of a geom or a pair of XY coordinates. The interpolated value is computed as the average value of s in the smallest box centered at the current pixel that contains at least one visible pixel. If all pixels in s are invisible, the function returns Null. The last parameter specifies an interpolation radius over which interpolation occurs, a negative value specifies infinite radius. See the discussion for the Interpolate (Parameter) transform operator. InterpolateRowHeight(s, g) InterpolateRowHeight(s, x, y) Returns the value of s at the specified location if it is visible and the interpolated value if it is invisible. The location is either the centroid of a geom or a pair of XY coordinates. The interpolated value is computed as the value of the straight line segment between the nearest visible pixels in the same row of s. If all pixels in the current row of s are invisible, the function returns Null. Overall, this function works much faster than Interpolate but is also less accurate. Kriging(drawing, column, neighbors, g) Kriging(drawing, column, neighbors, x, y) Kriging(drawing, column, neighbors, model, voronoi, g) Kriging(drawing, column, neighbors, model, voronoi, x, y) Returns the value of the interpolated surface at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. The surface is built from the specified drawing using the specified column as the height. Line objects participate as sets of their coordinates. Area objects are ignored. Setting the number of neighbors to -1 will use the default number of neighbors. The model argument is a case-insensitive string, e.g., "spherical" or "gaussian". Some models are only available in the Surface Tools extension. The voronoi argument is a boolean (if true, only Voronoi neighbors are used). KrigingMedianPolish(drawing, column, neighbors, g) KrigingMedianPolish(drawing, column, neighbors, x, y) KrigingMedianPolish(drawing, column, neighbors, model, voronoi, g) KrigingMedianPolish(drawing, column, neighbors, model, voronoi, x, y) Returns the value of the surface interpolated using the median-polish kriging interpolation method at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. The surface is built from the specified drawing using the specified column as the height. Line objects participate as sets of their coordinates. Area objects are ignored. Setting the number of neighbors to -1 will use the default number of neighbors. The model argument is a case-insensitive string, e.g., "spherical" or "gaussian". The voronoi argument is a boolean (if true, only Voronoi neighbors are used). This function requires the Surface Tools extension. Laplace1(p, g) Laplace1(p, x, y) Laplace1Height(s, g) Laplace1Height(s, x, y) Returns the value of the Laplace1 filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Laplace2(p, g) Laplace2(p, x, y) Laplace2Height(s, g) Laplace2Height(s, x, y) Returns the value of the Laplace2 filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. LowPass1(p, g) LowPass1(p, x, y) LowPass1Height(s, g) LowPass1Height(s, x, y) Returns the value of the LowPass1 filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. LowPass2(p, g) LowPass2(p, x, y) LowPass2Height(s, g) LowPass2Height(s, x, y) Returns the value of the LowPass2 filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. LowPass3(p, g) LowPass3(p, x, y) LowPass3Height(s, g) LowPass3Height(s, x, y) Returns the value of the LowPass3 filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. MedianCross(p, g) MedianCross(p, x, y) MedianCrossHeight(s, g) MedianCrossHeight(s, x, y) Returns the value of the MedianCross filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. MedianSquare(p, g) MedianSquare(p, x, y) MedianSquareHeight(s, g) MedianSquareHeight(s, x, y) Returns the value of the MedianSquare filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. MedianSquare5(p, g) MedianSquare5(p, x, y) MedianSquare5Height(s, g) MedianSquare5Height(s, x, y) Returns the value of the MedianSquare5 filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. PixelArea(p[, unit]) Returns the area of a single pixel in p in the specified units, or in the units of p. Pixel(p, g) Pixel(p, x, y) Returns the color of a pixel at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. PixelHeight(p[, unit]) Returns the height of a single pixel in p in the specified units, or in the units of p. PixelsByX(p) Returns the number of columns in p. PixelsByY(p) Returns the number of rows in p. PixelWidth(p[, unit]) Returns the width of a single pixel in p in the specified units, or in the units of p. Sharpen(p, g) Sharpen(p, x, y) SharpenHeight(s, g) SharpenHeight(s, x, y) Returns the value of the Sharpen filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. SharpenMore(p, g) SharpenMore(p, x, y) SharpenMoreHeight(s, g) SharpenMoreHeight(s, x, y) Returns the value of the SharpenMore filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. SlopeHeight(s, g) (was: Slope) SlopeHeight(s, x, y) SlopeHeight(s, x, y, w) Returns the slope of s at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. Passing the w parameter computes slope over a window of specified size (1 for 3x3, 2 for 5x5, etc). Surface Tools only. Tile(p, g, n) Tile(p, x, y, n) TileHeight(s, g, n) TileHeight(s, x, y, n) Returns the value of the Tile filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. The last parameter is the tile size. TileMedian(p, g, n) TileMedian(p, x, y, n) TileMedianHeight(s, g, n) TileMedianHeight(s, x, y, n) Returns the value of the TileMedian filter at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. The last parameter is the tile size. Triangulation(drawing, column, corners, g) Triangulation(drawing, column, corners, x, y) Returns the value of the surface interpolated using the triangulation interpolation method at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. The surface is built from the specified drawing using the specified column as the height. Line objects participate as sets of their coordinates. Area objects are ignored. The corners argument specifies the height to use for corners, and can be set to NULL. TriangulationContours(drawing, column, corners, g) TriangulationContours(drawing, column, corners, x, y) Returns the value of the surface interpolated using the contour triangulation interpolation method at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. The surface is built from the specified drawing using the specified column as the height. Line objects participate as sets of their segments, with intersections between segments being resolved automatically. Area objects are ignored. The corners argument specifies the height to use for corners, and can be set to NULL. Volume(s, g) Volume(s, g, w) Volume(s, x, y, w) Returns the volume covered by a geom or the volume of pixels in a window of specified size (1 for 3x3, 2 for 5x5, etc) centered at the specified location. The location is either the centroid of a geom or a pair of XY coordinates. The function assumes surface heights are in meters, and returns the volume in cubic meters. To compute volume, the system takes all pixels, computes the volume of each pixel multiplying its height (which can be negative) by its area, and sums the resulting volumes. Hence, the volume can be less than zero. Window computations are available in Surface Tools only.

Color Manipulation Functions

Colors within images may be manipulated using the following functions. In the following functions, c is a color.

 Function Comments ARGB(a, r, g, b) Combines given values for alpha, red, green and blue channels into a color. BGR(b, g, r) Combines given values for blue, green and red channels into a color. BGRA(b, g, r, a) Combines the given values for blue, green, red and alpha channels into a color. Channel(c, n) Extracts the value of the given channel of the color where n specifies the channel: 0 = blue, 1 = green, 2 = red, 3 = alpha. HLS(h, l, s) Combines given values for hue, lightness and saturation into a color. Hue(c) Extracts the hue of a color. Intensity(c) Extracts the brightness of a color (also known as "luma"). The name of the function has been kept for compatibility with previous versions of Manifold. Lightness(c) Extracts the lightness of a color. RGB(r, g, b) Combines given values for red, green and blue channels into a color. Saturation(c) Extracts the saturation of a color.

Lightness in the above is the same as L in classic HSL color space as used in traditional graphics arts. It is computed by the following formula:

l = (max(r, g, b) + min(r, g, b)) / 2

See the Expressions topic for additional SQL expressions.

Example: Transferring Aspect to Points

Suppose we have a drawing of points that are located in the same region of interest as a surface and we would like to compute the aspect of the surface at each point and to save that value as a data attribute for each point. This is easy to do using SQL as follows:

1. Open the drawing's table and add a new floating-point column named Aspect.

2. Create a new query.

3. Open the query and enter the following text for the query (substitute the name of the drawing for "Drawing" and the name of the surface for "Surface"):

UPDATE [Drawing] SET [Aspect] = AspectHeight([Surface], Centroid([Geom (I)]));

4. Run the query. This will set the values in the Aspect column for each point to the aspect of the surface at that point's location.