Regrid a raster image containing GIS-type data
REGRID uses a standard LAS mapping grid file to aggregate data such as land use category or surface properties into grid cells of a different size or in a different map projection. The program supports three modes of aggregation: finding the mode (most frequently occurring) of the values for all the input pixels which contribute to a given output pixel, finding the mean value over all the input pixels, or finding the fraction of input pixels which are in each of a small number of different classes. In computing these statistics, any input pixel which is only partly contained within a given output pixel is given a reduced weight, equal to the fraction of the input pixel's area which is within the output pixel.When determining the mode, one or more classes may be given special treatment in up to three different ways: weighting, thresholding, and/or reallocation. For each weighted class, the number of input pixels in that class which contribute to any given output pixel will be multiplied by a user-specified weight before determining which class makes the largest contribution to the output pixel. For a thresholded class, the class will not be accepted as the mode unless the ratio of the number of input pixels in that class to the total number of input pixels which contribute to the output pixel is at least as large as the specified threshold value. Finally, for a reallocated class, the count of input pixels in that class will be added to the counts for one or more other classes, after multiplication by user-specified weights.
- IN
- Name of input image file. Windowing is supported if WINDOPT = IN. Band selection is supported, but logical images (input image names separated by "+") is NOT supported.
- GRID
- Name of mapping grid file, in same format accepted by program GEOM.
- OUT
- Name of output file.
- WINDOPT(OUT)
- Image to use for defining output window; options are:
IN Use entire input image or window specified with IN to determine the smallest rectangle in the output projection which just encloses the input. If necessary, the output image will be extended outside the rectangle for which the mapping grid contains data, using bilinear extrapolation from the nearest mapping grid cell. If the input is rotated relative to the output, some output pixels may extend beyond the edges of the input image; they will be given the value specified by parameter FILL. OUT Use the output window specified by arguments OWINDOW (if present) or the rectangle in the output projection covered by the mapping grid data.
- OWINDOW(--)
- Output window specification if WINDOPT = OUT. The values specifying the upper-left corner of the image window and its size are entered in the following order:
SL Starting line SS Starting sample NL Number of lines in window NS Number of samples per lineIf OWINDOW is not specified, the entire image is processed according to values contained in the geometric mapping grid.
- ODTYPE(SAME)
- Output data type. Options are:
SAME Output has same data type as input (Default) BYTE Output data type is byte I*2 Output data type is two-byte integer. I*4 Output data type is four-byte integer. R*4 Output data type is four-byte real.If an integer data type is specified for subcommand FRACT, the fractional value is multiplied by 100 for BYTE, 10,000 for I*2, and 1,000,000 for I*4, and then rounded to the nearest integer.
- FILL(0.0)
- Fill value for output pixels entirely outside the input image. If an output pixel maps onto the boundary of the input image, such that the area covered by the output pixel is partly inside and partly outside the input image, an output value will be computed based only on the part of the output pixel which is within the input image.
- NODATA(--)
- Value of input pixel which is to be omitted from mean. If an output pixel overlaps one or more input pixels having the NODATA value, the mean will be computed using only those input pixels which are not equal to NODATA. If all input pixels have value NODATA, the output pixel will be assigned the FILL value.
- IN
- Name of input image file. Windowing is supported if WINDOPT = IN. Band selection is supported, but logical images (input image names separated by "+") is NOT supported.
- GRID
- Name of mapping grid file, in same format accepted by program GEOM.
- OUT
- Name of output file.
- WINDOPT(OUT)
- Image to use for defining output window; options are:
IN Use entire input image or window specified with IN to determine the smallest rectangle in the output projection which just encloses the input. If necessary, the output image will be extended outside the rectangle for which the mapping grid contains data, using bilinear extrapolation from the nearest mapping grid cell. If the input is rotated relative to the output, some output pixels may extend beyond the edges of the input image; they will be given the value specified by parameter FILL. OUT Use the output window specified by arguments OWINDOW (if present) or the rectangle in the output projection covered by the mapping grid data.
- OWINDOW(--)
- Output window specification if WINDOPT = OUT. The values specifying the upper-left corner of the image window and its size are entered in the following order:
SL Starting line SS Starting sample NL Number of lines in window NS Number of samples per lineIf OWINDOW is not specified, the entire image is processed according to values contained in the geometric mapping grid.
- ODTYPE(SAME)
- Output data type. Options are:
SAME Output has same data type as input (Default) BYTE Output data type is byte I*2 Output data type is two-byte integer. I*4 Output data type is four-byte integer. R*4 Output data type is four-byte real.If an integer data type is specified for subcommand FRACT, the fractional value is multiplied by 100 for BYTE, 10,000 for I*2, and 1,000,000 for I*4, and then rounded to the nearest integer.
- FILL(0.0)
- Fill value for output pixels entirely outside the input image. If an output pixel maps onto the boundary of the input image, such that the area covered by the output pixel is partly inside and partly outside the input image, an output value will be computed based only on the part of the output pixel which is within the input image.
- WCLASS(--)
- Input class(es) to be assigned weights other than 1.0. For subcommand MODE, this permits creating biases either for or against one or more classes.
Example 1: To force an output pixel to be classed as land use type "urban" whenever it contains one or more input pixels of type "urban", enter the class code for "urban" as the value of WCLASS and a number much larger than 1.0, such as 100.0, as the corresponding value for WEIGHT.
Example 2: To cause class 2 to be selected in favor of class 1 whenever there is a "tie" (each class contributes an equal number of input pixels to the output pixel), enter a weight of 1.001 for class 2.
- WEIGHT(--)
- Weight(s) to be assigned class(es) specified by WCLASS. The weights must be enetered in the same order as the WCLASS entries to which they correspond.
- TCLASS(--)
- Input class(es) for which threshold value(s) are to be used when determining mode. For subcommand MODE, if the class which contributes the greatest fractional coverage to an output pixel has a value less than its specified threshold, the class with the next largest fractional coverage will instead be assigned as the value of the output pixel.
Example: When aggregating land cover to a coarser grid scale, it may be desirable to report the dominant non-water land cover category along the edges of lakes or oceans unless water covers at least half the output pixel. To achieve this result, enter the class number for water under TCLASS and a value of .500 for THRESH.
- THRESH(--)
- Threshold value(s) to use with class(es) specified by TCLASS. The threshold values must be enetered in the same order as the TCLASS entries to which they correspond.
- REALLOC(--)
- Name of file containing class reallocation data and/or weight and/or threshold values. The input pixels from a given class may be reassigned to one or more other classes (for example, if pixels from a "mixed" class are to be counted towards the "unmixed" class frequencies when determining the mode). In addition, when a standard set of weights and/or thresholds is to be used repeatedly, it may be convenient to save them in a file.
This is a text file containing one record for each class reallocation, weight, or threshold. To distinguish the three types of entry, the records must begin with the letter "R", "W", or "T", respectively (in upper or lower case); records beginning with any other character will be ignored. The data records will, accordingly, have one of the following formats:
R oldclass newclass fract W class weight T class threshThe values for oldclass, newclass, and class should be entered as integers; fract, weight, and thresh should be entered as real numbers. For R records, there may be multiple records for the same oldclass; if so, all records for a given oldclass value must be together. For example, the entries
R 26 17 0.70 R 26 19 0.30will reallocate 70% of the input pixel count for class 26 to class 17, and the remaining 30% to class 19. For this example, the count for class 26 will be set to zero after the reallocation has been performed; if class 26 had been specified as one of the newclass values, the specified fraction of the original count for class 26 would be used as the final count for class 26.If a weight or threshold is specified for any class referenced by a reallocation record, the weight or threshold value will be applied after reallocation.
If the reallocation file does contain weight or threshold data, they will be used in addition to any values entered via parameters WEIGHT and THRESH; if WEIGHT or THRESH contain values for classes that also occur in the REALLOC file, the values from WEIGHT or THRESH will override those in the REALLOC file.
- IN
- Name of input image file. Windowing is supported if WINDOPT = IN. Band selection is supported, but logical images (input image names separated by "+") is NOT supported.
- GRID
- Name of mapping grid file, in same format accepted by program GEOM.
- OUT
- Name of output file.
- WINDOPT(OUT)
- Image to use for defining output window; options are:
IN Use entire input image or window specified with IN to determine the smallest rectangle in the output projection which just encloses the input. If necessary, the output image will be extended outside the rectangle for which the mapping grid contains data, using bilinear extrapolation from the nearest mapping grid cell. If the input is rotated relative to the output, some output pixels may extend beyond the edges of the input image; they will be given the value specified by parameter FILL. OUT Use the output window specified by arguments OWINDOW (if present) or the rectangle in the output projection covered by the mapping grid data.
- OWINDOW(--)
- Output window specification if WINDOPT = OUT. The values specifying the upper-left corner of the image window and its size are entered in the following order:
SL Starting line SS Starting sample NL Number of lines in window NS Number of samples per lineIf OWINDOW is not specified, the entire image is processed according to values contained in the geometric mapping grid.
- ODTYPE(SAME)
- Output data type. Options are:
SAME Output has same data type as input (Default) BYTE Output data type is byte I*2 Output data type is two-byte integer. I*4 Output data type is four-byte integer. R*4 Output data type is four-byte real.If an integer data type is specified for subcommand FRACT, the fractional value is multiplied by 100 for BYTE, 10,000 for I*2, and 1,000,000 for I*4, and then rounded to the nearest integer.
- WCLASS(--)
- Input class(es) to be assigned weights other than 1.0. For subcommand MODE, this permits creating biases either for or against one or more classes.
Example 1: To force an output pixel to be classed as land use type "urban" whenever it contains one or more input pixels of type "urban", enter the class code for "urban" as the value of WCLASS and a number much larger than 1.0, such as 100.0, as the corresponding value for WEIGHT.
Example 2: To cause class 2 to be selected in favor of class 1 whenever there is a "tie" (each class contributes an equal number of input pixels to the output pixel), enter a weight of 1.001 for class 2.
- WEIGHT(--)
- Weight(s) to be assigned class(es) specified by WCLASS. The weights must be enetered in the same order as the WCLASS entries to which they correspond.
- REALLOC(--)
- Name of file containing class reallocation data and/or weight and/or threshold values. The input pixels from a given class may be reassigned to one or more other classes (for example, if pixels from a "mixed" class are to be counted towards the "unmixed" class frequencies when determining the mode). In addition, when a standard set of weights and/or thresholds is to be used repeatedly, it may be convenient to save them in a file.
This is a text file containing one record for each class reallocation, weight, or threshold. To distinguish the three types of entry, the records must begin with the letter "R", "W", or "T", respectively (in upper or lower case); records beginning with any other character will be ignored. The data records will, accordingly, have one of the following formats:
R oldclass newclass fract W class weight T class threshThe values for oldclass, newclass, and class should be entered as integers; fract, weight, and thresh should be entered as real numbers. For R records, there may be multiple records for the same oldclass; if so, all records for a given oldclass value must be together. For example, the entries
R 26 17 0.70 R 26 19 0.30will reallocate 70% of the input pixel count for class 26 to class 17, and the remaining 30% to class 19. For this example, the count for class 26 will be set to zero after the reallocation has been performed; if class 26 had been specified as one of the newclass values, the specified fraction of the original count for class 26 would be used as the final count for class 26.If a weight or threshold is specified for any class referenced by a reallocation record, the weight or threshold value will be applied after reallocation.
If the reallocation file does contain weight or threshold data, they will be used in addition to any values entered via parameters WEIGHT and THRESH; if WEIGHT or THRESH contain values for classes that also occur in the REALLOC file, the values from WEIGHT or THRESH will override those in the REALLOC file.
A landuse data set in an Albers projection and at 1 km resolution is converted to a Lambert Azimuthal projection with 4 km resolution. The output image window is defaulted to coincide with the area covered by the mapping grid, no data-type conversion is made, and the fill value for output pixels entirely outside the input image is defaulted to 0. Pixels in class 3 are given extra weighting; for example, if class 3 represents urban landuse, output pixels which contain small towns, whose area is likely to be a small fraction of a 4km by 4km pixel, are likely to be assigned to a non-urban class unless the urban pixels are given extra weight. An output pixel is not assigned to class 1 unless at least 75% of the input pixels contributing to it are in class 1; for example, if class 1 repesents water, an output pixel will be assigned the class of the most prevalent non-water landuse unless three-quarters of its area is covered by water.
A multi-band input image is converted from 30m pixels
to an output image with with the same number of bands
and 100m pixels. For each output band, the value
assigned a given output pixel is the arithmetic mean of
the values of the input pixels of the same band which
contribute to the output pixel. The map projections of
the two images may be the same or different; for
example, if the GRID file was generated from tiepoints
used to register the input 30m image to another
100m-resolution image, the output image will now be in
registration with that image.
A 1000 by 1000 pixel area of a single band image specifying soil types at 200m resolution is processed to compute the fraction of each 1km square pixel which is covered by each soil type. The fractional values are output as integer percents in one byte per pixel; i.e., the fraction is multiplied by 100 and rounded to the nearest integer.
A multi-band input image containing, in each band, the fractional occurrence of a given soil type code within the pixel, is used to produce a single-band output image containing, in each pixel, the dominant soil type within that pixel. However, the number of output soil types is less than the number of input bands because some input soil types are reallocated to other types as specified by entries in the reallocation file soils.realloc.
REGRID begins by reading the program arguments. If argument REALLOC specifies a reallocation file, this file is opened and the reallocation, weight, and threshold records are read and entered into tables. If weights and/or thresholds are specified directly through parameters WCLASS/WEIGHT and TCLASS/THRESH, these weights are added to the tables; if a given class is referenced both in the reallocation file and by direct specification, the value specified by WEIGHT or THRESH replaces that from the reallocation file.
REGRID then reads the input image DDR and uses the information to determine the maxiumum number of classes and the number of output bands that are needed for the specified aggregation function, as specified by the subcommand. The mapping grid is read in and the derivatives of input coordinates with respect to output are computed for each mapping grid cell. If WINDOPT = IN, REGRID determines the output window needed to enclose the specified input window from the mapping grid; if the input window extends outside the mapping grid an advisory message is written and, if more than half the input is outside the mapping grid, REGRID aborts processing unless the mapping represents an affine transformation (in which case the grid may be safely extended). If WINDOPT = OUT, REGRID takes the output window directly from argument OWINDOW or, if OWINDOW is defaulted, from the output window defined by the mapping grid.
Once the output window is established, REGRID trims the mapping grid to match the output window and adjusts the output coordinate values in the grid to be relative to the upper left corner of this window. To minimize rereading of input image data, REGRID then determines the input image window needed to generate each line of output. After opening the input and output files, REGRID attempts to allocate sufficient space to read in the entire image at once. If that is not possible, buffer space is allocated sufficient to hold the maximum input window needed to generate any single output line; if this allocation is also unsuccessful, REGRID aborts with a message suggesting the output image window be subdivided into vertical strips, each one to be processed separately.
The actual computation of the output image is done one line at a time. Before starting on each new line, REGRID checks whether all needed input is in memory, and if not, reads in the additional lines needed. The program also uses the mapping grid to determine the input image coordinates of each corner of each output pixel on the line.
For each pixel on the output line, REGRID then determines all input pixels which may contribute to it and clears the accumlators for tallying the contributions of each input pixel. The overlap area between each of these input pixels and the output pixel is then computed. If the aggregation mode is FRACT or MODE with a single input band, the overlap area is added to the accumulator for each band (FRACT) or for the class specified by the input pixel (MODE). If the aggregation mode is instead MEAN or MODE with multiple input bands, the pixel value for each band is multipled by the overlap area and added to the accumlator for the band.
If there is no overlap between any input pixel and the output pixel, the output pixel is assigned the fill value for all bands. Otherwise, the overlap area or area-weighted value for each class or band is divided by the total overlap area between the input image and the output pixel.
For subcommand MODE, the fractional overlap area for each class is reallocated as specified by any entries in the reallocation file, multiplied by weights as specified in the reallocation file or by program arguments WCLASS/WEIGHT, and then scanned to find the largest value for any class. The number of the class with the largest value is entered into the output pixel unless a threshold has been specified for this class and the fractional overlap area is less than the threshold value, in which case the class with the next largest value which does not fail the threshold test is used. If all classes with overlap areas greater than zero fail the threshold test, the class with the largest area is used even though it is below the threshold. If two or more classes have equal values, the lowest numbered class is output.
For subcommand MEAN, the area-weighted average of the input values for each band are entered into the corresponding output band. For FRACT, the fractional coverage for each class is entered into the corresponding output band; if an integer output data type has been requested, the value is first multipled by a scaling factor of 100, 10000, or 1000000 for BYTE, I*2, or I*4 output data type, respectively.
After writing the last output line and closing the image files, REGRID uses the projection and georeferencing information from the mapping grid file to construct the data descriptor record for the output.
The reallocation-file record whose text is included in the
message either began with an "r" or "R" which was not
followed by two integer values and one real value or else
began with a "w", "W", "t", or "T" which was not followed by
one integer and one real value. The record was ignored; if
the record should have been processed, correct the
reallocation file and rerun REGRID.
For subcommand FRACT, output band N corresponds to Class N, so there is no output band for class 0. Class 0 input pixels are ignored when computing fraction of output pixel covered by each class. See User Note 1.
The output image window defined by the mapping grid and displayed in the message is smaller than the requested output image.
Since an affine transformation is represented by a single grid cell in the mapping grid and the transformation is linear, the mapping grid may be safely extended to cover the area specified by the reqested image window.
There is a serious mismatch between the area covered by the mapping grid and the specifed input image window.
Part of the input window, but probably less than about half, extends outside the area defined by the mapping grid.
The mapping is not affine (linear), and hence may not be extended to cover the entire area specified by the input image. Instead, the input window has been reduced -- but there may still be areas in the corners of the reduced window which extend outside the mapping grid, and which will be treated as if they contain no data.
A portion of the specified input window, but less than an entire image line or column of samples, extends outside the area covered by the mapping grid.
The mapping is not affine (linear), so it may not be safely extended to cover the entire input window. Processing continues, but the corner(s) of the input image which extend outside the area covered by the mapping grid will be lost.
Portions of the output image extend outside the available input image data. Output pixels in this region will be given the value specified by FILL. Check the output image to make sure it covers the desired region.
The input-image window is small enought to fit entirely within available memory.
The band-dependent part of the data descriptor record could not be updated; the immediately preceding message may indicate the cause.
REGRID cannot continue processing because of the error condition specified in the immediately preceding message.
The specified grid file does not exist or the user does not have read access to it.
The reallocation file could not be opened for input for the reason given.
The reallocation file contained more than 10 bad records. Correct the file and rerun REGRID.
The number of entries for arguments WCLASS and WEIGHT must be equal.
The number of entries for arguments TCLASS and THRESH must be equal.
The file <IN>.ddr does not exist. Check that argument IN is correctly entered and that the .ddr file is in the same directory as the .img file.
For subcommands FRACT and MODE with a single input band, real (non-integer) data cannot be handled. Convert the data type (using, e.g., COPY) and rerun REGRID.
For subcommand FRACT, REGRID creates one output band for each class value in a single input channel; the maximum class value in the input may not exceed the maximum number of output bands supported by LAS. See User Note 1.
The band-specific part of the DDR file, <IN>.ddr, has become corrupted. Use EDITDDR to fix the record.
REGRID needs the maximum pixel value in the DDR to determine the maxiumum number of classes present. Program MINMAX will determine the maximum and minimum values and enter them into the DDR, after which REGRID may be rerun.
For subcommands MODE and FRACT, all input values must be non-negative. Rescale the input before rerunning REGRID.
For subcommand FRACT, REGRID creates one output band for each class value; the maximum class value in the input may not exceed the maximum number of output bands supported by LAS. Rescale data before rerunning REGRID. See User Note 1.
The mapping grid represents a non-affine (non-linear) transformation. If REGRID attempts to extend the grid to cover the entire area of the user-specified input or output window, excessive mapping errors may be introduced. Either adjust the window specification to match the mapping grid or create a new mapping grid with appropriate coverage.
Argument OWINDOW was entered incorrectly. The third and fourth values must be greater than zero.
The mapping grid is not useable. Create a new mapping grid.
The mapping grid corresponds to an affine (linear) transformation which maps all output points into a single line in input space. Create a new mapping grid.
The input window determined from the requested output window using the mapping grid lies entirely outside the actual input image. Check window specifications and mapping grid.
REGRID attempts to allocate memory space to accumulate the area of input pixels for every class between 0 and the maximum value of any input pixel. If this maximum value is very large, there may be insufficient memory. The maximum input value must be reduced before REGRID can run successfully.
Insufficient memory was available for efficient buffering of input data. Follow the procedures suggested by the message.
The immediately preceding message may indicate the cause of the read failure. If the starting line value is greater than 1, part of the image may have been lost during copying; check whether the block being read is in fact contained within the input image, e.g., by displaying the image.
The data descriptor record could not be updated to record the output image projection and georeferencing data. The immediately preceding message may indicate the cause. The output image file has been created, but the .DDR file will need to be updated manually, using EDITDDR-SCREEN.
If there are "unused" classes (i.e., no input pixel belongs to the class), program MAP should be used to reassign class numbers to prevent generatiion of "empty" output bands.