Changes between Version 5 and Version 6 of rfc62_raster_algebra


Ignore:
Timestamp:
Apr 26, 2016, 7:42:56 AM (8 years ago)
Author:
Ari Jolma
Comment:

Refresh the API, add proposal: no C API

Legend:

Unmodified
Added
Removed
Modified
  • rfc62_raster_algebra

    v5 v6  
    1111== Summary ==
    1212
    13 It is proposed that a set of functions or methods for raster band object are written to support "raster algebra", i.e., a set of operations, which modify bands or compute values from bands. An example of a modification is adding a value to all the cells of the band. An example of a computation is the maximum cell value in the band. Operations may or may not take arguments, in addition to the band itself, and if they take, the argument may be a numeric value, a data structure, or another band. Similarly, the computed value may be a simple numeric value, a data structure, or another band.
     13It is proposed that a set of functions or methods are written for raster band objects to support "raster algebra", i.e., a set of operations, which modify bands or compute values from bands. An example of a modification is adding a value to all the cells of the band. An example of a computation is the maximum cell value in the band. Operations may or may not take arguments, in addition to the band itself, and if they take, the argument may be a numeric value, a data structure, or another band. Similarly, the computed value may be a simple numeric value, a data structure, or another band.
    1414
    1515== Rationale ==
     
    1919== Approach ==
    2020
    21 GDAL presents a few problems to raster algebra implementation: 1) the access to data is based on blocks, 2) GDAL supports several datatypes, even complex values, and 3) there is no immediate support for the not-simple data structures needed by some methods (by "method" I refer to functions of raster algebra in this text). In the development version of raster algebra for GDAL (see below the github link) these problems are solved as follows.
     21GDAL presents a few problems to raster algebra implementation: 1) the access to data is based on blocks, 2) GDAL supports several datatypes, even complex values, and 3) there is no immediate support for the not-simple data structures needed by some methods (by "method" I refer to functions of raster algebra in this text). It is proposed to solve these problems as follows.
    2222
    23231) The code is organized into two levels: the first one, which loops through all blocks in band(s) and maintains a cache of needed blocks, and the second one, which loops through all cells in a block. The first level is generic one and the method and its arguments just pass through it. The method is passed as a callback and arguments as pointers to objects of base class. The second one is method specific, it is where the method is really implemented. The method callbacks must have similar prototype and their return value is used to, e.g., determine whether the block needs to be written to disk etc.
    2424
    25 2) C++ templates are used to convey to the method functions the cell datatype.
     252) C++ templates will be used to generically support multiple cell datatypes. However, an interface class will be written, which is not templated, so the user is not distracted with the datatype too much.
    2626
    27273) An interface class structure is used for arguments and return values (non-band). The interface classes are not templated, they shadow actual classes, which are templated and use STL as much as possible.
     28
     29== The API ==
     30
     31A proposal is to have only a C++ interface, and also base the bindings on this C++ interface.
    2832
    2933{{{
     
    3438class gma_object_t {
    3539public:
    36     virtual ~gma_object_t() {};
    37     virtual gma_class_t get_class() {return gma_object;};
    38     virtual gma_object_t *clone() {};
     40    virtual ~gma_object_t();
     41    virtual gma_class_t get_class();
    3942};
    4043
    4144class gma_number_t : public gma_object_t {
    4245public:
    43     virtual gma_class_t get_class() {return gma_number;};
    44     virtual void set_value(double value) {};
    45     virtual void set_value(int value) {};
    46     virtual int value_as_int() {};
    47     virtual double value_as_double() {};
    48     virtual gma_number_t *clone() {};
    49     virtual void set_inf(int inf) {}; // -1 to minus inf, 0 to not inf, 1 to plus inf
    50     virtual bool is_inf() {};
    51     virtual bool is_integer() {};
    52     virtual bool is_float() {};
     46    virtual GDALDataType datatype();
     47    virtual void set_value(double value);
     48    virtual void set_value(int value);
     49    virtual int value_as_int();
     50    virtual double value_as_double();
     51    virtual bool is_defined();
     52    virtual void set_inf(int inf); // -1 to minus inf, 0 to not inf, 1 to plus inf
     53    virtual bool is_inf();
     54    virtual bool is_integer();
     55    virtual bool is_float();
    5356};
    5457
    5558class gma_pair_t : public gma_object_t {
    5659public:
    57     virtual gma_class_t get_class() {return gma_pair;};
    58     virtual void set_first(gma_object_t *first) {};
    59     virtual void set_second(gma_object_t *second) {};   
    60     virtual gma_object_t *first() {};
    61     virtual gma_object_t *second() {};
     60    virtual void set_first(gma_object_t *first);
     61    virtual void set_second(gma_object_t *second);   
     62    virtual gma_object_t *first();
     63    virtual gma_object_t *second();
    6264};
    6365
    6466class gma_bins_t : public gma_object_t {
    6567public:
    66     virtual gma_class_t get_class() {return gma_bins;};
    67     virtual unsigned int size() {};
    68     virtual void push(int value) {};
    69     virtual void push(double value) {};
     68    virtual GDALDataType datatype();
     69    virtual unsigned int size();
     70    virtual void push(int value);
     71    virtual void push(double value);
    7072};
    7173
    7274class gma_histogram_t : public gma_object_t {
    7375public:
    74     virtual gma_class_t get_class() {return gma_histogram;};
    75     virtual unsigned int size() {};
    76     virtual gma_object_t *at(unsigned int i) {};
     76    virtual GDALDataType datatype();
     77    virtual unsigned int size();
     78    virtual gma_object_t *at(unsigned int i);
     79    virtual void print();
    7780};
    7881
    7982class gma_classifier_t : public gma_object_t {
    8083public:
    81     virtual gma_class_t get_class() {return gma_classifier;};
    82     virtual void add_class(gma_number_t *interval_max, gma_number_t *value) {};
    83     virtual unsigned int size() {};
    84     virtual gma_object_t *at(unsigned int i) {};
     84    virtual GDALDataType datatype();
     85    virtual unsigned int size();
     86    virtual void add_class(gma_number_t *interval_max, gma_number_t *value);
     87    virtual void add_value(gma_number_t *old_value, gma_number_t *new_value);
     88    virtual void add_default(gma_number_t *default_value);
    8589};
    8690
    8791class gma_cell_t  : public gma_object_t {
    8892public:
    89     virtual gma_class_t get_class() {return gma_cell;};
    90     virtual int& x() {};
    91     virtual int& y() {};
    92     virtual void set_value(double value) {};
    93     virtual void set_value(int value) {};
    94     virtual int value_as_int() {};
    95     virtual double value_as_double() {};
     93    virtual GDALDataType datatype();
     94    virtual int& x();
     95    virtual int& y();
     96    virtual void set_value(double value);
     97    virtual void set_value(int value);
     98    virtual int value_as_int();
     99    virtual double value_as_double();
    96100};
    97101
     
    104108class gma_cell_callback_t : public gma_object_t {
    105109public:
    106     virtual gma_class_t get_class() {return gma_cell_callback;};
    107     virtual void set_callback(gma_cell_callback_f callback) {};
    108     virtual void set_user_data(gma_object_t*) {};
     110    virtual void set_callback(gma_cell_callback_f callback);
     111    virtual void set_user_data(gma_object_t*);
    109112};
    110113
    111114class gma_logical_operation_t  : public gma_object_t {
    112115public:
    113     virtual gma_class_t get_class() {return gma_logical_operation;};
    114     virtual void set_operation(gma_operator_t) {};
    115     virtual void set_value(int value) {};
    116     virtual void set_value(double value) {};
     116    virtual GDALDataType datatype();
     117    virtual void set_operation(gma_operator_t);
     118    virtual void set_value(int value);
     119    virtual void set_value(double value);
    117120};
    118121
    119122class gma_hash_t : public gma_object_t {
    120123public:
    121     virtual gma_class_t get_class() {return gma_hash;};
    122     virtual int size() {};
    123     virtual std::vector<gma_number_t*> *keys_sorted() {};
    124     virtual gma_object_t *get(gma_number_t *key) {};
     124    virtual GDALDataType datatype();
     125    virtual int size();
     126    virtual std::vector<gma_number_t*> *keys_sorted();
     127    virtual gma_object_t *get(gma_number_t *key);
    125128};
    126129
    127130class gma_band_t : public gma_object_t {
    128131public:
    129     virtual gma_class_t get_class() {return gma_band;};
    130     virtual GDALDataType gdal_datatype() {};
    131     virtual gma_number_t *new_number(int value) {};
    132 
    133     virtual void print() {};
    134     virtual void rand() {};
    135     virtual void abs() {};
    136     virtual void exp() {};
    137     virtual void log() {};
    138     virtual void log10() {};
    139     virtual void sqrt() {};
    140     virtual void sin() {};
    141     virtual void cos() {};
    142     virtual void tan() {};
    143     virtual void ceil() {};
    144     virtual void floor() {};
    145 
    146     virtual void assign(int value) {};
    147     virtual void assign_all(int value) {};
    148     virtual void add(int summand) {};
    149     virtual void subtract(int) {};
    150     virtual void multiply(int) {};
    151     virtual void divide(int) {};
    152     virtual void modulus(int divisor) {};
     132    virtual void update();
     133    virtual GDALRasterBand *band();
     134    virtual GDALDataset *dataset();
     135    virtual GDALDriver *driver();
     136    virtual GDALDataType datatype();
     137    virtual bool datatype_is_integer();
     138    virtual bool datatype_is_float();
     139    virtual int w();
     140    virtual int h();
     141
     142    virtual void set_progress_fct(GDALProgressFunc progress, void * progress_arg);
     143
     144    virtual gma_band_t *new_band(const char *name, GDALDataType datatype);
     145    virtual gma_number_t *new_number();
     146    virtual gma_number_t *new_int(int value);
     147    virtual gma_pair_t *new_pair();
     148    virtual gma_pair_t *new_range();
     149    virtual gma_bins_t *new_bins();
     150    virtual gma_cell_t *new_cell();
     151    virtual gma_classifier_t *new_classifier();
     152    virtual gma_cell_callback_t *new_cell_callback();
     153    virtual gma_logical_operation_t *new_logical_operation();
     154
     155    virtual void print();
     156    virtual void rand();
     157    virtual void abs();
     158    virtual void exp();
     159    virtual void log();
     160    virtual void log10();
     161    virtual void sqrt();
     162    virtual void sin();
     163    virtual void cos();
     164    virtual void tan();
     165    virtual void ceil();
     166    virtual void floor();
     167
     168    virtual void assign(int value);
     169    virtual void assign_all(int value);
     170    virtual void add(int summand);
     171    virtual void subtract(int);
     172    virtual void multiply(int);
     173    virtual void divide(int);
     174    virtual void modulus(int divisor);
    153175   
    154     virtual void assign(double value) {};
    155     virtual void assign_all(double value) {};
    156     virtual void add(double summand) {};
    157     virtual void subtract(double) {};
    158     virtual void multiply(double) {};
    159     virtual void divide(double) {};
    160 
    161     virtual void classify(gma_classifier_t*) {};
    162     virtual void cell_callback(gma_cell_callback_t*) {};
     176    virtual void assign(double value);
     177    virtual void assign_all(double value);
     178    virtual void add(double summand);
     179    virtual void subtract(double);
     180    virtual void multiply(double);
     181    virtual void divide(double);
     182
     183    virtual void classify(gma_classifier_t*);
     184    virtual void cell_callback(gma_cell_callback_t*);
    163185
    164186    // arg = NULL, pair:(n,pair:(min,max)), or bins; returns histogram
    165     virtual gma_histogram_t *histogram(gma_object_t *arg = NULL) {};
     187    virtual gma_histogram_t *histogram(gma_object_t *arg = NULL);
    166188    // returns hash of a hashes, keys are zone numbers
    167     virtual gma_hash_t *zonal_neighbors() {};
    168     virtual gma_number_t *get_min() {};
    169     virtual gma_number_t *get_max() {};
     189    virtual gma_hash_t *zonal_neighbors();
     190    virtual gma_number_t *get_min();
     191    virtual gma_number_t *get_max();
    170192    // returns a pair of numbers
    171     virtual gma_pair_t *get_range() {};
    172     virtual std::vector<gma_cell_t*> *gma_method_get_cells() {};
    173 
    174     virtual void assign(gma_band_t *) {};
    175     virtual void add(gma_band_t *summand) {};
    176     virtual void subtract(gma_band_t *) {};
    177     virtual void multiply(gma_band_t *) {};
    178     virtual void divide(gma_band_t *) {};
    179     virtual void modulus(gma_band_t *) {};
    180 
    181     virtual gma_hash_t *zonal_min(gma_band_t *zones) {};
    182     virtual gma_hash_t *zonal_max(gma_band_t *zones) {};
    183 
    184     virtual void rim_by8(gma_band_t *areas) {};
    185 
    186     virtual void fill_depressions(gma_band_t *dem) {};
    187     virtual void D8(gma_band_t *dem) {};
    188     virtual void route_flats(gma_band_t *dem) {};
    189     virtual void upstream_area(gma_band_t *) {};
    190     virtual void catchment(gma_band_t *, gma_cell_t *) {};
    191 
    192 };
    193 
     193    virtual gma_pair_t *get_range();
     194    virtual std::vector<gma_cell_t*> *cells();
     195
     196    // op can be used to make the operation conditional,
     197    // the test is made against the value of the parameter band
     198    virtual void assign(gma_band_t *, gma_logical_operation_t *op = NULL);
     199    virtual void add(gma_band_t *, gma_logical_operation_t *op = NULL);
     200    virtual void subtract(gma_band_t *, gma_logical_operation_t *op = NULL);
     201    virtual void multiply(gma_band_t *, gma_logical_operation_t *op = NULL);
     202    virtual void divide(gma_band_t *, gma_logical_operation_t *op = NULL);
     203    virtual void modulus(gma_band_t *, gma_logical_operation_t *op = NULL);
     204
     205    // this = value where decision is true
     206    // the decision band must be of type uint8_t
     207    virtual void decision(gma_band_t *value, gma_band_t *decision);
     208
     209    virtual gma_hash_t *zonal_min(gma_band_t *zones);
     210    virtual gma_hash_t *zonal_max(gma_band_t *zones);
     211
     212    virtual void rim_by8(gma_band_t *areas);
     213
     214    virtual void fill_depressions(gma_band_t *dem);
     215    virtual void D8(gma_band_t *dem);
     216    virtual void route_flats(gma_band_t *dem);
     217    virtual void upstream_area(gma_band_t *);
     218    virtual void catchment(gma_band_t *, gma_cell_t *);
     219
     220};
     221
     222// a band object factory
     223gma_band_t *gma_new_band(GDALRasterBand *b);
    194224
    195225}}}
     
    197227== Changes ==
    198228
    199 
    200229== Drivers ==
    201230
     
    229258
    230259== Voting history
    231