LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/osm - ogrosmdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 35 40 87.5 %
Date: 2024-05-07 17:03:27 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  Implements OGROSMDriver class.
       5             :  * Author:   Even Rouault, <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2012, 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_osm.h"
      30             : 
      31             : #include <cstring>
      32             : 
      33             : #include "cpl_conv.h"
      34             : #include "cpl_port.h"
      35             : #include "gdal.h"
      36             : #include "gdal_priv.h"
      37             : #include "ogr_core.h"
      38             : 
      39             : /* g++ -DHAVE_EXPAT -fPIC -g -Wall ogr/ogrsf_frmts/osm/ogrosmdriver.cpp
      40             :  * ogr/ogrsf_frmts/osm/ogrosmdatasource.cpp ogr/ogrsf_frmts/osm/ogrosmlayer.cpp
      41             :  * -Iport -Igcore -Iogr -Iogr/ogrsf_frmts/osm -Iogr/ogrsf_frmts/mitab
      42             :  * -Iogr/ogrsf_frmts -shared -o ogr_OSM.so -L. -lgdal */
      43             : 
      44             : /************************************************************************/
      45             : /*                      OGROSMDriverIdentify()                          */
      46             : /************************************************************************/
      47             : 
      48       42457 : static int OGROSMDriverIdentify(GDALOpenInfo *poOpenInfo)
      49             : 
      50             : {
      51       42457 :     if (poOpenInfo->fpL == nullptr || poOpenInfo->nHeaderBytes == 0)
      52       40233 :         return GDAL_IDENTIFY_FALSE;
      53             : 
      54        2224 :     if (strstr((const char *)poOpenInfo->pabyHeader, "<osm") != nullptr)
      55             :     {
      56          20 :         return GDAL_IDENTIFY_TRUE;
      57             :     }
      58             : 
      59        2204 :     const int nLimitI =
      60        2204 :         poOpenInfo->nHeaderBytes - static_cast<int>(strlen("OSMHeader"));
      61     5649370 :     for (int i = 0; i < nLimitI; i++)
      62             :     {
      63     5647210 :         if (memcmp(poOpenInfo->pabyHeader + i, "OSMHeader",
      64             :                    strlen("OSMHeader")) == 0)
      65             :         {
      66          42 :             return GDAL_IDENTIFY_TRUE;
      67             :         }
      68             :     }
      69             : 
      70        2162 :     return GDAL_IDENTIFY_FALSE;
      71             : }
      72             : 
      73             : /************************************************************************/
      74             : /*                                Open()                                */
      75             : /************************************************************************/
      76             : 
      77          31 : static GDALDataset *OGROSMDriverOpen(GDALOpenInfo *poOpenInfo)
      78             : 
      79             : {
      80          31 :     if (poOpenInfo->eAccess == GA_Update)
      81           0 :         return nullptr;
      82          31 :     if (OGROSMDriverIdentify(poOpenInfo) == FALSE)
      83           0 :         return nullptr;
      84             : 
      85          31 :     OGROSMDataSource *poDS = new OGROSMDataSource();
      86             : 
      87          31 :     if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->papszOpenOptions))
      88             :     {
      89           0 :         delete poDS;
      90           0 :         poDS = nullptr;
      91             :     }
      92             : 
      93          31 :     return poDS;
      94             : }
      95             : 
      96             : /************************************************************************/
      97             : /*                        RegisterOGROSM()                           */
      98             : /************************************************************************/
      99             : 
     100        1520 : void RegisterOGROSM()
     101             : {
     102        1520 :     if (!GDAL_CHECK_VERSION("OGR/OSM driver"))
     103           0 :         return;
     104             : 
     105        1520 :     if (GDALGetDriverByName("OSM") != nullptr)
     106         301 :         return;
     107             : 
     108        1219 :     GDALDriver *poDriver = new GDALDriver();
     109             : 
     110        1219 :     poDriver->SetDescription("OSM");
     111        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
     112        1219 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "OpenStreetMap XML and PBF");
     113        1219 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "osm pbf");
     114        1219 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/osm.html");
     115        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     116        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES");
     117        1219 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
     118             : 
     119        1219 :     poDriver->SetMetadataItem(
     120             :         GDAL_DMD_OPENOPTIONLIST,
     121             :         "<OpenOptionList>"
     122             :         "  <Option name='CONFIG_FILE' type='string' description='Configuration "
     123             :         "filename.'/>"
     124             :         "  <Option name='USE_CUSTOM_INDEXING' type='boolean' "
     125             :         "description='Whether to enable custom indexing.' default='YES'/>"
     126             :         "  <Option name='COMPRESS_NODES' type='boolean' description='Whether "
     127             :         "to compress nodes in temporary DB.' default='NO'/>"
     128             :         "  <Option name='MAX_TMPFILE_SIZE' type='int' description='Maximum "
     129             :         "size in MB of in-memory temporary file. If it exceeds that value, it "
     130             :         "will go to disk' default='100'/>"
     131             :         "  <Option name='INTERLEAVED_READING' type='boolean' "
     132             :         "description='Whether to enable interleaved reading.' default='NO'/>"
     133             :         "  <Option name='TAGS_FORMAT' type='string-select' "
     134             :         "description='Format for all_tags/other_tags fields.' default='HSTORE'>"
     135             :         "    <Value>HSTORE</Value>"
     136             :         "    <Value>JSON</Value>"
     137             :         "  </Option>"
     138        1219 :         "</OpenOptionList>");
     139             : 
     140        1219 :     poDriver->pfnOpen = OGROSMDriverOpen;
     141        1219 :     poDriver->pfnIdentify = OGROSMDriverIdentify;
     142             : 
     143        1219 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     144             : }

Generated by: LCOV version 1.14