/usr/include/terralib/kernel/TeCoverage.h is in libterralib-dev 4.0.0-5ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | /************************************************************************************
TerraLib - a library for developing GIS applications.
Copyright © 2001-2007 INPE and Tecgraf/PUC-Rio.
This code is part of the TerraLib library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
You should have received a copy of the GNU Lesser General Public
License along with this library.
The authors reassure the license terms regarding the warranties.
They specifically disclaim any warranties, including, but not limited to,
the implied warranties of merchantability and fitness for a particular purpose.
The library provided hereunder is on an "as is" basis, and the authors have no
obligation to provide maintenance, support, updates, enhancements, or modifications.
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
indirect, special, incidental, or consequential damages arising out of the use
of this library and its documentation.
*************************************************************************************/
/*!
\file TeCoverage.h
\par This file contains structures and definitions for a generic
Coverage representation.
*/
#ifndef __TERRALIB_INTERNAL_COVERAGE_H
#define __TERRALIB_INTERNAL_COVERAGE_H
#include "TeGeometry.h"
#include "TeDataTypes.h"
#include "TeCoverageParams.h"
#include "TeCoverageDecoder.h"
#include "TeCoverageDecoderCacheLRU.h"
#include "TeCoverageDecoderDatabase.h"
#include "TeCoverageInterpolator.h"
#include "TeCoverageInterpolatorNN.h"
#include <vector>
/*!
\class TeCoverage
\brief A generic Coverage class.
\par Coverage is a way of representing geographic information that
emphasizes relationships and the spatial distribution of earth
phenomena, rather than emphasizing features of independent locations.
\par This class represents a generic Coverage, which is a Coverage
with a generic geographic domain, e.g. a set of points or a set
of surfaces. Each element of the domain is associated to a value vector
that represents the different dimensions of the coverage information.
\par Each coverage is connected to a decoder, which provides a common
interface for retrieving coverage data wherever it is stored.
\par The elements of the domain can be traversed and its values can be
consulted using the coverage iterator. Also, the values on arbitrary
locations can be consulted using interpolation methods.
\sa TeCoverageParams TeCoverageDecoder TeCoverageInterpolator
*/
template <class T>
class TeCoverage : public TeGeometry
{
public:
//! Constructor from parameters and interpolator
/*!
Construct a coverage object, but do not initialize the internal
structures. The interpolator provided must be for exclusive use of
this coverage, any external use of the interpolator is discouraged.
\param params information about the coverage
\param interpolator pointer to a coverage iterpolator
*/
TeCoverage(TeCoverageParams& params, TeCoverageInterpolator<T>* interpolator = NULL) :
params_(params),
interpolator_(interpolator),
decoder_(NULL)
{
}
//! Coverage destructor
/*!
Clear internal structures before destroying the coverage object.
*/
virtual ~TeCoverage()
{
clear();
}
//! Initalize the coverage
/*!
Instantiate internal structures, preparing the coverage for actual use.
Must be called before any attempt to read from the coverage.
*/
virtual void init()
{
// Initialize decoder according to persistence type
if (!decoder_)
{
if (params_.getPersistenceType() == TePERSISTENCE_DATABASE)
{
decoder_ = new TeCoverageDecoderDatabase<T>(params_);
decoder_->init();
}
else if (params_.getPersistenceType() == TePERSISTENCE_DATABASE_CACHELRU)
{
decoder_ = new TeCoverageDecoderCacheLRU<T>(params_);
decoder_->init();
}
}
// Initialize interpolator
if (!interpolator_)
{
// If undefined, create default interpolator
interpolator_ = createDefaultInterpolator();
}
interpolator_->setDecoder(decoder_);
// Set box according to params
setBox(params_.getBoundingBox());
}
//! Clear internal structures
/*!
Clear internal structures such as de decoder and the interpolator.
*/
virtual void clear()
{
if (decoder_)
{
delete(decoder_);
decoder_ = NULL;
}
if (interpolator_)
{
delete(interpolator_);
interpolator_ = NULL;
}
}
//! Return the type of the geometry
/*!
\return the type of the geometry
*/
TeGeomRep elemType()
{
return TeCOVERAGE;
}
//! Return the coverage parameters
/*!
\return the coverage parameters
*/
TeCoverageParams& getParameters()
{
return params_;
}
/*!
\class iterator
\brief A generic Coverage iterator.
\par An iterator for a Coverage representation. This iterator
is specific for traversing a set of generic geometries and basically
it encapsulates a generic geometry-value pair iterator.
\par The move-forward operators are used to traverse the coverage data.
At any point of the traversal, dereferencing operators might be used
to access the generic geometry, while the "[]" operator might be
used to access the values in different dimensions of the coverage.
\sa TeCoverage
*/
class iterator
{
/*!
\typedef geom_it
\brief Generic geometry-value pair vector iterator.
*/
typedef typename std::vector<TeGeomValuePair<T> >::iterator geom_it;
public:
//! Constructor from the base iterator
iterator(geom_it it) :
it_(it)
{
}
//! Destructor
virtual ~iterator()
{
}
//! Prefix move-forward operator
iterator operator++()
{
it_++;
return *this;
}
//! Posfix move-forward operator
iterator operator++(int)
{
iterator temp = *this;
++it_;
return temp;
}
//! Operator for retrieving an instance of a generic geometry
/*!
\return an instance of a generic geometry
*/
T operator*()
{
return it_->geom;
}
//! Operator for retrieving a pointer to a generic geometry
/*!
\return a pointer to a generic geometry
*/
T* operator->()
{
return &(it_->geom);
}
//! Operator for getting the value at a dimension of the coverage
/*!
\param dimension the dimension to be retrieved
\return a double value
*/
double operator[](int dimension)
{
return it_->value[dimension];
}
//! Return whether two iterators point to the same element
bool operator==(const iterator& rhs)
{
return it_ == rhs.it_;
}
//! Return whether two iterators point to the different elements
bool operator!=(const iterator& rhs)
{
return it_ != rhs.it_;
}
protected:
geom_it it_; //!< Generic geometry-value pair vector iterator
};
// --------------------- End of class TeCoverage::iterator
//! Return the beginning iterator
/*!
\par Return the beginning iterator for traversing the generic geometries
that form the spatial domain of this coverage.
\par The polygon parameter may be used to define a selection area. If no
polygon is provided, the selection area includes all the domain.
\par The relation parameter may be used to specify the kind of relation
(e.g. intersection, crossing, overlapping) that holds between the
selection area and the geometries to be selected . If no relation
is provided, it defaults to intersection.
\param poly an instance of TePolygon representing a selection area
\param relation a spatial relation
\return the beginning iterator
*/
typename TeCoverage<T>::iterator begin(
TePolygon& poly = TePolygon(),
TeSpatialRelation relation = TeINTERSECTS)
{
std::vector<TeGeomValuePair<T> >& selected = selectGeomValuePairs(poly, relation);
TeCoverage<T>::iterator beginIt = TeCoverage<T>::iterator(selected.begin());
return beginIt;
}
//! Return the ending iterator
/*!
\par Return the beginning iterator for traversing the generic geometries
that form the spatial domain of this coverage.
\par The polygon parameter may be used to define a selection area. If no
polygon is provided, the selection area includes all the domain.
\par The relation parameter may be used to specify the kind of relation
(e.g. intersection, crossing, overlapping) that holds between the
selection area and the geometries to be selected . If no relation
is provided, it defaults to intersection.
\param poly an instance of TePolygon representing a selection area
\param relation a spatial relation
\return the ending iterator
*/
typename TeCoverage<T>::iterator end(
TePolygon& poly = TePolygon(),
TeSpatialRelation relation = TeINTERSECTS)
{
std::vector<TeGeomValuePair<T> >& selected = selectGeomValuePairs(poly, relation);
TeCoverage<T>::iterator endIt = TeCoverage<T>::iterator(selected.end());
return endIt;
}
//! Evaluate the value of this coverage at an arbitrary location.
/*!
Evaluate the value of this coverage at an arbitrary location, using
the auxiliary interpolator object.
\param position the arbitrary location to be evaluated
\param the value vector, to be filled by this method
*/
void evaluate(const TeCoord2D& location, std::vector<double>& value)
{
interpolator_->evaluate(location, value);
}
//! Fill a region of a raster with interpolated coverage data.
/*!
\par Fill the pixels of a squared region of a raster with
coverage data, using an interpolation method.
\param raster the raster to be filled with coverage data
\param rasterBand the raster band to be filled
\param coverageDimension the coverage dimension to be evaluated
\param box defines the raster region to be filled
*/
void evaluate(TeRaster& raster, const int rasterBand, const int coverageDimension, const TeBox& box = TeBox())
{
interpolator_->evaluate(raster, rasterBand, coverageDimension, box);
}
protected:
TeCoverageParams& params_; //!< stores information about this coverage
TeCoverageDecoder<T>* decoder_; //!< provides access to the coverage data
TeCoverageInterpolator<T>* interpolator_; //!< provides interpolation methods
//! Create a default interpolator
/*!
Create a default interpolator. This method is used in case no other
interpolator was provided on construction.
*/
TeCoverageInterpolator<T>* createDefaultInterpolator()
{
// Default Coverage interpolator is nearest neighbour
return new TeCoverageInterpolatorNN<T>();
}
//! Select generic geometry-value pairs from the coverage
/*!
\par Select generic geometry-value pairs from the coverage, using the
decoder to access the coverage data.
\par The polygon parameter defines a selection area and the relation
parameter specifies the kind of relation (e.g. intersection,
crossing, overlapping) that holds between the selection area and
the geometries to be selected.
\param poly an instance of TePolygon representing a selection area
\param relation a spatial relation
*/
std::vector<TeGeomValuePair<T> >& selectGeomValuePairs(const TePolygon& poly, const TeSpatialRelation relation)
{
std::vector<TeGeomValuePair<T> >& selected = lastSelectionResult_;
// Search decoder only if the selection is different from the last one
if ((!TeEquals(lastSelectionPolygon_, poly)) || lastSelectionRelation_ != relation)
{
decoder_->selectGeomValuePairs(poly, relation, selected);
// Save selection parameters and result
lastSelectionPolygon_ = poly;
lastSelectionRelation_ = relation;
lastSelectionResult_ = selected;
}
return selected;
}
private:
TePolygon lastSelectionPolygon_; //!< the last polygon used for a selection
TeSpatialRelation lastSelectionRelation_; //!< the last relation used for a selection
std::vector<TeGeomValuePair<T> > lastSelectionResult_; //!< the last result of a selection
};
#endif // __TERRALIB_INTERNAL_COVERAGE_H
|