Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OpenGIS Simple Features Reference Implementation 4 : * Purpose: C++ classes for the MiraMon driver 5 : * Author: Abel Pau 6 : ****************************************************************************** 7 : * Copyright (c) 2024, Xavier Pons 8 : * 9 : * SPDX-License-Identifier: MIT 10 : ****************************************************************************/ 11 : 12 : #ifndef OGRMIRAMON_H_INCLUDED 13 : #define OGRMIRAMON_H_INCLUDED 14 : 15 : #include "ogrsf_frmts.h" 16 : #include "ogr_api.h" 17 : #include "cpl_string.h" 18 : #include "mm_wrlayr.h" 19 : 20 : /************************************************************************/ 21 : /* OGRMiraMonLayer */ 22 : /************************************************************************/ 23 : 24 : class OGRMiraMonLayer final 25 : : public OGRLayer, 26 : public OGRGetNextFeatureThroughRaw<OGRMiraMonLayer> 27 : { 28 : GDALDataset *m_poDS; 29 : OGRSpatialReference *m_poSRS; 30 : OGRFeatureDefn *m_poFeatureDefn; 31 : 32 : GUIntBig m_iNextFID; 33 : 34 : // Pointer to one of three possible MiraMon layers: points, 35 : // arcs or polygons. Every time a feature is read this pointer 36 : // points to the appropriate layer 37 : struct MiraMonVectLayerInfo *phMiraMonLayer; 38 : 39 : // When writing a layer 40 : struct MiraMonVectLayerInfo hMiraMonLayerPNT; // MiraMon points layer 41 : struct MiraMonVectLayerInfo hMiraMonLayerARC; // MiraMon arcs layer 42 : struct MiraMonVectLayerInfo hMiraMonLayerPOL; // MiraMon polygons layer 43 : 44 : // When reading a layer or the result of writing is only a DBF 45 : struct MiraMonVectLayerInfo hMiraMonLayerReadOrNonGeom; 46 : 47 : struct MiraMonFeature hMMFeature; // Feature reading/writing 48 : 49 : bool m_bUpdate; 50 : 51 : VSILFILE *m_fp = nullptr; 52 : 53 : // Array of doubles used in the field features processing 54 : double *padfValues; 55 : GInt64 *pnInt64Values; 56 : 57 : OGRFeature *GetNextRawFeature(); 58 : OGRFeature *GetFeature(GIntBig nFeatureId) override; 59 : void GoToFieldOfMultipleRecord(MM_INTERNAL_FID iFID, 60 : MM_EXT_DBF_N_RECORDS nIRecord, 61 : MM_EXT_DBF_N_FIELDS nIField); 62 : 63 : OGRErr MMDumpVertices(OGRGeometryH hGeom, MM_BOOLEAN bExternalRing, 64 : MM_BOOLEAN bUseVFG); 65 : OGRErr MMProcessGeometry(OGRGeometryH poGeom, OGRFeature *poFeature, 66 : MM_BOOLEAN bcalculateRecord); 67 : OGRErr MMProcessMultiGeometry(OGRGeometryH hGeom, OGRFeature *poFeature); 68 : OGRErr MMLoadGeometry(OGRGeometryH hGeom); 69 : OGRErr MMWriteGeometry(); 70 : GIntBig GetFeatureCount(int bForce) override; 71 : 72 : public: 73 : bool bValidFile; 74 : 75 : OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename, VSILFILE *fp, 76 : const OGRSpatialReference *poSRS, int bUpdate, 77 : CSLConstList papszOpenOptions, 78 : struct MiraMonVectMapInfo *MMMap); 79 : ~OGRMiraMonLayer() override; 80 : 81 : void ResetReading() override; 82 1372 : DEFINE_GET_NEXT_FEATURE_THROUGH_RAW(OGRMiraMonLayer) 83 : 84 : OGRErr TranslateFieldsToMM(); 85 : OGRErr TranslateFieldsValuesToMM(OGRFeature *poFeature); 86 : static int MM_SprintfDoubleSignifFigures(char *szChain, size_t size_szChain, 87 : int nSignifFigures, 88 : double dfRealValue); 89 : OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent, 90 : bool bForce) override; 91 : 92 : const OGRFeatureDefn *GetLayerDefn() const override; 93 : 94 : OGRErr ICreateFeature(OGRFeature *poFeature) override; 95 : 96 : virtual OGRErr CreateField(const OGRFieldDefn *poField, 97 : int bApproxOK = TRUE) override; 98 : 99 : int TestCapability(const char *) const override; 100 : void AddToFileList(CPLStringList &oFileList); 101 : 102 16 : GDALDataset *GetDataset() override 103 : { 104 16 : return m_poDS; 105 : } 106 : }; 107 : 108 : /************************************************************************/ 109 : /* OGRMiraMonDataSource */ 110 : /************************************************************************/ 111 : 112 : class OGRMiraMonDataSource final : public GDALDataset 113 : { 114 : std::vector<std::unique_ptr<OGRMiraMonLayer>> m_apoLayers; 115 : std::string m_osRootName{}; 116 : bool m_bUpdate = false; 117 : struct MiraMonVectMapInfo m_MMMap; 118 : 119 : public: 120 : OGRMiraMonDataSource(); 121 : ~OGRMiraMonDataSource() override; 122 : 123 : bool Open(const char *pszFilename, VSILFILE *fp, 124 : const OGRSpatialReference *poSRS, CSLConstList papszOpenOptions); 125 : bool Create(const char *pszFilename, CSLConstList papszOptions); 126 : 127 409 : int GetLayerCount() const override 128 : { 129 409 : return static_cast<int>(m_apoLayers.size()); 130 : } 131 : 132 : const OGRLayer *GetLayer(int) const override; 133 : char **GetFileList() override; 134 : 135 : OGRLayer *ICreateLayer(const char *pszLayerName, 136 : const OGRGeomFieldDefn *poGeomFieldDefn, 137 : CSLConstList papszOptions) override; 138 : 139 : int TestCapability(const char *) const override; 140 : }; 141 : 142 : #endif /* OGRMIRAMON_H_INCLUDED */