1 /****************************************************************************** 2 * $Id: ogr_sxf.h 842d122d2f23aaebb28362e083b52d6bc7dbcde2 2019-08-11 17:42:34 +0200 Even Rouault $ 3 * 4 * Project: SXF Translator 5 * Purpose: Include file defining classes for OGR SXF driver, datasource and layers. 6 * Author: Ben Ahmed Daho Ali, bidandou(at)yahoo(dot)fr 7 * Dmitry Baryshnikov, polimax@mail.ru 8 * Alexandr Lisovenko, alexander.lisovenko@gmail.com 9 * 10 ****************************************************************************** 11 * Copyright (c) 2011, Ben Ahmed Daho Ali 12 * Copyright (c) 2013, NextGIS 13 * 14 * Permission is hereby granted, free of charge, to any person obtaining a 15 * copy of this software and associated documentation files (the "Software"), 16 * to deal in the Software without restriction, including without limitation 17 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 18 * and/or sell copies of the Software, and to permit persons to whom the 19 * Software is furnished to do so, subject to the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be included 22 * in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 27 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 30 * DEALINGS IN THE SOFTWARE. 31 ****************************************************************************/ 32 33 #ifndef OGR_SXF_H_INCLUDED 34 #define OGR_SXF_H_INCLUDED 35 36 #include <set> 37 #include <vector> 38 #include <map> 39 40 #include "ogrsf_frmts.h" 41 #include "org_sxf_defs.h" 42 43 #define CHECK_BIT(var,pos) (((var) & (1<<(pos))) != 0) 44 #define TO_DEGREES 57.2957795130823208766 45 #define TO_RADIANS 0.017453292519943295769 46 47 /************************************************************************/ 48 /* OGRSXFLayer */ 49 /************************************************************************/ 50 class OGRSXFLayer final: public OGRLayer 51 { 52 protected: 53 OGRFeatureDefn* poFeatureDefn; 54 VSILFILE* fpSXF; 55 GByte nLayerID; 56 std::map<unsigned, CPLString> mnClassificators; 57 std::map<long, vsi_l_offset> mnRecordDesc; 58 std::map<long, vsi_l_offset>::const_iterator oNextIt; 59 SXFMapDescription stSXFMapDescription; 60 std::set<GUInt16> snAttributeCodes; 61 int m_nSXFFormatVer; 62 CPLString sFIDColumn_; 63 CPLMutex **m_hIOMutex; 64 double m_dfCoeff; 65 virtual OGRFeature * GetNextRawFeature(long nFID); 66 67 GUInt32 TranslateXYH(const SXFRecordDescription& certifInfo, 68 const char *psBuff, GUInt32 nBufLen, 69 double *dfX, double *dfY, double *dfH = nullptr); 70 71 OGRFeature *TranslatePoint(const SXFRecordDescription& certifInfo, const char * psRecordBuf, GUInt32 nBufLen); 72 OGRFeature *TranslateText(const SXFRecordDescription& certifInfo, const char * psBuff, GUInt32 nBufLen); 73 OGRFeature *TranslatePolygon(const SXFRecordDescription& certifInfo, const char * psBuff, GUInt32 nBufLen); 74 OGRFeature *TranslateLine(const SXFRecordDescription& certifInfo, const char * psBuff, GUInt32 nBufLen); 75 OGRFeature *TranslateVetorAngle(const SXFRecordDescription& certifInfo, const char * psBuff, GUInt32 nBufLen); 76 public: 77 OGRSXFLayer(VSILFILE* fp, CPLMutex** hIOMutex, GByte nID, const char* pszLayerName, int nVer, const SXFMapDescription& sxfMapDesc); 78 virtual ~OGRSXFLayer(); 79 80 virtual void ResetReading() override; 81 virtual OGRFeature *GetNextFeature() override; 82 virtual OGRErr SetNextByIndex(GIntBig nIndex) override; 83 virtual OGRFeature *GetFeature(GIntBig nFID) override; GetLayerDefn()84 virtual OGRFeatureDefn *GetLayerDefn() override { return poFeatureDefn;} 85 86 virtual int TestCapability( const char * ) override; 87 88 virtual GIntBig GetFeatureCount(int bForce = TRUE) override; 89 virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override; GetExtent(int iGeomField,OGREnvelope * psExtent,int bForce)90 virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce) override 91 { return OGRLayer::GetExtent(iGeomField, psExtent, bForce); } 92 virtual OGRSpatialReference *GetSpatialRef() override; 93 virtual const char* GetFIDColumn() override; 94 GetId()95 virtual GByte GetId() const { return nLayerID; } 96 virtual void AddClassifyCode(unsigned nClassCode, const char *szName = nullptr); 97 virtual bool AddRecord( long nFID, unsigned nClassCode, 98 vsi_l_offset nOffset, bool bHasSemantic, 99 size_t nSemanticsSize ); 100 private: 101 static int CanRecode(const char* pszEncoding); 102 }; 103 104 /************************************************************************/ 105 /* OGRSXFDataSource */ 106 /************************************************************************/ 107 108 class OGRSXFDataSource final: public OGRDataSource 109 { 110 SXFPassport oSXFPassport; 111 112 CPLString pszName; 113 114 OGRLayer** papoLayers; 115 size_t nLayers; 116 117 VSILFILE* fpSXF; 118 CPLMutex *hIOMutex; 119 void FillLayers(); 120 void CreateLayers(); 121 void CreateLayers(VSILFILE* fpRSC, const char* const* papszOpenOpts); 122 static OGRErr ReadSXFInformationFlags(VSILFILE* fpSXF, SXFPassport& passport); 123 OGRErr ReadSXFDescription(VSILFILE* fpSXF, SXFPassport& passport); 124 static void SetVertCS(const long iVCS, SXFPassport& passport, 125 const char* const* papszOpenOpts); 126 static OGRErr ReadSXFMapDescription(VSILFILE* fpSXF, SXFPassport& passport, 127 const char* const* papszOpenOpts); 128 OGRSXFLayer* GetLayerById(GByte); 129 public: 130 OGRSXFDataSource(); 131 virtual ~OGRSXFDataSource(); 132 133 int Open(const char * pszFilename, bool bUpdate, 134 const char* const* papszOpenOpts = nullptr ); 135 GetName()136 virtual const char* GetName() override { return pszName; } 137 GetLayerCount()138 virtual int GetLayerCount() override { return static_cast<int>(nLayers); } 139 virtual OGRLayer* GetLayer( int ) override; 140 141 virtual int TestCapability( const char * ) override; 142 void CloseFile(); 143 }; 144 145 /************************************************************************/ 146 /* OGRSXFDriver */ 147 /************************************************************************/ 148 149 class OGRSXFDriver final: public GDALDriver 150 { 151 public: 152 ~OGRSXFDriver(); 153 154 static GDALDataset* Open( GDALOpenInfo * ); 155 static int Identify( GDALOpenInfo * ); 156 static CPLErr DeleteDataSource(const char* pszName); 157 }; 158 159 #endif 160