LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/sosi - ogr_sosi.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 19 23 82.6 %
Date: 2024-05-14 23:54:21 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  SOSI Translator
       5             :  * Purpose:  Implements OGRSOSIDriver.
       6             :  * Author:   Thomas Hirsch, <thomas.hirsch statkart no>
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2010, Thomas Hirsch
      10             :  * Copyright (c) 2010, Even Rouault <even dot rouault at spatialys.com>
      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_SOSI_H_INCLUDED
      32             : #define OGR_SOSI_H_INCLUDED
      33             : 
      34             : #include "ogrsf_frmts.h"
      35             : #include "fyba.h"
      36             : #include <map>
      37             : 
      38             : // Note: WRITE_SUPPORT not defined, since this is only partially implemented
      39             : 
      40             : /* interpolation of arcs(BUEP) creates # points for a full circle */
      41             : #define ARC_INTERPOLATION_FULL_CIRCLE 36.0
      42             : 
      43             : typedef std::map<std::string, std::string> S2S;
      44             : typedef std::map<std::string, unsigned int> S2I;
      45             : 
      46             : void RegisterOGRSOSI();
      47             : 
      48             : class ORGSOSILayer;      /* defined below */
      49             : class OGRSOSIDataSource; /* defined below */
      50             : 
      51             : /************************************************************************
      52             :  *                           OGRSOSILayer                               *
      53             :  * OGRSOSILayer reports all the OGR Features generated by the data      *
      54             :  * source, in an orderly fashion.                                       *
      55             :  ************************************************************************/
      56             : 
      57             : class OGRSOSILayer final : public OGRLayer
      58             : {
      59             :     int nNextFID;
      60             : 
      61             :     OGRSOSIDataSource *poParent; /* used to call methods from data source */
      62             :     LC_FILADM *poFileadm; /* ResetReading needs to refer to the file struct */
      63             :     OGRFeatureDefn *poFeatureDefn; /* the common definition of all features
      64             :                                       returned by this layer  */
      65             :     S2I *poHeaderDefn;
      66             : 
      67             :     LC_SNR_ADM oSnradm;
      68             :     LC_BGR oNextSerial; /* used by FYBA to iterate through features */
      69             :     LC_BGR *poNextSerial;
      70             : 
      71             :   public:
      72             :     OGRSOSILayer(OGRSOSIDataSource *poPar, OGRFeatureDefn *poFeatDefn,
      73             :                  LC_FILADM *poFil, S2I *poHeadDefn);
      74             :     ~OGRSOSILayer();
      75             : 
      76             :     void ResetReading() override;
      77             :     OGRFeature *GetNextFeature() override;
      78             :     OGRFeatureDefn *GetLayerDefn() override;
      79             : #ifdef WRITE_SUPPORT
      80             :     OGRErr CreateField(OGRFieldDefn *poField, int bApproxOK = TRUE) override;
      81             :     OGRErr ICreateFeature(OGRFeature *poFeature) override;
      82             : #endif
      83             :     int TestCapability(const char *) override;
      84             : };
      85             : 
      86             : /************************************************************************
      87             :  *                           OGRSOSIDataSource                          *
      88             :  * OGRSOSIDataSource reads a SOSI file, prebuilds the features, and     *
      89             :  * creates one OGRSOSILayer per geometry type                           *
      90             :  ************************************************************************/
      91             : class OGRSOSIDataSource final : public OGRDataSource
      92             : {
      93             :     char *pszName;
      94             :     OGRSOSILayer **papoLayers;
      95             :     int nLayers;
      96             : 
      97             : #define MODE_READING 0
      98             : #define MODE_WRITING 1
      99             :     int nMode;
     100             : 
     101             :     void buildOGRPoint(long nSerial);
     102             :     void buildOGRLineString(int nNumCoo, long nSerial);
     103             :     void buildOGRMultiPoint(int nNumCoo, long nSerial);
     104             :     void buildOGRLineStringFromArc(long nSerial);
     105             : 
     106             :   public:
     107             :     OGRSpatialReference *poSRS;
     108             :     const char *pszEncoding;
     109             :     unsigned int nNumFeatures;
     110             :     OGRGeometry **papoBuiltGeometries; /* OGRSOSIDataSource prebuilds some
     111             :                                         * features upon opening, te be used by
     112             :                                         * the more complex geometries later. */
     113             :     // FYBA specific
     114             :     LC_BASEADM *poBaseadm;
     115             :     LC_FILADM *poFileadm;
     116             : 
     117             :     S2I *poPolyHeaders; /* Contain the header definitions of the four feature
     118             :                            layers */
     119             :     S2I *poPointHeaders;
     120             :     S2I *poCurveHeaders;
     121             :     S2I *poTextHeaders;
     122             : 
     123             :     OGRSOSIDataSource();
     124             :     ~OGRSOSIDataSource();
     125             : 
     126             :     int Open(const char *pszFilename, int bUpdate);
     127             : #ifdef WRITE_SUPPORT
     128             :     int Create(const char *pszFilename);
     129             : #endif
     130           0 :     const char *GetName() override
     131             :     {
     132           0 :         return pszName;
     133             :     }
     134             : 
     135           0 :     int GetLayerCount() override
     136             :     {
     137           0 :         return nLayers;
     138             :     }
     139             : 
     140             :     OGRLayer *GetLayer(int) override;
     141             : #ifdef WRITE_SUPPORT
     142             :     OGRLayer *ICreateLayer(const char *pszName,
     143             :                            const OGRSpatialReference *poSpatialRef = NULL,
     144             :                            OGRwkbGeometryType eGType = wkbUnknown,
     145             :                            char **papszOptions = NULL) override;
     146             : #endif
     147             :     int TestCapability(const char *) override;
     148             : };
     149             : 
     150             : /************************************************************************
     151             :  *                           OGRSOSIDataTypes                           *
     152             :  * OGRSOSIDataTypes provides the correct data types for some of the     *
     153             :  * most common SOSI elements.                                           *
     154             :  ************************************************************************/
     155             : 
     156             : class OGRSOSISimpleDataType
     157             : {
     158             :     CPLString osName;
     159             :     OGRFieldType nType;
     160             : 
     161             :   public:
     162             :     OGRSOSISimpleDataType();
     163             :     OGRSOSISimpleDataType(const char *pszName, OGRFieldType nType);
     164             :     ~OGRSOSISimpleDataType();
     165             : 
     166             :     void setType(const char *pszName, OGRFieldType nType);
     167             : 
     168        1110 :     const char *GetName() const
     169             :     {
     170        1110 :         return osName.c_str();
     171             :     }
     172             : 
     173         483 :     OGRFieldType GetType() const
     174             :     {
     175         483 :         return nType;
     176             :     }
     177             : };
     178             : 
     179             : class OGRSOSIDataType
     180             : {
     181             :     OGRSOSISimpleDataType *poElements = nullptr;
     182             :     int nElementCount = 0;
     183             : 
     184             :     OGRSOSIDataType &operator=(const OGRSOSIDataType &) = delete;
     185             : 
     186             :   public:
     187             :     explicit OGRSOSIDataType(int nSize);
     188             : 
     189        1481 :     OGRSOSIDataType(const OGRSOSIDataType &oSrc)
     190        1481 :         : poElements(nullptr), nElementCount(oSrc.nElementCount)
     191             :     {
     192        3271 :         poElements = new OGRSOSISimpleDataType[nElementCount];
     193        3271 :         for (int i = 0; i < nElementCount; i++)
     194        1790 :             poElements[i] = oSrc.poElements[i];
     195        1481 :     }
     196             : 
     197        1481 :     OGRSOSIDataType(OGRSOSIDataType &&oSrc) noexcept
     198        1481 :         : poElements(oSrc.poElements), nElementCount(oSrc.nElementCount)
     199             :     {
     200        1481 :         oSrc.poElements = nullptr;
     201        1481 :         oSrc.nElementCount = 0;
     202        1481 :     }
     203             : 
     204             :     ~OGRSOSIDataType();
     205             : 
     206             :     void setElement(int nIndex, const char *name, OGRFieldType type);
     207             : 
     208         486 :     OGRSOSISimpleDataType *getElements()
     209             :     {
     210         486 :         return poElements;
     211             :     }
     212             : 
     213        1041 :     int getElementCount()
     214             :     {
     215        1041 :         return nElementCount;
     216             :     }
     217             : };
     218             : 
     219             : typedef std::map<CPLString, OGRSOSIDataType> C2F;
     220             : 
     221             : void SOSIInitTypes();
     222             : void SOSICleanupTypes();
     223             : OGRSOSIDataType *SOSIGetType(const CPLString &name);
     224             : int SOSITypeToInt(const char *value);
     225             : double SOSITypeToReal(const char *value);
     226             : void SOSITypeToDate(const char *value, int *date);
     227             : void SOSITypeToDateTime(const char *value, int *date);
     228             : 
     229             : #endif /* OGR_SOSI_H_INCLUDED */

Generated by: LCOV version 1.14