GDAL
ogrunionlayer.h
1 /******************************************************************************
2  * $Id$
3  *
4  * Project: OpenGIS Simple Features Reference Implementation
5  * Purpose: Defines OGRUnionLayer class
6  * Author: Even Rouault, even dot rouault at spatialys.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2012-2014, Even Rouault <even dot rouault at spatialys.com>
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #ifndef OGRUNIONLAYER_H_INCLUDED
31 #define OGRUNIONLAYER_H_INCLUDED
32 
33 #ifndef DOXYGEN_SKIP
34 
35 #include "ogrsf_frmts.h"
36 
37 /************************************************************************/
38 /* OGRUnionLayerGeomFieldDefn */
39 /************************************************************************/
40 
41 class CPL_DLL OGRUnionLayerGeomFieldDefn final : public OGRGeomFieldDefn
42 {
43  public:
44  int bGeomTypeSet = false;
45  int bSRSSet = false;
46  OGREnvelope sStaticEnvelope{};
47 
48  OGRUnionLayerGeomFieldDefn(const char *pszName, OGRwkbGeometryType eType);
49  explicit OGRUnionLayerGeomFieldDefn(const OGRGeomFieldDefn *poSrc);
50  explicit OGRUnionLayerGeomFieldDefn(
51  const OGRUnionLayerGeomFieldDefn *poSrc);
52  ~OGRUnionLayerGeomFieldDefn();
53 };
54 
55 /************************************************************************/
56 /* OGRUnionLayer */
57 /************************************************************************/
58 
59 typedef enum
60 {
61  FIELD_FROM_FIRST_LAYER,
62  FIELD_UNION_ALL_LAYERS,
63  FIELD_INTERSECTION_ALL_LAYERS,
64  FIELD_SPECIFIED,
65 } FieldUnionStrategy;
66 
67 class CPL_DLL OGRUnionLayer final : public OGRLayer
68 {
69  CPL_DISALLOW_COPY_ASSIGN(OGRUnionLayer)
70 
71  protected:
72  CPLString osName;
73  int nSrcLayers;
74  OGRLayer **papoSrcLayers;
75  int bHasLayerOwnership;
76 
77  OGRFeatureDefn *poFeatureDefn;
78  int nFields;
79  OGRFieldDefn **papoFields;
80  int nGeomFields;
81  OGRUnionLayerGeomFieldDefn **papoGeomFields;
82  FieldUnionStrategy eFieldStrategy;
83  CPLString osSourceLayerFieldName{};
84 
85  int bPreserveSrcFID;
86 
87  GIntBig nFeatureCount;
88 
89  int iCurLayer;
90  char *pszAttributeFilter;
91  int nNextFID;
92  int *panMap;
93  char **papszIgnoredFields;
94  int bAttrFilterPassThroughValue;
95  int *pabModifiedLayers;
96  int *pabCheckIfAutoWrap;
97  const OGRSpatialReference *poGlobalSRS;
98 
99  void AutoWarpLayerIfNecessary(int iSubLayer);
100  OGRFeature *TranslateFromSrcLayer(OGRFeature *poSrcFeature);
101  void ApplyAttributeFilterToSrcLayer(int iSubLayer);
102  int GetAttrFilterPassThroughValue();
103  void ConfigureActiveLayer();
104  void SetSpatialFilterToSourceLayer(OGRLayer *poSrcLayer);
105 
106  public:
107  OGRUnionLayer(
108  const char *pszName, int nSrcLayers, /* must be >= 1 */
109  OGRLayer *
110  *papoSrcLayers, /* array itself ownership always transferred, layer
111  ownership depending on bTakeLayerOwnership */
112  int bTakeLayerOwnership);
113 
114  virtual ~OGRUnionLayer();
115 
116  /* All the following non virtual methods must be called just after the
117  * constructor */
118  /* and before any virtual method */
119  void SetFields(
120  FieldUnionStrategy eFieldStrategy, int nFields,
121  OGRFieldDefn **papoFields, /* duplicated by the method */
122  int nGeomFields, /* maybe -1 to explicitly disable geometry fields */
123  OGRUnionLayerGeomFieldDefn *
124  *papoGeomFields /* duplicated by the method */);
125  void SetSourceLayerFieldName(const char *pszSourceLayerFieldName);
126  void SetPreserveSrcFID(int bPreserveSrcFID);
127  void SetFeatureCount(int nFeatureCount);
128  virtual const char *GetName() override
129  {
130  return osName.c_str();
131  }
132  virtual OGRwkbGeometryType GetGeomType() override;
133 
134  virtual void ResetReading() override;
135  virtual OGRFeature *GetNextFeature() override;
136 
137  virtual OGRFeature *GetFeature(GIntBig nFeatureId) override;
138 
139  virtual OGRErr ICreateFeature(OGRFeature *poFeature) override;
140 
141  virtual OGRErr ISetFeature(OGRFeature *poFeature) override;
142 
143  virtual OGRErr IUpsertFeature(OGRFeature *poFeature) override;
144 
145  OGRErr IUpdateFeature(OGRFeature *poFeature, int nUpdatedFieldsCount,
146  const int *panUpdatedFieldsIdx,
147  int nUpdatedGeomFieldsCount,
148  const int *panUpdatedGeomFieldsIdx,
149  bool bUpdateStyleString) override;
150 
151  virtual OGRFeatureDefn *GetLayerDefn() override;
152 
153  virtual OGRSpatialReference *GetSpatialRef() override;
154 
155  virtual GIntBig GetFeatureCount(int) override;
156 
157  virtual OGRErr SetAttributeFilter(const char *) override;
158 
159  virtual int TestCapability(const char *) override;
160 
161  virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
162  int bForce = TRUE) override;
163  virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce) override;
164 
165  virtual void SetSpatialFilter(OGRGeometry *poGeomIn) override;
166  virtual void SetSpatialFilter(int iGeomField, OGRGeometry *) override;
167 
168  virtual OGRErr SetIgnoredFields(const char **papszFields) override;
169 
170  virtual OGRErr SyncToDisk() override;
171 };
172 
173 #endif /* #ifndef DOXYGEN_SKIP */
174 
175 #endif // OGRUNIONLAYER_H_INCLUDED
OGRLayer::GetName
virtual const char * GetName()
Return the layer name.
Definition: ogrlayer.cpp:1994
OGRLayer::ICreateFeature
virtual OGRErr ICreateFeature(OGRFeature *poFeature)
Create and write a new feature within a layer.
Definition: ogrlayer.cpp:648
OGRLayer::ResetReading
virtual void ResetReading()=0
Reset feature reading to start on the first feature.
OGRLayer::IUpdateFeature
virtual OGRErr IUpdateFeature(OGRFeature *poFeature, int nUpdatedFieldsCount, const int *panUpdatedFieldsIdx, int nUpdatedGeomFieldsCount, const int *panUpdatedGeomFieldsIdx, bool bUpdateStyleString)
Update (part of) an existing feature.
Definition: ogrlayer.cpp:756
OGRLayer::GetSpatialRef
virtual OGRSpatialReference * GetSpatialRef()
Fetch the spatial reference system for this layer.
Definition: ogrlayer.cpp:1224
OGRSpatialReference
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:166
OGRLayer::GetFeatureCount
virtual GIntBig GetFeatureCount(int bForce=TRUE)
Fetch the feature count in this layer.
Definition: ogrlayer.cpp:177
OGRGeometry
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:334
OGRLayer
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:73
CPLString
Convenient string class based on std::string.
Definition: cpl_string.h:311
OGRLayer::GetExtent
virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce=TRUE)
Fetch the extent of this layer.
Definition: ogrlayer.cpp:215
OGRLayer::ISetFeature
virtual OGRErr ISetFeature(OGRFeature *poFeature)
Rewrite/replace an existing feature.
Definition: ogrlayer.cpp:608
OGRLayer::SetSpatialFilter
virtual void SetSpatialFilter(OGRGeometry *)
Set a new spatial filter.
Definition: ogrlayer.cpp:1301
OGRLayer::GetLayerDefn
virtual OGRFeatureDefn * GetLayerDefn()=0
Fetch the schema information for this layer.
OGRLayer::IUpsertFeature
virtual OGRErr IUpsertFeature(OGRFeature *poFeature)
Rewrite/replace an existing feature or create a new feature within a layer.
Definition: ogrlayer.cpp:688
ogrsf_frmts.h
OGRFieldDefn
Definition of an attribute of an OGRFeatureDefn.
Definition: ogr_feature.h:103
OGRGeomFieldDefn
Definition of a geometry field of an OGRFeatureDefn.
Definition: ogr_feature.h:286
OGRErr
int OGRErr
Type for a OGR error.
Definition: ogr_core.h:378
GIntBig
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:226
OGRwkbGeometryType
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:406
OGRFeature
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:680
OGRLayer::SetIgnoredFields
virtual OGRErr SetIgnoredFields(const char **papszFields)
Set which fields can be omitted when retrieving features from the layer.
Definition: ogrlayer.cpp:2058
OGREnvelope
Simple container for a bounding region (rectangle)
Definition: ogr_core.h:57
OGRFeatureDefn
Definition of a feature class or feature layer.
Definition: ogr_feature.h:385
OGRLayer::GetGeomType
virtual OGRwkbGeometryType GetGeomType()
Return the layer geometry type.
Definition: ogrlayer.cpp:2021
OGRLayer::SetAttributeFilter
virtual OGRErr SetAttributeFilter(const char *)
Set a new attribute query.
Definition: ogrlayer.cpp:344
OGRLayer::TestCapability
virtual int TestCapability(const char *)=0
Test if this layer supported the named capability.
OGRLayer::GetNextFeature
virtual OGRFeature * GetNextFeature()=0
Fetch the next available feature from this layer.
OGRLayer::SyncToDisk
virtual OGRErr SyncToDisk()
Flush pending changes to disk.
Definition: ogrlayer.cpp:1788
OGRLayer::GetFeature
virtual OGRFeature * GetFeature(GIntBig nFID)
Fetch a feature by its identifier.
Definition: ogrlayer.cpp:451
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:1042