Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: TIGER/Line Translator 4 : * Purpose: Implements OGRTigerDriver 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_tiger.h" 30 : #include "cpl_conv.h" 31 : 32 : /************************************************************************/ 33 : /* Open() */ 34 : /************************************************************************/ 35 : 36 20651 : static GDALDataset *OGRTigerDriverOpen(GDALOpenInfo *poOpenInfo) 37 : 38 : { 39 20651 : if (!poOpenInfo->bStatOK) 40 19698 : return nullptr; 41 953 : char **papszSiblingFiles = poOpenInfo->GetSiblingFiles(); 42 953 : if (papszSiblingFiles != nullptr) 43 : { 44 495 : bool bFoundCompatibleFile = false; 45 19248 : for (int i = 0; papszSiblingFiles[i] != nullptr; i++) 46 : { 47 18765 : int nLen = (int)strlen(papszSiblingFiles[i]); 48 18765 : if (nLen > 4 && papszSiblingFiles[i][nLen - 4] == '.' && 49 12822 : papszSiblingFiles[i][nLen - 1] == '1') 50 : { 51 12 : bFoundCompatibleFile = true; 52 12 : break; 53 : } 54 : } 55 495 : if (!bFoundCompatibleFile) 56 483 : return nullptr; 57 : } 58 : 59 470 : OGRTigerDataSource *poDS = new OGRTigerDataSource; 60 : 61 470 : if (!poDS->Open(poOpenInfo->pszFilename, TRUE)) 62 : { 63 470 : delete poDS; 64 470 : poDS = nullptr; 65 : } 66 : 67 470 : if (poDS != nullptr && poOpenInfo->eAccess == GA_Update) 68 : { 69 0 : CPLError(CE_Failure, CPLE_OpenFailed, 70 : "Tiger Driver doesn't support update."); 71 0 : delete poDS; 72 0 : poDS = nullptr; 73 : } 74 : 75 470 : return poDS; 76 : } 77 : 78 : /************************************************************************/ 79 : /* RegisterOGRTiger() */ 80 : /************************************************************************/ 81 : 82 1512 : void RegisterOGRTiger() 83 : 84 : { 85 1512 : if (GDALGetDriverByName("TIGER") != nullptr) 86 295 : return; 87 : 88 1217 : GDALDriver *poDriver = new GDALDriver(); 89 : 90 1217 : poDriver->SetDescription("TIGER"); 91 1217 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 92 1217 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "U.S. Census TIGER/Line"); 93 1217 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/tiger.html"); 94 1217 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 95 1217 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); 96 : 97 1217 : poDriver->pfnOpen = OGRTigerDriverOpen; 98 : 99 1217 : GetGDALDriverManager()->RegisterDriver(poDriver); 100 : }