Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: Carto Translator 4 : * Purpose: Implements OGRCARTODriver. 5 : * Author: Even Rouault, even dot rouault at spatialys.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2013, Even Rouault <even dot rouault at spatialys.com> 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_carto.h" 30 : #include "ogrcartodrivercore.h" 31 : 32 : // g++ -g -Wall -fPIC -shared -o ogr_CARTO.so -Iport -Igcore -Iogr 33 : // -Iogr/ogrsf_frmts -Iogr/ogrsf_frmts/carto ogr/ogrsf_frmts/carto/*.c* -L. 34 : // -lgdal -Iogr/ogrsf_frmts/geojson/libjson 35 : 36 : extern "C" void RegisterOGRCarto(); 37 : 38 : /************************************************************************/ 39 : /* OGRCartoDriverOpen() */ 40 : /************************************************************************/ 41 : 42 35 : static GDALDataset *OGRCartoDriverOpen(GDALOpenInfo *poOpenInfo) 43 : 44 : { 45 35 : if (!OGRCartoDriverIdentify(poOpenInfo)) 46 0 : return nullptr; 47 : 48 35 : OGRCARTODataSource *poDS = new OGRCARTODataSource(); 49 : 50 35 : if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->papszOpenOptions, 51 35 : poOpenInfo->eAccess == GA_Update)) 52 : { 53 17 : delete poDS; 54 17 : poDS = nullptr; 55 : } 56 : 57 35 : return poDS; 58 : } 59 : 60 : /************************************************************************/ 61 : /* OGRCartoDriverCreate() */ 62 : /************************************************************************/ 63 : 64 0 : static GDALDataset *OGRCartoDriverCreate(const char *pszName, 65 : CPL_UNUSED int nBands, 66 : CPL_UNUSED int nXSize, 67 : CPL_UNUSED int nYSize, 68 : CPL_UNUSED GDALDataType eDT, 69 : CPL_UNUSED char **papszOptions) 70 : 71 : { 72 0 : OGRCARTODataSource *poDS = new OGRCARTODataSource(); 73 : 74 0 : if (!poDS->Open(pszName, nullptr, TRUE)) 75 : { 76 0 : delete poDS; 77 0 : CPLError(CE_Failure, CPLE_AppDefined, 78 : "Carto driver doesn't support database creation."); 79 0 : return nullptr; 80 : } 81 : 82 0 : return poDS; 83 : } 84 : 85 : /************************************************************************/ 86 : /* RegisterOGRCARTO() */ 87 : /************************************************************************/ 88 : 89 1511 : void RegisterOGRCarto() 90 : 91 : { 92 1511 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 93 295 : return; 94 : 95 1216 : GDALDriver *poDriver = new GDALDriver(); 96 1216 : OGRCartoDriverSetCommonMetadata(poDriver); 97 1216 : poDriver->pfnOpen = OGRCartoDriverOpen; 98 1216 : poDriver->pfnCreate = OGRCartoDriverCreate; 99 : 100 1216 : GetGDALDriverManager()->RegisterDriver(poDriver); 101 : }