calcArea
Description
calcArea calculates the valid data coverage area (in square meters and square kilometers) of one or more OMG/JHC raster grid files (.r4 32-bit floating-point grids or .8bit/.mos 8-bit unsigned integer grids). Written by Ian Church in December 2012, the tool reads the 1024-byte JHC_header of each input map sheet, verifies that the grid uses a projected coordinate system, computes the area of each pixel (xstep * ystep), and sums the area of all non-empty grid cells across each file and across the entire batch of input files.
Usage
calcArea [-v] -in <mapSheet1> [mapSheet2 ...]
Example Commands
Calculate the surveyed area of a single .r4 bathymetric grid:
calcArea -in bay_of_fundy_2m.r4
Calculate individual sheet areas and total combined coverage across multiple .r4 or .8bit map sheets:
calcArea -v -in sheet01.r4 sheet02.r4 sheet03.r4
CLI Arguments and Options
| Flag / Argument | Parameters | Description |
|---|---|---|
-v | None | Increments the verbosity flag (verbose_flag). |
-in | <file1> [file2 ...] | Required. One or more OMG raster grid files (.r4, .8bit, .mos), up to 10,000 files. Consumes all subsequent arguments until the next - flag or end of command line. |
File Formats
Input Formats: OMG Raster Grids (.r4, .8bit, .mos)
- Header: 1024-byte
JHC_headerread viaread_JHC_header(FILE *, JHC_header *)(fromarray.h). Key header fields used bycalcArea:projection: Must not be0(unprojected) or3(geographic lat/lon); otherwisecalcAreaprintsMap is not projected, so can't calculate area....skippingand skips the file.data_type:3indicates 32-bit floating-point (float,.r4); other values are treated as 8-bit unsigned char (unsigned char,.8bit/.mos).dx,dy: Grid dimensions in pixels (columns and rows).xstep,ystep: Cell resolution in meters along X and Y.
- Grid Data Payload:
- For
.r4files (data_type == 3): A pixel is counted as valid data ifvarF != 0.0f. - For 8-bit files (
data_type != 3): A pixel is counted as valid data ifvar != 0 && var != 255(since both0and255represent background/no-data in OMG 8-bit images).
- For
Output Format
For each valid projected map sheet, calcArea prints a single summary line to stdout:
Map <filename> area: <sumArea> m^2 of <mapArea> m^2 total area ( <percent> percent )
When more than one input file is provided (nFiles > 1), a grand total line is printed at the end:
Total Area of all input maps: <totalArea> m^2 or <totalArea_km2> km^2
How It Works
- Header Inspection & Projection Check: For each file passed after
-in,calcAreaopens the file in binary read mode ("rb") and callsread_JHC_header(). IfJHChead.projection == 0 || JHChead.projection == 3, the grid steps are not in linear meters, so the file is skipped. - Pixel & Bounding Box Area Calculation:
- Total number of grid cells:
pixels = JHChead.dx * JHChead.dy - Single-cell area:
pixArea = JHChead.xstep * JHChead.ystep - Total bounding-box area:
mapArea = pixArea * pixels
- Total number of grid cells:
- Cell-by-Cell Accumulation:
- If
JHChead.data_type == 3(r4Flag == 1), the program reads 4-bytefloatvalues untilfeof(), addingpixAreatosumAreawhenevervarF != 0. - Otherwise, it reads 1-byte
unsigned charvalues untilfeof(), addingpixAreatosumAreawhenevervar != 0 && var != 255.
- If
- Multi-Sheet Aggregation: Each sheetβs
sumAreais added tototalArea, and ifnFiles > 1, the total area is reported in both square meters (m^2) and square kilometers (totalArea / 1000000).