pihmRasterLIBS/gioapi.h

Go to the documentation of this file.
00001 
00002 /*
00003 ****************************************************
00004  
00005 Grid IO API
00006 ---------------
00007 
00008 Function Naming Conventions
00009 ---------------------------
00010 
00011 Function names are multi-word with no underscores,
00012 and the first letter of each word capitalized.
00013 For example : CellLyrOpen, GetWindowRectangle.
00014 
00015 ****************************************************
00016 */
00017 
00018 
00019 /*
00020 Constants Defining String Handling
00021 */
00022 
00023 #ifndef STRLEN
00024 #define STRLEN          129             /* Max string Length */
00025 #endif
00026 
00027 /*
00028 Defined C constants
00029 */
00030 #ifndef TRUE
00031 #define TRUE            1
00032 #endif
00033 
00034 #ifndef FALSE
00035 #define FALSE           0
00036 #endif
00037 
00038 #ifndef NULL
00039 #define NULL            0
00040 #endif
00041 
00042 /*
00043 Constants Defining CellLayer ReadWrite Flag
00044 */
00045 #ifndef READONLY
00046 #define READONLY        1
00047 #endif
00048 #ifndef READWRITE
00049 #define READWRITE       2
00050 #endif
00051 #ifndef WRITEONLY
00052 #define WRITEONLY       3
00053 #endif
00054 
00055 /*
00056 Constants Defining CellLayer I/O Mode
00057 Buffer Cache Allocation is dependent on IO mode.
00058 */
00059 
00060 #define ROWIO           1
00061 
00062 #define CELLIO          2
00063 
00064 #define BLOCKIO         3
00065 
00066 #define ROWRUNIO        4
00067 #define BLOCKRUNIO      5
00068 
00069 #define REGIONIO        6       
00070 #define REGIONRUNIO     7
00071 
00072 
00073 typedef int             CELLTYPE;       /* cell values are 32 bit quantities */
00074 
00075 #define CELLINT         1               /* 32 bit signed integers */
00076 #define CELLFLOAT       2               /* 32 bit floating point numbers*/
00077 
00078 #define CELLMAX          2147483646     /* maximum integer value  (2**31 - 2) */
00079 #define CELLMIN         -2147483646     /* minimum integer value -(2**31 - 2) */
00080 
00081 
00082 
00083 #define MISSINGINT      -2147483647     /* CELLMIN - 1 */
00084 
00085 
00086 void  GetMissingFloat(float *);
00087           
00088 
00089 /*
00090  * ------------------------------------------------------------------
00091  */
00092 
00093 
00094 /*
00095  * Grid Management Functions
00096  * -------------------------
00097  *
00098  * GridExists - check for existence of a grid 
00099  * GridCopy - copy a grid given from and to pathnames
00100  * GridRename - rename a grid given old and new pathnames
00101  * GridDelete - delete a grid removing all 
00102  *              component files including info files 
00103  * GridKill - delete a grid with options for component removal 
00104  * DescribeGridDbl - Describe spatial, statistical and attribute
00105  *                   characteristics of a grid
00106  * BndCellRead - read the bounding box for a grid
00107  */
00108 
00109 int GridExists(char *grid_name);
00110 int GridCopy(char *from_grid, char *to_grid);
00111 int GridRename(char *from_grid, char *to_grid);
00112 int GridDelete(char *grid_name);
00113 int GridKill(char *grid_name, int option);
00114 
00115 int DescribeGridDbl(char *grdnam, double *cellsz, int *gridsz, 
00116                     double *box, double *sta, 
00117                     int *datatyp, int *nclass, int *reclen);
00118 
00119 
00120 int BndCellRead (char *grdnam, double *box); 
00121 
00122 
00123 
00124 
00125 /* 
00126  * CLYRIO : Access operations on Grids
00127  * -----------------------------------
00128  */
00129 
00130 /*
00131  * PURPOSE
00132  *
00133  * CLYRIO performs I/O operations on grids.
00134  * It consists of a library of C functions that allow the user
00135  * to read and write raster data by row, rectangle or cell
00136  * to or from a specified area of a grid at a specified resolution. 
00137  * It handles windowing, resampling, 
00138  * attribute access and data compression 
00139  * in a manner transparent to the application program.
00140  */
00141 
00142 /*
00143  * IMPLEMENTATION
00144  *
00145  * Grids are based on a locational data model in which space is partitioned
00146  * into square cells. Each cell in a grid stores a numeric value.
00147  * Integer Grids are also accompanied by Value Attribute Tables that
00148  * can store attributes defined on the set of values for a grid. 
00149  *
00150  * A grid exists in a cartesian coordinate system, and the rows and columns in the
00151  * grid are parallel to the axes of the coordinate system.
00152  * Grids in a database that are used for joint analysis
00153  * need not be at the same resolution
00154  * or cover exactly the same spatial area
00155  * but they must be in the same map projection.
00156  * 
00157  * Grids are implemented using a tiled raster data structure
00158  * in which the basic unit of data storage is 
00159  * a rectangular block of cells. 
00160  *
00161  * A Cell Layer is a raster layer defined
00162  * by a grid name and optionally an item name in the VAT.
00163  * The CLYRIO module allows an aplication program to
00164  * create, open and close cell layers and 
00165  * to read and write data from and
00166  * to cell layers. 
00167  * All access to the data in a cell layer is 
00168  * made through a rectangular window in cartesian (map) coordinate space.
00169  * The extent and resolution of 
00170  * this window must be set by the application program by calling
00171  * the WindowSet routine, prior to performing any
00172  * I/O operations.
00173  * Once a window has been set, an application program can access the cells 
00174  * in a cell layer by row, rectangle, or cell - all specified 
00175  * relative to the virtual raster represented by the window.
00176  *
00177  * The I/O units used by the application program are  
00178  * the Window-Row spanning the width of the window, the Window-Band consisting
00179  * of a set of contiguos rows, the Window-Rectangle consisting of a 2D rectangle
00180  * contained in the window and, the Window-Cell consisting of a single cell
00181  * specified by its window row and column coordinates.
00182  * All cell data is automatically resampled to the window cell size on retrieval
00183  * during row and cell access. 
00184  *
00185  * An application program can either set a global window 
00186  * that is applied to all cell layers accessed or set a separate 
00187  * window for each layer accessed. The latter mode is suitable 
00188  * when transforming a grid from one coordinate system to another
00189  * such as during warping or projection. 
00190  * 
00191  * Grids may be integer or floating point.
00192  * Integer grids are accompanied by a Value Attribute Table.
00193  * The CLYRIO module supports spatial access to the numeric value 
00194  * attributes associated with a grid by supporting 
00195  * a grid.item naming convention for cell layers that correspond 
00196  * to grid value attributes.
00197  * If an item name is specified when a Cell Layer is opened
00198  * for read access then the values returned for the cells retrieved
00199  * will be the values for the specified item.
00200  * 
00201  */
00202 
00203 
00204  
00205 /* 
00206  * Initialization  and Termination
00207  * --------------------------------
00208  *
00209  * GridIOSetup - Initialize the Grid IO library
00210  * GridIOExit  - Call when done using the Grid IO library
00211  */
00212 int GridIOSetup(void);
00213 int GridIOExit(void);
00214 
00215 
00216 /* 
00217  * Creating, Opening and Closing Grids :
00218  * -----------------------------------
00219  *
00220  * CellLyrExists - Check if a cell layer exists.
00221  * CellLayerCreate - Create a new Cell Layer using the default blocksize.
00222  * CellLayerCreateTiled - Create a new Cell Layer using the specified blocksize.
00223  * CellLayerOpen - Open an existing Cell Layer.
00224  * CellLyrClose - Close an opened or created Cell Layer, 
00225  *                automatically builds VAT and STA.
00226  * CellLyrCloseNoVat - Close an opened or created Cell Layer, 
00227  *                     does not build VAT.
00228  * CellLyrDelete - Delete a cell layer.
00229  *
00230  * IO mode 
00231  * -------
00232  *
00233  * The client is responsible for selecting an IO mode
00234  * when opening or creating a cell layer and for using 
00235  * the access method appropriate for the current IO mode.
00236  * The IO mode can be reset while the layer is opened.
00237  * The permissible values for IO mode are
00238  * ROWIO, ROWRUNIO, CELLIO, REGIONIO, REGIONRUNIO, BLOCKIO and BLOCKRUNIO
00239  * For a more detailed description of these modes see the
00240  * section on IO mode below.
00241  *
00242  * ReadWriteFlag
00243  * -------------
00244  * A celllayer is opened READONLY or READWRITE 
00245  *
00246  * Compression
00247  * -----------
00248  *
00249  * Integer grids are stored in a run length compressed format.
00250  * Floating point grids are stored in uncompressed format.
00251  *
00252  */
00253 
00254 #define  ROWIO               1
00255 #define  CELLIO              2
00256 #define  BLOCKIO             3
00257 #define  ROWRUNIO            4
00258 #define  BLOCKRUNIO          5
00259 #define  REGIONIO            6
00260 #define  REGIONRUNIO         7
00261 
00262 
00263 #define  READONLY            1
00264 #define  READWRITE           2
00265 
00266 
00267 #define  ADAPTIVE           -1
00268 
00269 #define  COMPRESSED          0
00270 #define  UNCOMPRESSED        1
00271 
00272 int CellLyrExists (char *clyr_name);
00273 
00274 int CellLayerCreate (char *clyr_name, int rdwrflag, int iomode, 
00275                      int celltype, double cellsize, double box[4]);
00276 
00277 int CellLayerCreateTiled (char *clyr_name, int rdwrflag, int iomode, 
00278                           int  celltype, double cellsize, double box[4], 
00279                           int blockxcells, int blockycells);
00280 
00281 int CellLayerOpen (char *clyr_name, int rdwrflag, int iomode, 
00282                    int  *celltype, double *cellsize);
00283 
00284 int CellLyrClose (int channel);
00285 int CellLyrCloseNoVat (int channel);
00286 int CellLyrDelete (char *clyr_name);
00287 
00288 /*
00289  * AcessDepth 
00290  *
00291  * CLYRIO mantains an internal cache of block buffers for each opened grid.
00292  *
00293  * The process of performing IO on a cell layer involves
00294  * mapping data between client buffers and cache buffers
00295  * for the layer and between the cache buffers and records on disk. 
00296  * Data compression is applied in the process of mapping data between the 
00297  * cache buffers and records on disk and is hidden from the client.
00298  * 
00299  * When a layer is opened in 32 bit mode the client is responsible
00300  * for ensuring that all client (input and output) buffers used in the
00301  * CLYRIO API functions are 32 bits per cell.
00302  * In 32 bit access mode all the block buffers in the cache for the layer
00303  * are also 32 bits per cell.
00304  * The Client is responsible for using the 32 bit API functions.
00305  * By default a layer is opened in 32 bit mode.
00306  *
00307  *
00308  */
00309  
00310  
00311 
00312 /*
00313  * IO mode 
00314  *
00315  * The client is responsible for using 
00316  * the access method appropriate for the current IO mode.
00317  * The IO modes supported are :
00318  *
00319  * ROWIO - To Get and Put Rows of Cells
00320  * CELLIO - To Get and Put individual cells
00321  * REGIONIO - To Get and Put Rectangles of cells
00322  *
00323  * The IO mode for an opened layer can be queried and changed
00324  * with the following API calls
00325  *
00326  */
00327 int CellLyrGetIO(int channel);
00328 int CellLyrSetIO(int channel, int mode);
00329 
00330 
00331 /*
00332  * Getting information about an opened cell layer given its handle
00333  *
00334  * CellLyrName - query the grid name for the cell layer 
00335  * CellLyrItem - query the item name for the cell layer 
00336  * CellLyrEvalType - query the cell type for the cell layer, 
00337  *                   the cell type is based on the type of the item
00338  * CellLyrBlockSize - query the block size for the cell layer 
00339  * CellLyrSta - query the statistics for the cell layer 
00340  */
00341 
00342 int CellLyrName (int channel, char *name);
00343 int CellLyrItem (int channel, char *name);
00344 int CellLyrEvalType (int channel);
00345 int CellLyrBlockSize (int channel, int *bxcells, int *bycells);
00346 int CellLyrSta (int channel, double *dmin, double *dmax, 
00347                 double *dmean, double *dstdv);
00348 
00349 
00350 /* 
00351  * Setting and Querying the Overlay Window for Multi-Layer registered I/O
00352  *
00353  * AccessWindowSet - Set the Overlay Window
00354  * WindowRows - Return number of rows in the overlay window.
00355  * WindowCols - Return number of columns in the overlay window.
00356  * WindowBox - Return the box for the overlay window.
00357  * XY2WindowColRow - translate from map to window cell coordinates
00358  * AccessWindowClear - Clear the Overlay Window
00359  */
00360 
00361 int AccessWindowSet(double box[4], double cellsize, double newbox[4]);
00362 int WindowRows(void);
00363 int WindowCols(void);
00364 int WindowBox(double box[4]);
00365 int XY2WindowColRow(double x, double y, int *col, int *row);
00366 int AccessWindowClear(void);
00367 
00368 /*
00369  * 
00370  * Routines for Setting Separate Windows for each layer 
00371  *
00372  * PrivateAccessWindowSet - Set the Window for the specified layer.
00373  * PrivateWindowRows - Return number of rows in window for specified layer.
00374  * PrivateWindowColumns - Return number of columns in window for specified layer.
00375  * PrivateWindowBox - Return the box for the window for specified layer.
00376  * XY2PrivateWindowColRow - translate from map to window cell coordinates
00377  * PrivateAccessWindowClear - Clear the window for the specified layer
00378  */
00379 
00380 int PrivateAccessWindowSet(int channel, double box[4], 
00381                            double cellsize, double newbox[4]);
00382 int PrivateWindowCols(int i);
00383 int PrivateWindowRows(int i);
00384 int PrivateWindowBox(int i, double box[4]);
00385 int XY2PrivateWindowColRow(int i, double x, double y, int *col, int *row);
00386 int PrivateAccessWindowClear(int channel);
00387 
00388 
00389 /*
00390  * Memory Allocation for Rows, Bands and Rectangles
00391  *
00392  * CAllocate1 - allocate a 1 dimensional  array (Row)
00393  *              that can be accessed as pointer[i]
00394  * CAllocate2 - allocate a 2 dimensional "array" (Rectangle, Band)
00395  *              that can be accessed as pointer[i][j]
00396  * CAllocate3 - allocate a 3 dimensional "array" 
00397  *              that can be accessed as pointer[i][j][k]
00398  * CFree1     - free a 1 dimensional array
00399  * CFree2     - free a 2 dimensional array
00400  * CFree3     - free a 3 dimensional array
00401  *
00402  */
00403 
00404 char *CAllocate1(int number, int size);
00405 char **CAllocate2(int nrows, int ncols, int size);
00406 char ***CAllocate3(int nlyrs, int nrows, int ncols, int size);
00407 
00408 void CFree1(char *ptr);
00409 void CFree2(char **ptr, int nrows);
00410 void CFree3(char ***ptr, int nlyrs, int nrows);
00411 
00412 /* 
00413  * ACCESS FUNCTIONS :
00414  * The following functions access the data within the window for a given layer.
00415  * The window may be the overlay window, or the private window set for the layer.
00416  */
00417 
00418 /*
00419  * Routines for 32 bit ROW based access :
00420  * 
00421  * GetWindowRow - Get a row spanning the window for a layer
00422  *                as a buffer of 32 bit values.
00423  *                Client must interpret the type of the output buffer
00424  *                to be the type of the layer being read from (32 bit int or float).
00425  *
00426  * GetWindowRowFloat - Get a row as a buffer of 32 bit floating points
00427  * GetWindowRowInt - Get a row as a buffer of 32 bit integers
00428  *
00429  * PutWindowRow - Put a row spanning the window for a layer
00430  *                as a buffer of 32 bit values.
00431  *                Client must ensure that the type of the input buffer
00432  *                (32 bit int or float) is the type of the layer being written to.  
00433  *
00434  * The following band access functions retrieve contiguos sets of
00435  * rows into a two dimensional buffer.
00436  *               
00437  * GetWindowBand - Get a band of rows spanning the window for a layer.
00438  *                 Client must interpret the type of the output buffer
00439  *                 to be the type of the layer being read from (32 bit int or float).
00440  * GetWindowBandFloat - Get a band of rows as a buffer of 32 bit floating points
00441  * GetWindowBandInt - Get a band of rows as a buffer of 32 bit ints
00442  *
00443  * PutWindowBand - Put a band of rows spanning the window for a layer.
00444  *                Client must ensure that the type of the input buffer
00445  *                (32 bit int or float) is the type of the layer being written to.  
00446  *
00447  */
00448 
00449 
00450 int GetWindowRow(int channel, int nreswinrow, CELLTYPE *rowbuf);
00451 int GetWindowRowFloat(int channel, int nreswinrow, float *rowbuf);
00452 int GetWindowRowInt(int channel, int nreswinrow, int *rowbuf);
00453 
00454 int PutWindowRow(int channel, int nwinrow, CELLTYPE *rowbuf);
00455 
00456 int GetWindowBand(int channel, int startrow, int nrows, CELLTYPE **bandbuf);
00457 int GetWindowBandFloat(int channel, int startrow, int nrows, float **bandbuf);
00458 int GetWindowBandInt(int channel, int startrow, int nrows, int **bandbuf);
00459 
00460 int PutWindowBand(int channel, int startrow, int nrows, CELLTYPE **bandbuf);
00461 
00462 
00463 
00464 
00465 /*
00466  * Routines for 32 bit REGION (rectangle) based access :
00467  *
00468  * GetWindowRectangle - Get a rectangle of cells within the window for a layer
00469  *                      as a 2D buffer of 32 bit values.
00470  *                      Client must interpret the type of the output buffer
00471  *                      to be the type of the layer being read from 
00472  *                      (32 bit int or float).
00473  *
00474  * GetWindowRectangleInt - Get a rectangle of cells within the window for a layer
00475  *                         as a 2D buffer of 32 bit integers.
00476  *
00477  * GetWindowRectangleFloat - Get a rectangle of cells within the window for a layer
00478  *                         as a 2D buffer of 32 bit floats.
00479  *
00480  * PutWindowRectangle - Put a rectangle of cells within the window for a layer
00481  *                      as a 2D buffer of 32 bit values.
00482  *                      Client must ensure that the type of the input buffer
00483  *                      (32 bit int or float) is the type of the 
00484  *                      layer being written to.  
00485  */
00486 
00487 int GetWindowRectangle(int channel, int rxul, int ryul, 
00488                        int rxcells, int rycells, CELLTYPE **rbuf);
00489 int GetWindowRectangleInt(int channel, int rxul, int ryul, 
00490                           int rxcells, int rycells, int **rbuf);
00491 int GetWindowRectangleFloat(int channel, int rxul, int ryul, 
00492                             int rxcells, int rycells, float **rbuf);
00493 
00494 int PutWindowRectangle(int channel, int rxul, int ryul, 
00495                        int rxcells, int rycells, CELLTYPE **rbuf);
00496 
00497 
00498 /*
00499  * Routines for 32 bit CELL based access :
00500  *
00501  * GetWindowCell - Get a cell within the window for a layer,
00502  *                 Client must interpret the type of the output 32 Bit Ptr
00503  *                 to be the type of the layer being read from.
00504  *
00505  * GetWindowCellFloat - Get a cell within the window for a layer as a 32 Bit Float
00506  *
00507  * GetWindowCellInt - Get a cell within the window for a layer as a 32 Bit Integer
00508  *
00509  * PutWindowCell - Put a cell within the window for a layer.
00510  *                 Client must ensure that the type of the input 32 Bit Ptr
00511  *                 is the type of the layer being read from.
00512  *
00513  *
00514  * PutWindowCellFloat - Put a cell within the window for a layer as a 32 Bit Float
00515  *
00516  * PutWindowCellInt - Put a cell within the window for a layer as a 32 Bit Integer
00517  *
00518  */
00519 int GetWindowCell(int channel, int rescol, int resrow, CELLTYPE *cell);
00520 int GetWindowCellFloat(int channel, int rescol, int resrow, float *cell);
00521 int GetWindowCellInt(int channel, int rescol, int resrow, int *cell);
00522 
00523 int PutWindowCellFloat(int channel, int col, int row, double fcell);
00524 int PutWindowCellInt(int channel, int col, int row, int icell);
00525 int PutWindowCell(int channel, int col, int row, CELLTYPE cell);
00526 
00527 
00528 /*
00529  * STAIO : Read Statistics for a cell layer
00530  *
00531  * StaGetDbl - get min, max, mean and stdv for a cell layer
00532  * StaGetMinMaxDbl - get min and max for a cell layer
00533  *
00534  */
00535 
00536 int StaGetDbl(char *clyr_name, double *dmin, double *dmax, 
00537                               double *dmean, double *dstdv);
00538 
00539 int StaGetMinmaxDbl(char *clyr_name, double *dmin, double *dmax);
00540 

Generated on Sun Aug 5 17:34:00 2007 for PIHMgis by  doxygen 1.5.2