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 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14#ifndef OGRUNIONLAYER_H_INCLUDED
15#define OGRUNIONLAYER_H_INCLUDED
16
17#ifndef DOXYGEN_SKIP
18
19#include "ogrsf_frmts.h"
20
21/************************************************************************/
22/* OGRUnionLayerGeomFieldDefn */
23/************************************************************************/
24
25 class CPL_DLL OGRUnionLayerGeomFieldDefn final : public OGRGeomFieldDefn
26{
27 public:
28 int bGeomTypeSet = false;
29 int bSRSSet = false;
30 OGREnvelope sStaticEnvelope{};
31
32 OGRUnionLayerGeomFieldDefn(const char *pszName, OGRwkbGeometryType eType);
33 explicit OGRUnionLayerGeomFieldDefn(const OGRGeomFieldDefn *poSrc);
34 explicit OGRUnionLayerGeomFieldDefn(
35 const OGRUnionLayerGeomFieldDefn *poSrc);
36 ~OGRUnionLayerGeomFieldDefn();
37};
38
39/************************************************************************/
40/* OGRUnionLayer */
41/************************************************************************/
42
43 typedef enum
44{
45 FIELD_FROM_FIRST_LAYER,
46 FIELD_UNION_ALL_LAYERS,
47 FIELD_INTERSECTION_ALL_LAYERS,
48 FIELD_SPECIFIED,
49} FieldUnionStrategy;
50
51 class CPL_DLL OGRUnionLayer final : public OGRLayer
52{
53 CPL_DISALLOW_COPY_ASSIGN(OGRUnionLayer)
54
55 protected:
56 CPLString osName{};
57 int nSrcLayers = 0;
58 OGRLayer **papoSrcLayers = nullptr;
59 int bHasLayerOwnership = false;
60
61 OGRFeatureDefn *poFeatureDefn = nullptr;
62 int nFields = 0;
63 OGRFieldDefn **papoFields = nullptr;
64 int nGeomFields = 0;
65 OGRUnionLayerGeomFieldDefn **papoGeomFields = nullptr;
66 FieldUnionStrategy eFieldStrategy = FIELD_UNION_ALL_LAYERS;
67 CPLString osSourceLayerFieldName{};
68
69 int bPreserveSrcFID = false;
70
71 GIntBig nFeatureCount = -1;
72
73 int iCurLayer = -1;
74 char *pszAttributeFilter = nullptr;
75 int nNextFID = 0;
76 int *panMap = nullptr;
77 CPLStringList m_aosIgnoredFields{};
78 int bAttrFilterPassThroughValue = -1;
79 int *pabModifiedLayers = nullptr;
80 int *pabCheckIfAutoWrap = nullptr;
81 const OGRSpatialReference *poGlobalSRS = nullptr;
82
83 void AutoWarpLayerIfNecessary(int iSubLayer);
84 OGRFeature *TranslateFromSrcLayer(OGRFeature *poSrcFeature);
85 void ApplyAttributeFilterToSrcLayer(int iSubLayer);
86 int GetAttrFilterPassThroughValue();
87 void ConfigureActiveLayer();
88 void SetSpatialFilterToSourceLayer(OGRLayer *poSrcLayer);
89
90 public:
91 OGRUnionLayer(
92 const char *pszName, int nSrcLayers, /* must be >= 1 */
93 OGRLayer *
94 *papoSrcLayers, /* array itself ownership always transferred, layer
95 ownership depending on bTakeLayerOwnership */
96 int bTakeLayerOwnership);
97
98 virtual ~OGRUnionLayer();
99
100 /* All the following non virtual methods must be called just after the
101 * constructor */
102 /* and before any virtual method */
103 void SetFields(
104 FieldUnionStrategy eFieldStrategy, int nFields,
105 OGRFieldDefn **papoFields, /* duplicated by the method */
106 int nGeomFields, /* maybe -1 to explicitly disable geometry fields */
107 OGRUnionLayerGeomFieldDefn *
108 *papoGeomFields /* duplicated by the method */);
109 void SetSourceLayerFieldName(const char *pszSourceLayerFieldName);
110 void SetPreserveSrcFID(int bPreserveSrcFID);
111 void SetFeatureCount(int nFeatureCount);
112
113 virtual const char *GetName() override
114 {
115 return osName.c_str();
116 }
117
118 virtual OGRwkbGeometryType GetGeomType() override;
119
120 virtual void ResetReading() override;
121 virtual OGRFeature *GetNextFeature() override;
122
123 virtual OGRFeature *GetFeature(GIntBig nFeatureId) override;
124
125 virtual OGRErr ICreateFeature(OGRFeature *poFeature) override;
126
127 virtual OGRErr ISetFeature(OGRFeature *poFeature) override;
128
129 virtual OGRErr IUpsertFeature(OGRFeature *poFeature) override;
130
131 OGRErr IUpdateFeature(OGRFeature *poFeature, int nUpdatedFieldsCount,
132 const int *panUpdatedFieldsIdx,
133 int nUpdatedGeomFieldsCount,
134 const int *panUpdatedGeomFieldsIdx,
135 bool bUpdateStyleString) override;
136
137 virtual OGRFeatureDefn *GetLayerDefn() override;
138
139 virtual OGRSpatialReference *GetSpatialRef() override;
140
141 virtual GIntBig GetFeatureCount(int) override;
142
143 virtual OGRErr SetAttributeFilter(const char *) override;
144
145 virtual int TestCapability(const char *) override;
146
147 virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
148 int bForce = TRUE) override;
149 virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce) override;
150
151 virtual void SetSpatialFilter(OGRGeometry *poGeomIn) override;
152 virtual void SetSpatialFilter(int iGeomField, OGRGeometry *) override;
153
154 virtual OGRErr SetIgnoredFields(CSLConstList papszFields) override;
155
156 virtual OGRErr SyncToDisk() override;
157};
158
159#endif /* #ifndef DOXYGEN_SKIP */
160
161#endif // OGRUNIONLAYER_H_INCLUDED
CPLStringList
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:436
CPLString
Convenient string class based on std::string.
Definition cpl_string.h:307
OGREnvelope
Simple container for a bounding region (rectangle)
Definition ogr_core.h:45
OGRFeatureDefn
Definition of a feature class or feature layer.
Definition ogr_feature.h:501
OGRFeature
A simple feature, including geometry and attributes.
Definition ogr_feature.h:877
OGRFieldDefn
Definition of an attribute of an OGRFeatureDefn.
Definition ogr_feature.h:95
OGRGeomFieldDefn
Definition of a geometry field of an OGRFeatureDefn.
Definition ogr_feature.h:330
OGRGeomFieldDefn::GetSpatialRef
virtual const OGRSpatialReference * GetSpatialRef() const
Fetch spatial reference system of this field.
Definition ogrgeomfielddefn.cpp:463
OGRGeometry
Abstract base class for all geometry classes.
Definition ogr_geometry.h:361
OGRLayer
This class represents a layer of simple features, with access methods.
Definition ogrsf_frmts.h:58
OGRSpatialReference
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:153
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:1030
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1179
GIntBig
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:199
OGRwkbGeometryType
OGRwkbGeometryType
List of well known binary geometry types.
Definition ogr_core.h:407
OGRErr
int OGRErr
Type for a OGR error.
Definition ogr_core.h:371
ogrsf_frmts.h
Classes related to registration of format support, and opening datasets.