Line data Source code
1 : /****************************************************************************** 2 : * $Id$ 3 : * 4 : * Project: Interlis 1 Translator 5 : * Purpose: Definition of classes for OGR Interlis 1 driver. 6 : * Author: Pirmin Kalberer, Sourcepole AG 7 : * 8 : ****************************************************************************** 9 : * Copyright (c) 2004, Pirmin Kalberer, Sourcepole AG 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 OGR_ILI1_H_INCLUDED 31 : #define OGR_ILI1_H_INCLUDED 32 : 33 : #include "ogrsf_frmts.h" 34 : #include "ili1reader.h" 35 : 36 : class OGRILI1DataSource; 37 : 38 : /************************************************************************/ 39 : /* OGRILI1Layer */ 40 : /************************************************************************/ 41 : 42 : class OGRILI1Layer final : public OGRLayer 43 : { 44 : private: 45 : #if 0 46 : OGRSpatialReference *poSRS; 47 : #endif 48 : OGRFeatureDefn *poFeatureDefn; 49 : GeomFieldInfos oGeomFieldInfos; 50 : 51 : int nFeatures; 52 : OGRFeature **papoFeatures; 53 : int nFeatureIdx; 54 : 55 : bool bGeomsJoined; 56 : 57 : OGRILI1DataSource *poDS; 58 : 59 : public: 60 : OGRILI1Layer(OGRFeatureDefn *poFeatureDefn, 61 : const GeomFieldInfos &oGeomFieldInfos, 62 : OGRILI1DataSource *poDS); 63 : 64 : ~OGRILI1Layer(); 65 : 66 : OGRErr AddFeature(OGRFeature *poFeature); 67 : 68 : void ResetReading() override; 69 : OGRFeature *GetNextFeature() override; 70 : OGRFeature *GetNextFeatureRef(); 71 : OGRFeature *GetFeatureRef(GIntBig nFid); 72 : OGRFeature *GetFeatureRef(const char *); 73 : 74 : GIntBig GetFeatureCount(int bForce = TRUE) override; 75 : 76 : OGRErr ICreateFeature(OGRFeature *poFeature) override; 77 : int GeometryAppend(OGRGeometry *poGeometry); 78 : 79 1208 : OGRFeatureDefn *GetLayerDefn() override 80 : { 81 1208 : return poFeatureDefn; 82 : } 83 : 84 : GeomFieldInfos GetGeomFieldInfos() 85 : { 86 : return oGeomFieldInfos; 87 : } 88 : 89 : OGRErr CreateField(const OGRFieldDefn *poField, 90 : int bApproxOK = TRUE) override; 91 : 92 : int TestCapability(const char *) override; 93 : 94 : GDALDataset *GetDataset() override; 95 : 96 : private: 97 : void JoinGeomLayers(); 98 : void JoinSurfaceLayer(OGRILI1Layer *poSurfaceLineLayer, 99 : int nSurfaceFieldIndex); 100 : OGRMultiPolygon *Polygonize(OGRGeometryCollection *poLines, 101 : bool fix_crossing_lines = false); 102 : void PolygonizeAreaLayer(OGRILI1Layer *poAreaLineLayer, int nAreaFieldIndex, 103 : int nPointFieldIndex); 104 : }; 105 : 106 : /************************************************************************/ 107 : /* OGRILI1DataSource */ 108 : /************************************************************************/ 109 : 110 : class OGRILI1DataSource final : public OGRDataSource 111 : { 112 : private: 113 : char *pszName; 114 : ImdReader *poImdReader; 115 : IILI1Reader *poReader; 116 : VSILFILE *fpTransfer; 117 : char *pszTopic; 118 : int nLayers; 119 : OGRILI1Layer **papoLayers; 120 : 121 : CPL_DISALLOW_COPY_ASSIGN(OGRILI1DataSource) 122 : 123 : public: 124 : OGRILI1DataSource(); 125 : virtual ~OGRILI1DataSource(); 126 : 127 : int Open(const char *, char **papszOpenOptions, int bTestOpen); 128 : int Create(const char *pszFile, char **papszOptions); 129 : 130 0 : const char *GetName() override 131 : { 132 0 : return pszName; 133 : } 134 : 135 64 : int GetLayerCount() override 136 : { 137 64 : return poReader ? poReader->GetLayerCount() : 0; 138 : } 139 : 140 : OGRLayer *GetLayer(int) override; 141 : OGRILI1Layer *GetLayerByName(const char *) override; 142 : 143 745 : VSILFILE *GetTransferFile() 144 : { 145 745 : return fpTransfer; 146 : } 147 : 148 : OGRLayer *ICreateLayer(const char *pszName, 149 : const OGRGeomFieldDefn *poGeomFieldDefn, 150 : CSLConstList papszOptions) override; 151 : 152 : int TestCapability(const char *) override; 153 : }; 154 : 155 : #endif /* OGR_ILI1_H_INCLUDED */