Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: SDTS Translator 4 : * Purpose: Implements OGRSDTSDriver 5 : * Author: Frank Warmerdam, warmerdam@pobox.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 1999, Frank Warmerdam 9 : * 10 : * Permission is hereby granted, free of charge, to any person obtaining a 11 : * copy of this software and associated documentation files (the "Software"), 12 : * to deal in the Software without restriction, including without limitation 13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 : * and/or sell copies of the Software, and to permit persons to whom the 15 : * Software is furnished to do so, subject to the following conditions: 16 : * 17 : * The above copyright notice and this permission notice shall be included 18 : * in all copies or substantial portions of the Software. 19 : * 20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 : * DEALINGS IN THE SOFTWARE. 27 : ****************************************************************************/ 28 : 29 : #include "ogr_sdts.h" 30 : #include "cpl_conv.h" 31 : 32 : /************************************************************************/ 33 : /* Open() */ 34 : /************************************************************************/ 35 : 36 26501 : static GDALDataset *OGRSDTSDriverOpen(GDALOpenInfo *poOpenInfo) 37 : 38 : { 39 26501 : if (!EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "DDF")) 40 26500 : return nullptr; 41 1 : if (poOpenInfo->nHeaderBytes < 10) 42 0 : return nullptr; 43 1 : const char *pachLeader = (const char *)poOpenInfo->pabyHeader; 44 1 : if ((pachLeader[5] != '1' && pachLeader[5] != '2' && 45 0 : pachLeader[5] != '3') || 46 1 : pachLeader[6] != 'L' || (pachLeader[8] != '1' && pachLeader[8] != ' ')) 47 : { 48 0 : return nullptr; 49 : } 50 : 51 1 : OGRSDTSDataSource *poDS = new OGRSDTSDataSource(); 52 1 : if (!poDS->Open(poOpenInfo->pszFilename, TRUE)) 53 : { 54 0 : delete poDS; 55 0 : poDS = nullptr; 56 : } 57 : 58 1 : if (poDS != nullptr && poOpenInfo->eAccess == GA_Update) 59 : { 60 0 : CPLError(CE_Failure, CPLE_OpenFailed, 61 : "SDTS Driver doesn't support update."); 62 0 : delete poDS; 63 0 : poDS = nullptr; 64 : } 65 : 66 1 : return poDS; 67 : } 68 : 69 : /************************************************************************/ 70 : /* RegisterOGRSDTS() */ 71 : /************************************************************************/ 72 : 73 1512 : void RegisterOGRSDTS() 74 : 75 : { 76 1512 : if (GDALGetDriverByName("OGR_SDTS") != nullptr) 77 295 : return; 78 : 79 1217 : GDALDriver *poDriver = new GDALDriver(); 80 : 81 1217 : poDriver->SetDescription("OGR_SDTS"); 82 1217 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 83 1217 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "SDTS"); 84 1217 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/sdts.html"); 85 1217 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 86 1217 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); 87 : 88 1217 : poDriver->pfnOpen = OGRSDTSDriverOpen; 89 : 90 1217 : GetGDALDriverManager()->RegisterDriver(poDriver); 91 : }