LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/wasp - ogrwasp.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 11 11 100.0 %
Date: 2025-07-11 10:11:13 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  WAsP Translator
       4             :  * Purpose:  Definition of classes for OGR .map driver.
       5             :  * Author:   Vincent Mora, vincent dot mora at oslandia dot com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2014, Oslandia <info at oslandia dot com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #ifndef OGR_WASP_H_INCLUDED
      14             : #define OGR_WASP_H_INCLUDED
      15             : 
      16             : #include "ogrsf_frmts.h"
      17             : 
      18             : #include <memory>
      19             : #include <fstream>
      20             : #include <vector>
      21             : 
      22             : /************************************************************************/
      23             : /*                             OGRWAsPLayer                             */
      24             : /************************************************************************/
      25             : 
      26             : class OGRWAsPLayer final : public OGRLayer,
      27             :                            public OGRGetNextFeatureThroughRaw<OGRWAsPLayer>
      28             : {
      29             :     /* stuff for polygon processing */
      30             : 
      31             :     /* note if shared ptr are available, replace the ptr in the two structs */
      32             :     /* and remove deletion of array elements in ~OGRWAsPLayer() */
      33             :     struct Zone
      34             :     {
      35             :         OGREnvelope oEnvelope;
      36             :         OGRPolygon *poPolygon;
      37             :         double dfZ;
      38             :     };
      39             : 
      40             :     struct Boundary
      41             :     {
      42             :         OGRLineString *poLine;
      43             :         double dfLeft;
      44             :         double dfRight;
      45             :     };
      46             : 
      47             :     GDALDataset *m_poDS = nullptr;
      48             :     const bool bMerge;
      49             :     std::vector<Zone> oZones{};
      50             :     std::vector<Boundary> oBoundaries{};
      51             : 
      52          45 :     static bool isEqual(const double &dfRouhness1, const double &dfRouhness2)
      53             :     {
      54          45 :         return fabs(dfRouhness1 - dfRouhness2) < 1e-3;
      55             :     }
      56             : 
      57             :     /* end of stuff for polygon processing */
      58             : 
      59             :     int iFeatureCount{};
      60             : 
      61             :     const CPLString sName;
      62             :     VSILFILE *hFile{};
      63             : 
      64             :     /* for roughness zone, two fields for linestrings (left/right), one for
      65             :      * polygons */
      66             :     /* for elevation, one field (height) */
      67             :     const CPLString sFirstField;
      68             :     const CPLString sSecondField;
      69             :     const CPLString sGeomField;
      70             :     int iFirstFieldIdx{};
      71             :     int iSecondFieldIdx{};
      72             :     int iGeomFieldIdx{};
      73             : 
      74             :     OGRFeatureDefn *poLayerDefn{};
      75             :     OGRSpatialReference *poSpatialReference{};
      76             : 
      77             :     vsi_l_offset iOffsetFeatureBegin{};
      78             : 
      79             :     enum OpenMode
      80             :     {
      81             :         READ_ONLY,
      82             :         WRITE_ONLY
      83             :     };
      84             : 
      85             :     OpenMode eMode = READ_ONLY;
      86             : 
      87             :     std::unique_ptr<double> pdfTolerance{};
      88             :     std::unique_ptr<double> pdfAdjacentPointTolerance{};
      89             :     std::unique_ptr<double> pdfPointToCircleRadius{};
      90             : 
      91             :     OGRErr WriteRoughness(OGRLineString *, const double &dfZleft,
      92             :                           const double &dfZright);
      93             :     OGRErr WriteRoughness(OGRPolygon *, const double &dfZ);
      94             :     OGRErr WriteRoughness(OGRGeometry *, const double &dfZleft,
      95             :                           const double &dfZright);
      96             : 
      97             :     OGRErr WriteElevation(OGRLineString *, const double &dfZ);
      98             :     OGRErr WriteElevation(OGRGeometry *, const double &dfZ);
      99             : 
     100             :     static double AvgZ(OGRLineString *poGeom);
     101             :     static double AvgZ(OGRPolygon *poGeom);
     102             :     static double AvgZ(OGRGeometryCollection *poGeom);
     103             :     static double AvgZ(OGRGeometry *poGeom);
     104             : 
     105             :     /* return a simplified line (caller is responsible for resource)
     106             :      *
     107             :      * if pdfTolerance is not NULL,
     108             :      *     calls GEOS simplify
     109             :      *
     110             :      * if pdfAdjacentPointTolerance is not NULL,
     111             :      *     remove consecutive points that are less than tolerance apart
     112             :      *     in x and y
     113             :      *
     114             :      * if pdfPointToCircleRadius is not NULL,
     115             :      *     lines that have been simplified to a point are converted to a 8 pt
     116             :      * circle
     117             :      * */
     118             :     OGRLineString *Simplify(const OGRLineString &line) const;
     119             : 
     120             :     OGRFeature *GetNextRawFeature();
     121             : 
     122             :     CPL_DISALLOW_COPY_ASSIGN(OGRWAsPLayer)
     123             : 
     124             :   public:
     125             :     /* For writing */
     126             :     /* Takes ownership of poTolerance */
     127             :     OGRWAsPLayer(GDALDataset *poDS, const char *pszName, VSILFILE *hFile,
     128             :                  OGRSpatialReference *poSpatialRef,
     129             :                  const CPLString &sFirstField, const CPLString &sSecondField,
     130             :                  const CPLString &sGeomField, bool bMerge, double *pdfTolerance,
     131             :                  double *pdfAdjacentPointTolerance,
     132             :                  double *pdfPointToCircleRadius);
     133             : 
     134             :     /* For reading */
     135             :     OGRWAsPLayer(GDALDataset *poDS, const char *pszName, VSILFILE *hFile,
     136             :                  OGRSpatialReference *poSpatialRef);
     137             : 
     138             :     virtual ~OGRWAsPLayer();
     139             : 
     140         240 :     virtual OGRFeatureDefn *GetLayerDefn() override
     141             :     {
     142         240 :         return poLayerDefn;
     143             :     }
     144             : 
     145             :     virtual void ResetReading() override;
     146             :     virtual int TestCapability(const char *) override;
     147             : 
     148             :     virtual OGRErr CreateField(const OGRFieldDefn *poField,
     149             :                                int bApproxOK = TRUE) override;
     150             :     virtual OGRErr CreateGeomField(const OGRGeomFieldDefn *poGeomField,
     151             :                                    int bApproxOK = TRUE) override;
     152             : 
     153             :     virtual OGRErr ICreateFeature(OGRFeature *poFeature) override;
     154             : 
     155          19 :     DEFINE_GET_NEXT_FEATURE_THROUGH_RAW(OGRWAsPLayer)
     156             : 
     157          10 :     virtual const char *GetName() override
     158             :     {
     159          10 :         return sName.c_str();
     160             :     }
     161             : 
     162          10 :     GDALDataset *GetDataset() override
     163             :     {
     164          10 :         return m_poDS;
     165             :     }
     166             : };
     167             : 
     168             : /************************************************************************/
     169             : /*                           OGRWAsPDataSource                          */
     170             : /************************************************************************/
     171             : 
     172             : class OGRWAsPDataSource final : public GDALDataset
     173             : {
     174             :     CPLString sFilename{};
     175             :     VSILFILE *hFile{};
     176             :     std::unique_ptr<OGRWAsPLayer> oLayer{};
     177             : 
     178             :     void GetOptions(CPLString &sFirstField, CPLString &sSecondField,
     179             :                     CPLString &sGeomField, bool &bMerge) const;
     180             : 
     181             :     CPL_DISALLOW_COPY_ASSIGN(OGRWAsPDataSource)
     182             : 
     183             :   public:
     184             :     /** @note takes ownership of hFile (i.e. responsibility for closing) */
     185             :     OGRWAsPDataSource(const char *pszName, VSILFILE *hFile);
     186             :     virtual ~OGRWAsPDataSource();
     187             : 
     188           1 :     virtual int GetLayerCount() override
     189             :     {
     190           1 :         return oLayer.get() ? 1 : 0;
     191             :     }
     192             : 
     193             :     virtual OGRLayer *GetLayer(int) override;
     194             :     virtual OGRLayer *GetLayerByName(const char *) override;
     195             : 
     196             :     OGRLayer *ICreateLayer(const char *pszName,
     197             :                            const OGRGeomFieldDefn *poGeomFieldDefn,
     198             :                            CSLConstList papszOptions) override;
     199             : 
     200             :     virtual int TestCapability(const char *) override;
     201             :     OGRErr Load(bool bSilent = false);
     202             : };
     203             : 
     204             : #endif /* ndef OGR_WASP_H_INCLUDED */

Generated by: LCOV version 1.14