This file is indexed.

/usr/include/terralib/kernel/TeCoverageDecoderDatabase.h is in libterralib-dev 4.3.0+dfsg.2-11.

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
379
380
381
382
383
384
385
386
387
388
389
390
391
/************************************************************************************
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 TeCoverageDecoderDatabase.h

  \par This file contains definitions and algorithms for accessing a
       generic Coverage from a TerraLib database.
*/
#ifndef  __TERRALIB_INTERNAL_COVERAGEDECODERDATABASE_H
#define  __TERRALIB_INTERNAL_COVERAGEDECODERDATABASE_H

#include "TeCoverageDecoder.h"

/*!
  \class TeCoverageDecoderDatabase
  \brief Class to decode a generic Coverage from a TerraLib database.
*/
template <class T>
class TeCoverageDecoderDatabase : public TeCoverageDecoder<T>
{
public:

    //! Constructor from parameters
    TeCoverageDecoderDatabase(TeCoverageParams& params) :
        TeCoverageDecoder<T>(params)
    {
    }

    //! Initialize internal structures
    /*!
      Instantiate internal structures, must be called before any
      attempt to access the coverage data.
    */
    virtual void init()
    {
        TeLayer* layer = TeRetrieveLayer(params_.getDatabase(), params_.getLayerId());

        // Check if the coverage ID is specified
        if (params_.getCoverageId().empty())
        {
            // Otherwise, get the first coverage (if any)
            std::vector<std::string> coverageIds;
            TeRetrieveCoverageIds(layer, coverageIds);
            if (coverageIds.empty())
            {
                std::string errorMsg = "No coverage defined on layer " + Te2String(layer->id()) + ".";
                throw TeException(UNKNOWN_ERROR_TYPE, errorMsg, false);
            }
            // New coverage ID is the first coverage found on layer
            params_.setCoverageId(coverageIds.at(0));
        }

        // Set coverage table name
        params_.setCoverageTable(TeRetrieveCoverageTable(layer, params_.getCoverageId()));

        // Retrieve coverage dimensions information from the database
        std::vector<TeCoverageDimension> dimensions;
        TeRetrieveDimensions(layer, params_.getCoverageId(), dimensions);
        params_.setDimensions(dimensions);

        // Set coverage projection
        params_.setProjection(layer->projection());

        // Set coverage bounding box
        params_.setBoundingBox(TeRetrieveCoverageBox(layer, params_.getCoverageId()));

        // Set number of elements of the coverage
        params_.setNumElements(TeRetrieveCoverageNumElements(layer, params_.getCoverageId()));
    }

    //! Select generic coverage blocks from the database.
    /*!
      \par Select generic coverage blocks from a TerraLib database. Uses
           a TeBlockLoader object for retrieving blocks from the database.
      \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
           at least one geometry in each block to be selected.
      \param poly an instance of TePolygon representing a selection area
      \param relation a spatial relation
      \param dontSelect list IDs of blocks that must not be retrieved
      \sa TeCoverageBlock TeSpatialRelation TeBlockLoader
    */
    void selectBlocks(const TePolygon& poly, const TeSpatialRelation relation, std::vector<TeCoverageBlock<T> >& selected, std::set<int>& dontSelect)
    {
        selected.clear();

        TeBox queryBox = poly.box();

        // Set block loader parameters.
        TeBlockLoaderParams loaderParams;
        loaderParams.db = params_.getDatabase();
        loaderParams.table_name = params_.getCoverageTable();
        loaderParams.selection_box = queryBox;
        loaderParams.load_all_attrs = true;
        loaderParams.dont_load_ids = dontSelect;

        // Construct loader and load blocks.
        TeBlockLoader loader(loaderParams);
        loader.loadBlocks();

        // Iterate over blocks loaded
        while (loader.fetchNext()) {

            TeBox blockBox(loader.getDouble("lower_x"),
                        loader.getDouble("lower_y"),
                        loader.getDouble("upper_x"),
                        loader.getDouble("upper_y"));

            TePolygon& blockPoly = polygonFromBox(blockBox);

            // If the spatial relation doesn't hold, proceed to the next block
            if (!TeTopologicalRelation(&blockPoly, &poly, relation))
            {
                continue;
            }

            // Extract block contents.
            long blockSize = 0;
            unsigned char* data = NULL;
            loader.getSpatialData(data, blockSize);
            
            // Decode block contents.
            TeCoverageBlock<T>& block = decodeCoverageBlock(data, blockSize, params_.getDimensions());

            // Set other block attributes
            block.id = loader.getID();
            block.box = blockBox;

            // Add block to result
            selected.push_back(block);
        }
    }

protected:

    //! Decode a generic geometry-value pair
    /*!
      \par Decode a generic geometry-value pair from a block of raw data.
           As a side effect, the pointer to the data is moved forward to the
           end of the decoded chunk.
        \param data pointer to the memory location where the raw data starts
        \param dimensions information about the coverage dimensions
        \return a generic geometry-value pair
    */
    TeGeomValuePair<T> decodeGeomValuePair(unsigned char*& data, std::vector<TeCoverageDimension>& dimensions);

    //! Decode a generic coverage block
    /*!
        \par Decode coverage block contents that are stored in the database
             as raw binary data. As a side effect, the pointer to the data
             is moved forward to the end of the decoded chunk.
        \param data pointer to the memory location where the raw data starts
        \param dataSize size of the raw data block to be decoded
        \param dimensions information about the coverage dimensions
        \return a generic coverage block
    */
    TeCoverageBlock<T> decodeCoverageBlock(unsigned char*& data, const long dataSize, std::vector<TeCoverageDimension>& dimensions)
    {
        TeCoverageBlock<T> block;

        unsigned char* dataEnd = data + dataSize;

        // Decode geom-value pairs from chunks of the block
        unsigned int count = 0;
        while (data < dataEnd)
        {
            TeGeomValuePair<T>& gvPair = decodeGeomValuePair(data, dimensions);
            gvPair.geom.objectId(Te2String(count++));

            block.pairs.push_back(gvPair); // Insert geom-value pair in block
        }
        return block;
    }
};

