1 /****************************************************************************** 2 * $Id: ogrunionlayer.h 842d122d2f23aaebb28362e083b52d6bc7dbcde2 2019-08-11 17:42:34 +0200 Even Rouault $ 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 OGRUnionLayerGeomFieldDefn final: public OGRGeomFieldDefn 42 { 43 public: 44 45 int bGeomTypeSet = false; 46 int bSRSSet = false; 47 OGREnvelope sStaticEnvelope{}; 48 49 OGRUnionLayerGeomFieldDefn(const char* pszName, OGRwkbGeometryType eType); 50 explicit OGRUnionLayerGeomFieldDefn(OGRGeomFieldDefn* poSrc); 51 explicit OGRUnionLayerGeomFieldDefn(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 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 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( const char* pszName, 108 int nSrcLayers, /* must be >= 1 */ 109 OGRLayer** papoSrcLayers, /* array itself ownership always transferred, layer ownership depending on bTakeLayerOwnership */ 110 int bTakeLayerOwnership); 111 112 virtual ~OGRUnionLayer(); 113 114 /* All the following non virtual methods must be called just after the constructor */ 115 /* and before any virtual method */ 116 void SetFields(FieldUnionStrategy eFieldStrategy, 117 int nFields, 118 OGRFieldDefn** papoFields, /* duplicated by the method */ 119 int nGeomFields, /* maybe -1 to explicitly disable geometry fields */ 120 OGRUnionLayerGeomFieldDefn** papoGeomFields /* duplicated by the method */); 121 void SetSourceLayerFieldName(const char* pszSourceLayerFieldName); 122 void SetPreserveSrcFID(int bPreserveSrcFID); 123 void SetFeatureCount(int nFeatureCount); GetName()124 virtual const char *GetName() override { return osName.c_str(); } 125 virtual OGRwkbGeometryType GetGeomType() override; 126 127 virtual void ResetReading() override; 128 virtual OGRFeature *GetNextFeature() override; 129 130 virtual OGRFeature *GetFeature( GIntBig nFeatureId ) override; 131 132 virtual OGRErr ICreateFeature( OGRFeature* poFeature ) override; 133 134 virtual OGRErr ISetFeature( OGRFeature* poFeature ) override; 135 136 virtual OGRFeatureDefn *GetLayerDefn() override; 137 138 virtual OGRSpatialReference *GetSpatialRef() override; 139 140 virtual GIntBig GetFeatureCount( int ) override; 141 142 virtual OGRErr SetAttributeFilter( const char * ) override; 143 144 virtual int TestCapability( const char * ) override; 145 146 virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce = TRUE) override; 147 virtual OGRErr GetExtent( OGREnvelope *psExtent, int bForce ) override; 148 149 virtual void SetSpatialFilter( OGRGeometry * poGeomIn ) override; 150 virtual void SetSpatialFilter( int iGeomField, OGRGeometry * ) override; 151 152 virtual OGRErr SetIgnoredFields( const char **papszFields ) override; 153 154 virtual OGRErr SyncToDisk() override; 155 }; 156 157 #endif /* #ifndef DOXYGEN_SKIP */ 158 159 #endif // OGRUNIONLAYER_H_INCLUDED 160