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: 2024-11-21 22:18:42 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;
      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             :   public:
     123             :     /* For writing */
     124             :     /* Takes ownership of poTolerance */
     125             :     OGRWAsPLayer(GDALDataset *poDS, const char *pszName, VSILFILE *hFile,
     126             :                  OGRSpatialReference *poSpatialRef,
     127             :                  const CPLString &sFirstField, const CPLString &sSecondField,
     128             :                  const CPLString &sGeomField, bool bMerge, double *pdfTolerance,
     129             :                  double *pdfAdjacentPointTolerance,
     130             :                  double *pdfPointToCircleRadius);
     131             : 
     132             :     /* For reading */
     133             :     OGRWAsPLayer(GDALDataset *poDS, const char *pszName, VSILFILE *hFile,
     134             :                  OGRSpatialReference *poSpatialRef);
     135             : 
     136             :     virtual ~OGRWAsPLayer();
     137             : 
     138         240 :     virtual OGRFeatureDefn *GetLayerDefn() override
     139             :     {
     140         240 :         return poLayerDefn;
     141             :     }
     142             : 
     143             :     virtual void ResetReading() override;
     144             :     virtual int TestCapability(const char *) override;
     145             : 
     146             :     virtual OGRErr CreateField(const OGRFieldDefn *poField,
     147             :                                int bApproxOK = TRUE) override;
     148             :     virtual OGRErr CreateGeomField(const OGRGeomFieldDefn *poGeomField,
     149             :                                    int bApproxOK = TRUE) override;
     150             : 
     151             :     virtual OGRErr ICreateFeature(OGRFeature *poFeature) override;
     152             : 
     153          19 :     DEFINE_GET_NEXT_FEATURE_THROUGH_RAW(OGRWAsPLayer)
     154             : 
     155          10 :     virtual const char *GetName() override
     156             :     {
     157          10 :         return sName.c_str();
     158             :     }
     159             : 
     160          10 :     GDALDataset *GetDataset() override
     161             :     {
     162          10 :         return m_poDS;
     163             :     }
     164             : };
     165             : 
     166             : /************************************************************************/
     167             : /*                           OGRWAsPDataSource                          */
     168             : /************************************************************************/
     169             : 
     170             : class OGRWAsPDataSource final : public GDALDataset
     171             : {
     172             :     CPLString sFilename;
     173             :     VSILFILE *hFile;
     174             :     std::unique_ptr<OGRWAsPLayer> oLayer;
     175             : 
     176             :     void GetOptions(CPLString &sFirstField, CPLString &sSecondField,
     177             :                     CPLString &sGeomField, bool &bMerge) const;
     178             : 
     179             :   public:
     180             :     /** @note takes ownership of hFile (i.e. responsibility for closing) */
     181             :     OGRWAsPDataSource(const char *pszName, VSILFILE *hFile);
     182             :     virtual ~OGRWAsPDataSource();
     183             : 
     184           1 :     virtual int GetLayerCount() override
     185             :     {
     186           1 :         return oLayer.get() ? 1 : 0;
     187             :     }
     188             : 
     189             :     virtual OGRLayer *GetLayer(int) override;
     190             :     virtual OGRLayer *GetLayerByName(const char *) override;
     191             : 
     192             :     OGRLayer *ICreateLayer(const char *pszName,
     193             :                            const OGRGeomFieldDefn *poGeomFieldDefn,
     194             :                            CSLConstList papszOptions) override;
     195             : 
     196             :     virtual int TestCapability(const char *) override;
     197             :     OGRErr Load(bool bSilent = false);
     198             : };
     199             : 
     200             : #endif /* ndef OGR_WASP_H_INCLUDED */

Generated by: LCOV version 1.14