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-11-21 22:18:42 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             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "ogr_osm.h"
      14             : 
      15             : #include <cstring>
      16             : 
      17             : #include "cpl_conv.h"
      18             : #include "cpl_port.h"
      19             : #include "gdal.h"
      20             : #include "gdal_priv.h"
      21             : #include "ogr_core.h"
      22             : 
      23             : /* g++ -DHAVE_EXPAT -fPIC -g -Wall ogr/ogrsf_frmts/osm/ogrosmdriver.cpp
      24             :  * ogr/ogrsf_frmts/osm/ogrosmdatasource.cpp ogr/ogrsf_frmts/osm/ogrosmlayer.cpp
      25             :  * -Iport -Igcore -Iogr -Iogr/ogrsf_frmts/osm -Iogr/ogrsf_frmts/mitab
      26             :  * -Iogr/ogrsf_frmts -shared -o ogr_OSM.so -L. -lgdal */
      27             : 
      28             : /************************************************************************/
      29             : /*                      OGROSMDriverIdentify()                          */
      30             : /************************************************************************/
      31             : 
      32       45482 : static int OGROSMDriverIdentify(GDALOpenInfo *poOpenInfo)
      33             : 
      34             : {
      35       45482 :     if (poOpenInfo->fpL == nullptr || poOpenInfo->nHeaderBytes == 0)
      36       42925 :         return GDAL_IDENTIFY_FALSE;
      37             : 
      38        2557 :     if (strstr(reinterpret_cast<const char *>(poOpenInfo->pabyHeader),
      39             :                "<osm") != nullptr)
      40             :     {
      41          20 :         return GDAL_IDENTIFY_TRUE;
      42             :     }
      43             : 
      44        2537 :     const int nLimitI =
      45        2537 :         poOpenInfo->nHeaderBytes - static_cast<int>(strlen("OSMHeader"));
      46     6785870 :     for (int i = 0; i < nLimitI; i++)
      47             :     {
      48     6783380 :         if (memcmp(poOpenInfo->pabyHeader + i, "OSMHeader",
      49             :                    strlen("OSMHeader")) == 0)
      50             :         {
      51          44 :             return GDAL_IDENTIFY_TRUE;
      52             :         }
      53             :     }
      54             : 
      55        2493 :     return GDAL_IDENTIFY_FALSE;
      56             : }
      57             : 
      58             : /************************************************************************/
      59             : /*                                Open()                                */
      60             : /************************************************************************/
      61             : 
      62          32 : static GDALDataset *OGROSMDriverOpen(GDALOpenInfo *poOpenInfo)
      63             : 
      64             : {
      65          32 :     if (poOpenInfo->eAccess == GA_Update)
      66           0 :         return nullptr;
      67          32 :     if (OGROSMDriverIdentify(poOpenInfo) == FALSE)
      68           0 :         return nullptr;
      69             : 
      70          32 :     OGROSMDataSource *poDS = new OGROSMDataSource();
      71             : 
      72          32 :     if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->papszOpenOptions))
      73             :     {
      74           0 :         delete poDS;
      75           0 :         poDS = nullptr;
      76             :     }
      77             : 
      78          32 :     return poDS;
      79             : }
      80             : 
      81             : /************************************************************************/
      82             : /*                        RegisterOGROSM()                           */
      83             : /************************************************************************/
      84             : 
      85        1595 : void RegisterOGROSM()
      86             : {
      87        1595 :     if (!GDAL_CHECK_VERSION("OGR/OSM driver"))
      88           0 :         return;
      89             : 
      90        1595 :     if (GDALGetDriverByName("OSM") != nullptr)
      91         302 :         return;
      92             : 
      93        1293 :     GDALDriver *poDriver = new GDALDriver();
      94             : 
      95        1293 :     poDriver->SetDescription("OSM");
      96        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      97        1293 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "OpenStreetMap XML and PBF");
      98        1293 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "osm pbf");
      99        1293 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/osm.html");
     100        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     101        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES");
     102        1293 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
     103             : 
     104        1293 :     poDriver->SetMetadataItem(
     105             :         GDAL_DMD_OPENOPTIONLIST,
     106             :         "<OpenOptionList>"
     107             :         "  <Option name='CONFIG_FILE' type='string' description='Configuration "
     108             :         "filename.'/>"
     109             :         "  <Option name='USE_CUSTOM_INDEXING' type='boolean' "
     110             :         "description='Whether to enable custom indexing.' default='YES'/>"
     111             :         "  <Option name='COMPRESS_NODES' type='boolean' description='Whether "
     112             :         "to compress nodes in temporary DB.' default='NO'/>"
     113             :         "  <Option name='MAX_TMPFILE_SIZE' type='int' description='Maximum "
     114             :         "size in MB of in-memory temporary file. If it exceeds that value, it "
     115             :         "will go to disk' default='100'/>"
     116             :         "  <Option name='INTERLEAVED_READING' type='boolean' "
     117             :         "description='Whether to enable interleaved reading.' default='NO'/>"
     118             :         "  <Option name='TAGS_FORMAT' type='string-select' "
     119             :         "description='Format for all_tags/other_tags fields.' default='HSTORE'>"
     120             :         "    <Value>HSTORE</Value>"
     121             :         "    <Value>JSON</Value>"
     122             :         "  </Option>"
     123        1293 :         "</OpenOptionList>");
     124             : 
     125        1293 :     poDriver->pfnOpen = OGROSMDriverOpen;
     126        1293 :     poDriver->pfnIdentify = OGROSMDriverIdentify;
     127             : 
     128        1293 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     129             : }

Generated by: LCOV version 1.14