Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: Interlis 2 Translator 4 : * Purpose: Implements OGRILI2Layer class. 5 : * Author: Markus Schnider, Sourcepole AG 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2004, Pirmin Kalberer, Sourcepole AG 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 "xercesc_headers.h" 30 : 31 : #include "cpl_conv.h" 32 : #include "ogr_ili2.h" 33 : #include "ogrsf_frmts.h" 34 : 35 : /************************************************************************/ 36 : /* Open() */ 37 : /************************************************************************/ 38 : 39 24547 : static GDALDataset *OGRILI2DriverOpen(GDALOpenInfo *poOpenInfo) 40 : 41 : { 42 24547 : if (poOpenInfo->eAccess == GA_Update || 43 23809 : (!poOpenInfo->bStatOK && 44 20336 : strchr(poOpenInfo->pszFilename, ',') == nullptr)) 45 21017 : return nullptr; 46 : 47 3530 : if (poOpenInfo->pabyHeader != nullptr) 48 : { 49 3017 : if (poOpenInfo->pabyHeader[0] != '<' || 50 178 : strstr((const char *)poOpenInfo->pabyHeader, 51 : "interlis.ch/INTERLIS2") == nullptr) 52 : { 53 3016 : return nullptr; 54 : } 55 : } 56 513 : else if (poOpenInfo->bIsDirectory) 57 453 : return nullptr; 58 : 59 61 : OGRILI2DataSource *poDS = new OGRILI2DataSource(); 60 : 61 61 : if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->papszOpenOptions, 62 65 : TRUE) || 63 4 : poDS->GetLayerCount() == 0) 64 : { 65 57 : delete poDS; 66 57 : return nullptr; 67 : } 68 : 69 4 : return poDS; 70 : } 71 : 72 : /************************************************************************/ 73 : /* Create() */ 74 : /************************************************************************/ 75 : 76 20 : static GDALDataset *OGRILI2DriverCreate(const char *pszName, int /* nBands */, 77 : int /* nXSize */, int /* nYSize */, 78 : GDALDataType /* eDT */, 79 : char **papszOptions) 80 : { 81 20 : OGRILI2DataSource *poDS = new OGRILI2DataSource(); 82 : 83 20 : if (!poDS->Create(pszName, papszOptions)) 84 : { 85 19 : delete poDS; 86 19 : return nullptr; 87 : } 88 : 89 1 : return poDS; 90 : } 91 : 92 : /************************************************************************/ 93 : /* RegisterOGRILI2() */ 94 : /************************************************************************/ 95 : 96 1512 : void RegisterOGRILI2() 97 : { 98 1512 : if (GDALGetDriverByName("Interlis 2") != nullptr) 99 295 : return; 100 : 101 1217 : GDALDriver *poDriver = new GDALDriver(); 102 : 103 1217 : poDriver->SetDescription("Interlis 2"); 104 1217 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 105 1217 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 106 1217 : poDriver->SetMetadataItem(GDAL_DCAP_CURVE_GEOMETRIES, "YES"); 107 1217 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 108 1217 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Interlis 2"); 109 1217 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/ili.html"); 110 1217 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "xtf xml ili"); 111 1217 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); 112 1217 : poDriver->SetMetadataItem( 113 : GDAL_DMD_OPENOPTIONLIST, 114 : "<OpenOptionList>" 115 : " <Option name='MODEL' type='string' description='Filename of the " 116 : "model in IlisMeta format (.imd)'/>" 117 1217 : "</OpenOptionList>"); 118 1217 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 119 : 120 1217 : poDriver->pfnOpen = OGRILI2DriverOpen; 121 1217 : poDriver->pfnCreate = OGRILI2DriverCreate; 122 : 123 1217 : GetGDALDriverManager()->RegisterDriver(poDriver); 124 : }