GDAL

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

ogr_gensql.h
1 /******************************************************************************
2 * $Id: ogr_gensql.h 33714 2016-03-13 05:42:13Z goatbar $
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
38 #define GEOM_FIELD_INDEX_TO_ALL_FIELD_INDEX(poFDefn, iGeom) \
39 ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (iGeom))
40
41 #define IS_GEOM_FIELD_INDEX(poFDefn, idx) \
42 (((idx) >= (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT) && \
43 ((idx) < (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (poFDefn)->GetGeomFieldCount()))
44
45 #define ALL_FIELD_INDEX_TO_GEOM_FIELD_INDEX(poFDefn, idx) \
46 ((idx) - ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT))
47
48 /************************************************************************/
49 /* OGRGenSQLResultsLayer */
50 /************************************************************************/
51
52 class CPL_DLL OGRGenSQLResultsLayer : public OGRLayer
53 {
54 private:
55 GDALDataset *poSrcDS;
56 OGRLayer *poSrcLayer;
57 void *pSelectInfo;
58
59 char *pszWHERE;
60
61 OGRLayer **papoTableLayers;
62
63 OGRFeatureDefn *poDefn;
64
65 int *panGeomFieldToSrcGeomField;
66
67 GIntBig nIndexSize;
68 GIntBig *panFIDIndex;
69 int bOrderByValid;
70
71 GIntBig nNextIndexFID;
72 OGRFeature *poSummaryFeature;
73
74 int iFIDFieldIndex;
75
76 int nExtraDSCount;
77 GDALDataset **papoExtraDS;
78
79 int PrepareSummary();
80
81 OGRFeature *TranslateFeature( OGRFeature * );
82 void CreateOrderByIndex();
83 int SortIndexSection( OGRField *pasIndexFields,
84 GIntBig nStart, GIntBig nEntries );
85 int Compare( OGRField *pasFirst, OGRField *pasSecond );
86
87 void ClearFilters();
88 void ApplyFiltersToSource();
89
90 void FindAndSetIgnoredFields();
91 void ExploreExprForIgnoredFields(swq_expr_node* expr, CPLHashSet* hSet);
92 void AddFieldDefnToSet(int iTable, int iColumn, CPLHashSet* hSet);
93
94 int ContainGeomSpecialField(swq_expr_node* expr);
95
96 void InvalidateOrderByIndex();
97
98 int MustEvaluateSpatialFilterOnGenSQL();
99
100 public:
101 OGRGenSQLResultsLayer( GDALDataset *poSrcDS,
102 void *pSelectInfo,
103 OGRGeometry *poSpatFilter,
104 const char *pszWHERE,
105 const char *pszDialect );
106 virtual ~OGRGenSQLResultsLayer();
107
108 virtual OGRGeometry *GetSpatialFilter();
109
110 virtual void ResetReading();
111 virtual OGRFeature *GetNextFeature();
112 virtual OGRErr SetNextByIndex( GIntBig nIndex );
113 virtual OGRFeature *GetFeature( GIntBig nFID );
114
115 virtual OGRFeatureDefn *GetLayerDefn();
116
117 virtual GIntBig GetFeatureCount( int bForce = TRUE );
118 virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) { return GetExtent(0, psExtent, bForce); }
119 virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce = TRUE);
120
121 virtual int TestCapability( const char * );
122
123 virtual void SetSpatialFilter( OGRGeometry * poGeom ) { SetSpatialFilter(0, poGeom); }
124 virtual void SetSpatialFilter( int iGeomField, OGRGeometry * );
125 virtual OGRErr SetAttributeFilter( const char * );
126 };
127
128 #endif /* ndef OGR_GENSQL_H_INCLUDED */
OGRLayer::GetLayerDefn
virtual OGRFeatureDefn * GetLayerDefn()=0
Fetch the schema information for this layer.
OGRLayer::SetAttributeFilter
virtual OGRErr SetAttributeFilter(const char *)
Set a new attribute query.
Definition: ogrlayer.cpp:340
OGRLayer::SetSpatialFilter
virtual void SetSpatialFilter(OGRGeometry *)
Set a new spatial filter.
Definition: ogrlayer.cpp:1106
OGRLayer::SetNextByIndex
virtual OGRErr SetNextByIndex(GIntBig nIndex)
Move read cursor to the nIndex'th feature in the current resultset.
Definition: ogrlayer.cpp:498
OGRLayer::GetSpatialFilter
virtual OGRGeometry * GetSpatialFilter()
This method returns the current spatial filter for this layer.
Definition: ogrlayer.cpp:1079
cpl_hash_set.h
Hash set implementation.
OGRFeatureDefn
Definition of a feature class or feature layer.
Definition: ogr_feature.h:206
OGRLayer::GetFeature
virtual OGRFeature * GetFeature(GIntBig nFID) CPL_WARN_UNUSED_RESULT
Fetch a feature by its identifier.
Definition: ogrlayer.cpp:446
OGRLayer::GetFeatureCount
virtual GIntBig GetFeatureCount(int bForce=TRUE)
Fetch the feature count in this layer.
Definition: ogrlayer.cpp:171
OGRGeometry
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:104
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.
OGRLayer::ResetReading
virtual void ResetReading()=0
Reset feature reading to start on the first feature.
OGREnvelope
Simple container for a bounding region.
Definition: ogr_core.h:48
OGRField
OGRFeature field attribute value union.
Definition: ogr_core.h:662
OGRGenSQLResultsLayer::GetExtent
virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce=TRUE)
Fetch the extent of this layer.
Definition: ogr_gensql.h:118
OGRLayer
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:66
OGRLayer::GetExtent
virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce=TRUE) CPL_WARN_UNUSED_RESULT
Fetch the extent of this layer.
Definition: ogrlayer.cpp:212
OGRFeature
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:274
OGRLayer::GetNextFeature
virtual OGRFeature * GetNextFeature() CPL_WARN_UNUSED_RESULT=0
Fetch the next available feature from this layer.
GDALDataset
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:296
OGRGenSQLResultsLayer::SetSpatialFilter
virtual void SetSpatialFilter(OGRGeometry *poGeom)
Set a new spatial filter.
Definition: ogr_gensql.h:123
OGRGenSQLResultsLayer
Definition: ogr_gensql.h:52
swq_expr_node
Definition: swq.h:102

Generated for GDAL by 1.8.8.