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 : virtual ~OGRMiraMonLayer(); 80 : 81 : void ResetReading() override; 82 1279 : DEFINE_GET_NEXT_FEATURE_THROUGH_RAW(OGRMiraMonLayer) 83 : 84 : OGRErr TranslateFieldsToMM(); 85 : OGRErr TranslateFieldsValuesToMM(OGRFeature *poFeature); 86 : OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent, 87 : bool bForce) override; 88 : 89 : OGRFeatureDefn *GetLayerDefn() override; 90 : 91 : OGRErr ICreateFeature(OGRFeature *poFeature) override; 92 : 93 : virtual OGRErr CreateField(const OGRFieldDefn *poField, 94 : int bApproxOK = TRUE) override; 95 : 96 : int TestCapability(const char *) override; 97 : void AddToFileList(CPLStringList &oFileList); 98 : 99 16 : GDALDataset *GetDataset() override 100 : { 101 16 : return m_poDS; 102 : } 103 : }; 104 : 105 : /************************************************************************/ 106 : /* OGRMiraMonDataSource */ 107 : /************************************************************************/ 108 : 109 : class OGRMiraMonDataSource final : public GDALDataset 110 : { 111 : std::vector<std::unique_ptr<OGRMiraMonLayer>> m_apoLayers; 112 : std::string m_osRootName{}; 113 : bool m_bUpdate = false; 114 : struct MiraMonVectMapInfo m_MMMap; 115 : 116 : public: 117 : OGRMiraMonDataSource(); 118 : ~OGRMiraMonDataSource(); 119 : 120 : bool Open(const char *pszFilename, VSILFILE *fp, 121 : const OGRSpatialReference *poSRS, CSLConstList papszOpenOptions); 122 : bool Create(const char *pszFilename, CSLConstList papszOptions); 123 : 124 383 : int GetLayerCount() override 125 : { 126 383 : return static_cast<int>(m_apoLayers.size()); 127 : } 128 : 129 : OGRLayer *GetLayer(int) override; 130 : char **GetFileList() override; 131 : 132 : OGRLayer *ICreateLayer(const char *pszLayerName, 133 : const OGRGeomFieldDefn *poGeomFieldDefn, 134 : CSLConstList papszOptions) override; 135 : 136 : int TestCapability(const char *) override; 137 : }; 138 : 139 : #endif /* OGRMIRAMON_H_INCLUDED */