GDAL

- Main Page
- Related Pages
- Classes
- Files
- Download
- Issue Tracker

- File List
- File Members

ogr_gensql.h
1 /******************************************************************************
2 * $Id$
3 *
4 * Project: OpenGIS Simple Features Reference Implementation
5 * Purpose: Classes related to generic implementation of ExecuteSQL().
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 2002, Frank Warmerdam
10 * Copyright (c) 2010-2013, Even Rouault <even dot rouault at mines-paris dot org>
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 ****************************************************************************/
30
31 #ifndef OGR_GENSQL_H_INCLUDED
32 #define OGR_GENSQL_H_INCLUDED
33
34 #include "ogrsf_frmts.h"
35 #include "swq.h"
36 #include "cpl_hash_set.h"
37 #include "cpl_string.h"
38
39 #include <vector>
40
43 #define GEOM_FIELD_INDEX_TO_ALL_FIELD_INDEX(poFDefn, iGeom) \
44 ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (iGeom))
45
46 #define IS_GEOM_FIELD_INDEX(poFDefn, idx) \
47 (((idx) >= (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT) && \
48 ((idx) < (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (poFDefn)->GetGeomFieldCount()))
49
50 #define ALL_FIELD_INDEX_TO_GEOM_FIELD_INDEX(poFDefn, idx) \
51 ((idx) - ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT))
52
53 /************************************************************************/
54 /* OGRGenSQLResultsLayer */
55 /************************************************************************/
56
57 class OGRGenSQLResultsLayer final: public OGRLayer
58 {
59 private:
60 GDALDataset *poSrcDS;
61 OGRLayer *poSrcLayer;
62 void *pSelectInfo;
63
64 char *pszWHERE;
65
66 OGRLayer **papoTableLayers;
67
68 OGRFeatureDefn *poDefn;
69
70 int *panGeomFieldToSrcGeomField;
71
72 size_t nIndexSize;
73 GIntBig *panFIDIndex;
74 int bOrderByValid;
75
76 GIntBig nNextIndexFID;
77 OGRFeature *poSummaryFeature;
78
79 int iFIDFieldIndex;
80
81 int nExtraDSCount;
82 GDALDataset **papoExtraDS;
83
84 GIntBig nIteratedFeatures;
85 std::vector<CPLString> m_oDistinctList;
86
87 int PrepareSummary();
88
89 OGRFeature *TranslateFeature( OGRFeature * );
90 void CreateOrderByIndex();
91 void ReadIndexFields( OGRFeature* poSrcFeat,
92 int nOrderItems,
93 OGRField *pasIndexFields );
94 void SortIndexSection( const OGRField *pasIndexFields,
95 GIntBig *panMerged,
96 size_t nStart, size_t nEntries );
97 void FreeIndexFields(OGRField *pasIndexFields,
98 size_t l_nIndexSize,
99 bool bFreeArray = true);
100 int Compare( const OGRField *pasFirst, const OGRField *pasSecond );
101
102 void ClearFilters();
103 void ApplyFiltersToSource();
104
105 void FindAndSetIgnoredFields();
106 void ExploreExprForIgnoredFields(swq_expr_node* expr, CPLHashSet* hSet);
107 void AddFieldDefnToSet(int iTable, int iColumn, CPLHashSet* hSet);
108
109 int ContainGeomSpecialField(swq_expr_node* expr);
110
111 void InvalidateOrderByIndex();
112
113 int MustEvaluateSpatialFilterOnGenSQL();
114
115 CPL_DISALLOW_COPY_ASSIGN(OGRGenSQLResultsLayer)
116
117 public:
118 OGRGenSQLResultsLayer( GDALDataset *poSrcDS,
119 void *pSelectInfo,
120 OGRGeometry *poSpatFilter,
121 const char *pszWHERE,
122 const char *pszDialect );
123 virtual ~OGRGenSQLResultsLayer();
124
125 virtual OGRGeometry *GetSpatialFilter() override;
126
127 virtual void ResetReading() override;
128 virtual OGRFeature *GetNextFeature() override;
129 virtual OGRErr SetNextByIndex( GIntBig nIndex ) override;
130 virtual OGRFeature *GetFeature( GIntBig nFID ) override;
131
132 virtual OGRFeatureDefn *GetLayerDefn() override;
133
134 virtual GIntBig GetFeatureCount( int bForce = TRUE ) override;
135 virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override { return GetExtent(0, psExtent, bForce); }
136 virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce = TRUE) override;
137
138 virtual int TestCapability( const char * ) override;
139
140 virtual void SetSpatialFilter( OGRGeometry * poGeom ) override { SetSpatialFilter(0, poGeom); }
141 virtual void SetSpatialFilter( int iGeomField, OGRGeometry * ) override;
142 virtual OGRErr SetAttributeFilter( const char * ) override;
143 };
144
147 #endif /* ndef OGR_GENSQL_H_INCLUDED */
OGRLayer::SetAttributeFilter
virtual OGRErr SetAttributeFilter(const char *)
Set a new attribute query.
Definition: ogrlayer.cpp:338
OGRLayer::SetSpatialFilter
virtual void SetSpatialFilter(OGRGeometry *)
Set a new spatial filter.
Definition: ogrlayer.cpp:1113
cpl_hash_set.h
Hash set implementation.
OGRFeatureDefn
Definition of a feature class or feature layer.
Definition: ogr_feature.h:259
cpl_string.h
Various convenience functions for working with strings and string lists.
OGRGeometry
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:286
ogrsf_frmts.h
Classes related to registration of format support, and opening datasets.
OGRLayer::TestCapability
virtual int TestCapability(const char *)=0
Test if this layer supported the named capability.
OGRField
OGRFeature field attribute value union.
Definition: ogr_core.h:683
OGRLayer
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:70
OGRLayer::GetExtent
virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce=TRUE) CPL_WARN_UNUSED_RESULT
Fetch the extent of this layer.
Definition: ogrlayer.cpp:211
OGRFeature
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:354
GDALDataset
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:335
GIntBig
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:248
OGRErr
int OGRErr
Simple container for a bounding region.
Definition: ogr_core.h:290
CPLHashSet
struct _CPLHashSet CPLHashSet
Opaque type for a hash set.
Definition: cpl_hash_set.h:52
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:989

Generated for GDAL by 1.8.8.