Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL/OGR Geography Network support (Geographic Network Model) 4 : * Purpose: GNM generic driver. 5 : * Authors: Mikhail Gusev (gusevmihs at gmail dot com) 6 : * Dmitry Baryshnikov, polimax@mail.ru 7 : * 8 : ****************************************************************************** 9 : * Copyright (c) 2014, Mikhail Gusev 10 : * Copyright (c) 2014-2015, NextGIS <info@nextgis.com> 11 : * 12 : * Permission is hereby granted, free of charge, to any person obtaining a 13 : * copy of this software and associated documentation files (the "Software"), 14 : * to deal in the Software without restriction, including without limitation 15 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 : * and/or sell copies of the Software, and to permit persons to whom the 17 : * Software is furnished to do so, subject to the following conditions: 18 : * 19 : * The above copyright notice and this permission notice shall be included 20 : * in all copies or substantial portions of the Software. 21 : * 22 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 23 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 : * DEALINGS IN THE SOFTWARE. 29 : ****************************************************************************/ 30 : 31 : #include "gnm_frmts.h" 32 : #include "gnm_priv.h" 33 : #include "gnmdb.h" 34 : 35 43115 : static int GNMDBDriverIdentify(GDALOpenInfo *poOpenInfo) 36 : 37 : { 38 43115 : if (!STARTS_WITH_CI(poOpenInfo->pszFilename, "PGB:") && 39 43115 : !STARTS_WITH_CI(poOpenInfo->pszFilename, "PG:")) 40 43115 : return FALSE; 41 0 : if ((poOpenInfo->nOpenFlags & GDAL_OF_GNM) == 0) 42 0 : return FALSE; 43 : 44 : // TODO: do we need to open datasource end check tables/layer exist? 45 : 46 0 : return TRUE; 47 : } 48 : 49 0 : static GDALDataset *GNMDBDriverOpen(GDALOpenInfo *poOpenInfo) 50 : 51 : { 52 0 : if (!GNMDBDriverIdentify(poOpenInfo)) 53 0 : return nullptr; 54 : 55 0 : GNMDatabaseNetwork *poFN = new GNMDatabaseNetwork(); 56 : 57 0 : if (poFN->Open(poOpenInfo) != CE_None) 58 : { 59 0 : delete poFN; 60 0 : poFN = nullptr; 61 : } 62 : 63 0 : return poFN; 64 : } 65 : 66 : static GDALDataset * 67 0 : GNMDBDriverCreate(const char *pszName, CPL_UNUSED int nBands, 68 : CPL_UNUSED int nXSize, CPL_UNUSED int nYSize, 69 : CPL_UNUSED GDALDataType eDT, char **papszOptions) 70 : { 71 0 : CPLAssert(nullptr != pszName); 72 0 : CPLDebug("GNM", "Attempt to create network at: %s", pszName); 73 : 74 0 : GNMDatabaseNetwork *poFN = new GNMDatabaseNetwork(); 75 : 76 0 : if (poFN->Create(pszName, papszOptions) != CE_None) 77 : { 78 0 : delete poFN; 79 0 : poFN = nullptr; 80 : } 81 : 82 0 : return poFN; 83 : } 84 : 85 0 : static CPLErr GNMDBDriverDelete(const char *pszDataSource) 86 : 87 : { 88 0 : GDALOpenInfo oOpenInfo(pszDataSource, GA_Update); 89 0 : GNMDatabaseNetwork *poFN = new GNMDatabaseNetwork(); 90 : 91 0 : if (poFN->Open(&oOpenInfo) != CE_None) 92 : { 93 0 : delete poFN; 94 0 : poFN = nullptr; 95 : 96 0 : return CE_Failure; 97 : } 98 : 99 0 : return poFN->Delete(); 100 : } 101 : 102 1595 : void RegisterGNMDatabase() 103 : { 104 1595 : if (GDALGetDriverByName("GNMDatabase") == nullptr) 105 : { 106 1293 : GDALDriver *poDriver = new GDALDriver(); 107 : 108 1293 : poDriver->SetDescription("GNMDatabase"); 109 1293 : poDriver->SetMetadataItem(GDAL_DCAP_GNM, "YES"); 110 1293 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, 111 : "Geographic Network generic DB based " 112 1293 : "model"); 113 : 114 1293 : poDriver->SetMetadataItem( 115 : GDAL_DMD_CREATIONOPTIONLIST, 116 : CPLSPrintf( 117 : "<CreationOptionList>" 118 : " <Option name='%s' type='string' description='The network " 119 : "name. Also it will be a folder name, so the limits for folder " 120 : "name distribute on network name'/>" 121 : " <Option name='%s' type='string' description='The network " 122 : "description. Any text describes the network'/>" 123 : " <Option name='%s' type='string' description='The network " 124 : "Spatial reference. All network features will reproject to " 125 : "this spatial reference. May be a WKT text or EPSG code'/>" 126 : " <Option name='FORMAT' type='string' description='The OGR " 127 : "format to store network data.'/>" 128 : " <Option name='OVERWRITE' type='boolean' " 129 : "description='Overwrite exist network or not' default='NO'/>" 130 : "</CreationOptionList>", 131 1293 : GNM_MD_NAME, GNM_MD_DESCR, GNM_MD_SRS)); 132 : 133 1293 : poDriver->SetMetadataItem(GDAL_DS_LAYER_CREATIONOPTIONLIST, 134 1293 : "<LayerCreationOptionList/>"); 135 1293 : poDriver->pfnOpen = GNMDBDriverOpen; 136 1293 : poDriver->pfnIdentify = GNMDBDriverIdentify; 137 1293 : poDriver->pfnCreate = GNMDBDriverCreate; 138 1293 : poDriver->pfnDelete = GNMDBDriverDelete; 139 : 140 1293 : GetGDALDriverManager()->RegisterDriver(poDriver); 141 : } 142 1595 : }