| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Project: SXF Translator |
| 4 | * Purpose: Definition of classes for OGR SXF driver. |
| 5 | * Author: Ben Ahmed Daho Ali, bidandou(at)yahoo(dot)fr |
| 6 | * Dmitry Baryshnikov, [email protected] |
| 7 | * |
| 8 | ****************************************************************************** |
| 9 | * Copyright (c) 2011, Ben Ahmed Daho Ali |
| 10 | * Copyright (c) 2013, NextGIS |
| 11 | * Copyright (c) 2014, Even Rouault <even dot rouault at spatialys.com> |
| 12 | * |
| 13 | * SPDX-License-Identifier: MIT |
| 14 | ****************************************************************************/ |
| 15 | |
| 16 | #include "cpl_conv.h"cxx . . $ `<file>/port/cpl_conv.h`/ |
| 17 | #include "ogr_sxf.h"cxx . . $ `<file>/ogr/ogrsf_frmts/sxf/ogr_sxf.h`/ |
| 18 | |
| 19 | /************************************************************************/ |
| 20 | /* Open() */ |
| 21 | /************************************************************************/ |
| 22 | |
| 23 | static GDALDatasetcxx . . $ GDALDataset# *OGRSXFDriverOpencxx . . $ OGRSXFDriverOpen(905b7966ba8c1649).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 24 | |
| 25 | { |
| 26 | /* -------------------------------------------------------------------- */ |
| 27 | /* Determine what sort of object this is. */ |
| 28 | /* -------------------------------------------------------------------- */ |
| 29 | |
| 30 | VSIStatBufL sStatBuf; |
| 31 | if (!poOpenInfo->IsExtensionEqualToCIcxx . . $ GDALOpenInfo#IsExtensionEqualToCI(7d4bdb1abc417636).("sxf") || |
| 32 | VSIStatL(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., &sStatBuf) != 0 || |
| 33 | !VSI_ISREGcxx . . $ `port/cpl_vsi.h:120:9`!(sStatBuf.st_mode)) |
| 34 | return nullptr; |
| 35 | |
| 36 | OGRSXFDataSourcecxx . . $ OGRSXFDataSource# *poDS = new OGRSXFDataSourcecxx . . $ OGRSXFDataSource#(); |
| 37 | |
| 38 | if (!poDS->Opencxx . . $ OGRSXFDataSource#Open(f6535c476e85e5b0).(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., poOpenInfo->eAccesscxx . . $ GDALOpenInfo#eAccess. == GA_Update, |
| 39 | poOpenInfo->papszOpenOptionscxx . . $ GDALOpenInfo#papszOpenOptions.)) |
| 40 | { |
| 41 | delete poDS; |
| 42 | poDS = nullptr; |
| 43 | } |
| 44 | |
| 45 | return poDS; |
| 46 | } |
| 47 | |
| 48 | /************************************************************************/ |
| 49 | /* Identify() */ |
| 50 | /************************************************************************/ |
| 51 | |
| 52 | static int OGRSXFDriverIdentifycxx . . $ OGRSXFDriverIdentify(48f695ac6b30cd84).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 53 | { |
| 54 | if (!poOpenInfo->IsExtensionEqualToCIcxx . . $ GDALOpenInfo#IsExtensionEqualToCI(7d4bdb1abc417636).("sxf") || !poOpenInfo->bStatOKcxx . . $ GDALOpenInfo#bStatOK. || |
| 55 | poOpenInfo->bIsDirectorycxx . . $ GDALOpenInfo#bIsDirectory.) |
| 56 | { |
| 57 | return GDAL_IDENTIFY_FALSEcxx . . $ GDAL_IDENTIFY_FALSE.; |
| 58 | } |
| 59 | |
| 60 | if (poOpenInfo->nHeaderBytescxx . . $ GDALOpenInfo#nHeaderBytes. < 4) |
| 61 | { |
| 62 | return GDAL_IDENTIFY_UNKNOWNcxx . . $ GDAL_IDENTIFY_UNKNOWN.; |
| 63 | } |
| 64 | |
| 65 | if (0 != memcmp(poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader., "SXF", 3)) |
| 66 | { |
| 67 | return GDAL_IDENTIFY_FALSEcxx . . $ GDAL_IDENTIFY_FALSE.; |
| 68 | } |
| 69 | |
| 70 | return GDAL_IDENTIFY_TRUEcxx . . $ GDAL_IDENTIFY_TRUE.; |
| 71 | } |
| 72 | |
| 73 | /************************************************************************/ |
| 74 | /* GRSXFDriverDelete() */ |
| 75 | /************************************************************************/ |
| 76 | |
| 77 | static CPLErr OGRSXFDriverDeletecxx . . $ OGRSXFDriverDelete(80d06f1dc84b2c8f).(const char *pszName) |
| 78 | { |
| 79 | // TODO: add more extensions if applicable |
| 80 | static const char *const apszExtensions[] = {"szf", "rsc", "SZF", "RSC", |
| 81 | nullptr}; |
| 82 | |
| 83 | VSIStatBufL sStatBuf; |
| 84 | if (VSIStatL(pszName, &sStatBuf) != 0) |
| 85 | { |
| 86 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 87 | "%s does not appear to be a valid sxf file.", pszName); |
| 88 | |
| 89 | return CE_Failure; |
| 90 | } |
| 91 | |
| 92 | for (int iExt = 0; apszExtensions[iExt] != nullptr; iExt++) |
| 93 | { |
| 94 | const stdcxx . . $ std/::string osFile = |
| 95 | CPLResetExtensionSafe(pszName, apszExtensions[iExt]); |
| 96 | if (VSIStatL(osFile.c_str(), &sStatBuf) == 0) |
| 97 | VSIUnlink(osFile.c_str()); |
| 98 | } |
| 99 | |
| 100 | return CE_None; |
| 101 | } |
| 102 | |
| 103 | /************************************************************************/ |
| 104 | /* RegisterOGRSXF() */ |
| 105 | /************************************************************************/ |
| 106 | void RegisterOGRSXFcxx . . $ RegisterOGRSXF(49f6e7a06ebc5aa8).() |
| 107 | { |
| 108 | if (GDALGetDriverByName("SXF") != nullptr) |
| 109 | return; |
| 110 | |
| 111 | GDALDrivercxx . . $ GDALDriver# *poDriver = new GDALDrivercxx . . $ GDALDriver#GDALDriver(49f6e7a06ebc5aa8).(); |
| 112 | |
| 113 | poDriver->SetDescriptioncxx . . $ GDALMajorObject#SetDescription(85c52e162fed56f9).("SXF"); |
| 114 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_VECTORcxx . . $ `gcore/gdal.h:682:9`!, "YES"); |
| 115 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_LONGNAMEcxx . . $ `gcore/gdal.h:443:9`!, "Storage and eXchange Format"); |
| 116 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_HELPTOPICcxx . . $ `gcore/gdal.h:446:9`!, "drivers/vector/sxf.html"); |
| 117 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_EXTENSIONcxx . . $ `gcore/gdal.h:452:9`!, "sxf"); |
| 118 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_VIRTUALIOcxx . . $ `gcore/gdal.h:674:9`!, "YES"); |
| 119 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_Z_GEOMETRIEScxx . . $ `gcore/gdal.h:780:9`!, "YES"); |
| 120 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_SUPPORTED_SQL_DIALECTScxx . . $ `gcore/gdal.h:991:9`!, "OGRSQL SQLITE"); |
| 121 | poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).( |
| 122 | GDAL_DMD_OPENOPTIONLISTcxx . . $ `gcore/gdal.h:509:9`!, |
| 123 | "<OpenOptionList>" |
| 124 | " <Option name='SXF_LAYER_FULLNAME' type='string' description='Use " |
| 125 | "long layer names' default='NO'/>" |
| 126 | " <Option name='SXF_RSC_FILENAME' type='string' description='RSC file " |
| 127 | "name' default=''/>" |
| 128 | " <Option name='SXF_SET_VERTCS' type='string' description='Layers " |
| 129 | "spatial reference will include vertical coordinate system description " |
| 130 | "if exist' default='NO'/>" |
| 131 | "</OpenOptionList>"); |
| 132 | |
| 133 | poDriver->pfnOpencxx . . $ GDALDriver#pfnOpen. = OGRSXFDriverOpencxx . . $ OGRSXFDriverOpen(905b7966ba8c1649).; |
| 134 | poDriver->pfnDeletecxx . . $ GDALDriver#pfnDelete. = OGRSXFDriverDeletecxx . . $ OGRSXFDriverDelete(80d06f1dc84b2c8f).; |
| 135 | poDriver->pfnIdentifycxx . . $ GDALDriver#pfnIdentify. = OGRSXFDriverIdentifycxx . . $ OGRSXFDriverIdentify(48f695ac6b30cd84).; |
| 136 | |
| 137 | GetGDALDriverManager()->RegisterDrivercxx . . $ GDALDriverManager#RegisterDriver(ed1dabcc01594d64).(poDriver); |
| 138 | } |