Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: UK NTF Reader 4 : * Purpose: Implements OGRNTFDriver 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 "ntf.h" 30 : #include "cpl_conv.h" 31 : 32 : /************************************************************************/ 33 : /* ==================================================================== */ 34 : /* OGRNTFDriver */ 35 : /* ==================================================================== */ 36 : /************************************************************************/ 37 : 38 : /************************************************************************/ 39 : /* Open() */ 40 : /************************************************************************/ 41 : 42 26532 : static GDALDataset *OGRNTFDriverOpen(GDALOpenInfo *poOpenInfo) 43 : 44 : { 45 26532 : if (!poOpenInfo->bStatOK) 46 21063 : return nullptr; 47 : 48 5469 : if (poOpenInfo->nHeaderBytes != 0) 49 : { 50 4808 : if (poOpenInfo->nHeaderBytes < 80) 51 273 : return nullptr; 52 4535 : const char *pszHeader = (const char *)poOpenInfo->pabyHeader; 53 4535 : if (!STARTS_WITH_CI(pszHeader, "01")) 54 4524 : return nullptr; 55 : 56 11 : int j = 0; // Used after for. 57 891 : for (; j < 80; j++) 58 : { 59 880 : if (pszHeader[j] == 10 || pszHeader[j] == 13) 60 : break; 61 : } 62 : 63 11 : if (j == 80 || pszHeader[j - 1] != '%') 64 11 : return nullptr; 65 : } 66 : 67 661 : OGRNTFDataSource *poDS = new OGRNTFDataSource; 68 661 : if (!poDS->Open(poOpenInfo->pszFilename, TRUE)) 69 : { 70 661 : delete poDS; 71 661 : poDS = nullptr; 72 : } 73 : 74 661 : if (poDS != nullptr && poOpenInfo->eAccess == GA_Update) 75 : { 76 0 : CPLError(CE_Failure, CPLE_OpenFailed, 77 : "NTF Driver doesn't support update."); 78 0 : delete poDS; 79 0 : poDS = nullptr; 80 : } 81 : 82 661 : return poDS; 83 : } 84 : 85 : /************************************************************************/ 86 : /* RegisterOGRNTF() */ 87 : /************************************************************************/ 88 : 89 1520 : void RegisterOGRNTF() 90 : 91 : { 92 1520 : if (GDALGetDriverByName("UK .NTF") != nullptr) 93 301 : return; 94 : 95 1219 : GDALDriver *poDriver = new GDALDriver(); 96 : 97 1219 : poDriver->SetDescription("UK .NTF"); 98 1219 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 99 1219 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "UK .NTF"); 100 1219 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/ntf.html"); 101 1219 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 102 1219 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 103 1219 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); 104 : 105 1219 : poDriver->pfnOpen = OGRNTFDriverOpen; 106 : 107 1219 : GetGDALDriverManager()->RegisterDriver(poDriver); 108 : }