//! Specialization for decoding a TePoint instead of a generic geometry
TeGeomValuePair<TePoint>
TeCoverageDecoderDatabase<TePoint>::decodeGeomValuePair(unsigned char*& data, std::vector<TeCoverageDimension>& dimensions)
{
    TeGeomValuePair<TePoint> gvPair = TeGeomValuePair<TePoint>();

    // Set coordinates
    double x = READ(data, double);
    double y = READ(data, double);

    gvPair.geom = TePoint(x, y);
    
    // Set values
    gvPair.value = std::vector<double>();
    std::vector<TeCoverageDimension>::iterator it = dimensions.begin();
    std::vector<TeCoverageDimension>::iterator end = dimensions.end();
    while (it != end)
    {
        double val = 0;

        switch (it->type)
        {
        case (TeUNSIGNEDSHORT):
            val = READ(data, unsigned short);
            break;
        case (TeSHORT):
            val = READ(data, short);
            break;
        case (TeINTEGER):
            val = READ(data, int);
            break;                
        case (TeUNSIGNEDLONG):
            val = READ(data, unsigned long);
            break;
        case (TeLONG):
            val = READ(data, long);
            break;
        case (TeFLOAT):
            val = READ(data, float);
            break;
        case (TeDOUBLE):
            val = READ(data, double);
            break;
        default:
            // Exception (invalid type)
            break;
        }

        gvPair.value.push_back(val);
        it++;
    }

    return gvPair;
}

//! Specialization for decoding a TeLine2D instead of a generic geometry
TeGeomValuePair<TeLine2D>
TeCoverageDecoderDatabase<TeLine2D>::decodeGeomValuePair(unsigned char*& data, std::vector<TeCoverageDimension>& dimensions)
{
    TeGeomValuePair<TeLine2D> gvPair = TeGeomValuePair<TeLine2D>();

    TeLine2D line = TeLine2D();

    // Check number of points in the line
    unsigned int numPoints = READ(data, unsigned int);

    // Decode points and add to the line
    for (unsigned int i = 0; i < numPoints; ++i)
    {
        double x = READ(data, double);
        double y = READ(data, double);

        line.add(TeCoord2D(x, y));
    }

    gvPair.geom = line;
    
    // Set values
    gvPair.value = std::vector<double>();
    std::vector<TeCoverageDimension>::iterator it = dimensions.begin();
    std::vector<TeCoverageDimension>::iterator end = dimensions.end();
    while (it != end)
    {
        double val = 0;

        switch (it->type)
        {
        case (TeUNSIGNEDSHORT):
            val = READ(data, unsigned short);
            break;
        case (TeSHORT):
            val = READ(data, short);
            break;
        case (TeINTEGER):
            val = READ(data, int);
            break;                
        case (TeUNSIGNEDLONG):
            val = READ(data, unsigned long);
            break;
        case (TeLONG):
            val = READ(data, long);
            break;
        case (TeFLOAT):
            val = READ(data, float);
            break;
        case (TeDOUBLE):
            val = READ(data, double);
            break;
        default:
            // Exception (invalid type)
            break;
        }

        gvPair.value.push_back(val);
        it++;
    }

    return gvPair;
}

//! Specialization for decoding a TePolygon instead of a generic geometry
TeGeomValuePair<TePolygon>
TeCoverageDecoderDatabase<TePolygon>::decodeGeomValuePair(unsigned char*& data, std::vector<TeCoverageDimension>& dimensions)
{
    TeGeomValuePair<TePolygon> gvPair = TeGeomValuePair<TePolygon>();

    TePolygon poly = TePolygon();
    // Check number of linear rings in the polygon
    unsigned int numLines = READ(data, unsigned int);

    for (unsigned int i = 0; i < numLines; ++i)
    {
        TeLine2D line = TeLine2D();

        // Check number of points in the line
        unsigned int numPoints = READ(data, unsigned int);

        // Decode points and add to the line
        for (unsigned int i = 0; i < numPoints; ++i)
        {
            double x = READ(data, double);
            double y = READ(data, double);

            line.add(TeCoord2D(x, y));
        }

        TeLinearRing ring = TeLinearRing(line);
        poly.add(ring);
    }
    gvPair.geom = poly;
    
    // Set values
    gvPair.value = std::vector<double>();
    std::vector<TeCoverageDimension>::iterator it = dimensions.begin();
    std::vector<TeCoverageDimension>::iterator end = dimensions.end();
    while (it != end)
    {
        double val = 0;

        switch (it->type)
        {
        case (TeUNSIGNEDSHORT):
            val = READ(data, unsigned short);
            break;
        case (TeSHORT):
            val = READ(data, short);
            break;
        case (TeINTEGER):
            val = READ(data, int);
            break;                
        case (TeUNSIGNEDLONG):
            val = READ(data, unsigned long);
            break;
        case (TeLONG):
            val = READ(data, long);
            break;
        case (TeFLOAT):
            val = READ(data, float);
            break;
        case (TeDOUBLE):
            val = READ(data, double);
            break;
        default:
            // Exception (invalid type)
            break;
        }

        gvPair.value.push_back(val);
        it++;
    }

    return gvPair;
}

#endif // __TERRALIB_INTERNAL_COVERAGEDECODERDATABASE_H