LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/wfs - ogrwfsdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 35 36 97.2 %
Date: 2024-05-04 12:52:34 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  WFS Translator
       4             :  * Purpose:  Implements OGRWFSDriver.
       5             :  * Author:   Even Rouault, even dot rouault at spatialys.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2010, 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_wfs.h"
      30             : #include "cpl_conv.h"
      31             : 
      32             : // g++ -fPIC -g -Wall ogr/ogrsf_frmts/wfs/*.cpp -shared -o ogr_WFS.so -Iport
      33             : // -Igcore -Iogr -Iogr/ogrsf_frmts -Iogr/ogrsf_frmts/gml -Iogr/ogrsf_frmts/wfs
      34             : // -L. -lgdal
      35             : 
      36             : extern "C" void RegisterOGRWFS();
      37             : 
      38             : /************************************************************************/
      39             : /*                             Identify()                               */
      40             : /************************************************************************/
      41             : 
      42       42523 : static int OGRWFSDriverIdentify(GDALOpenInfo *poOpenInfo)
      43             : 
      44             : {
      45       42523 :     if (!STARTS_WITH_CI(poOpenInfo->pszFilename, "WFS:"))
      46             :     {
      47       42261 :         if (poOpenInfo->fpL == nullptr)
      48       40031 :             return FALSE;
      49        2230 :         if (!STARTS_WITH_CI((const char *)poOpenInfo->pabyHeader,
      50        2218 :                             "<OGRWFSDataSource>") &&
      51        2218 :             strstr((const char *)poOpenInfo->pabyHeader, "<WFS_Capabilities") ==
      52        2210 :                 nullptr &&
      53        2210 :             strstr((const char *)poOpenInfo->pabyHeader,
      54             :                    "<wfs:WFS_Capabilities") == nullptr)
      55             :         {
      56        2210 :             return FALSE;
      57             :         }
      58             :     }
      59         282 :     return TRUE;
      60             : }
      61             : 
      62             : /************************************************************************/
      63             : /*                                Open()                                */
      64             : /************************************************************************/
      65             : 
      66         141 : static GDALDataset *OGRWFSDriverOpen(GDALOpenInfo *poOpenInfo)
      67             : 
      68             : {
      69         141 :     if (!OGRWFSDriverIdentify(poOpenInfo))
      70           0 :         return nullptr;
      71             : 
      72         141 :     OGRWFSDataSource *poDS = new OGRWFSDataSource();
      73             : 
      74         141 :     if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->eAccess == GA_Update,
      75             :                     poOpenInfo->papszOpenOptions))
      76             :     {
      77          11 :         delete poDS;
      78          11 :         poDS = nullptr;
      79             :     }
      80             : 
      81         141 :     return poDS;
      82             : }
      83             : 
      84             : /************************************************************************/
      85             : /*                           RegisterOGRWFS()                           */
      86             : /************************************************************************/
      87             : 
      88        1520 : void RegisterOGRWFS()
      89             : 
      90             : {
      91        1520 :     if (GDALGetDriverByName("WFS") != nullptr)
      92         301 :         return;
      93             : 
      94        1219 :     GDALDriver *poDriver = new GDALDriver();
      95             : 
      96        1219 :     poDriver->SetDescription("WFS");
      97        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      98        1219 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME,
      99        1219 :                               "OGC WFS (Web Feature Service)");
     100        1219 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/wfs.html");
     101             : 
     102        1219 :     poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "WFS:");
     103             : 
     104        1219 :     poDriver->SetMetadataItem(
     105             :         GDAL_DMD_OPENOPTIONLIST,
     106             :         "<OpenOptionList>"
     107             :         "  <Option name='URL' type='string' description='URL to the WFS server "
     108             :         "endpoint' required='true'/>"
     109             :         "  <Option name='TRUST_CAPABILITIES_BOUNDS' type='boolean' "
     110             :         "description='Whether to trust layer bounds declared in "
     111             :         "GetCapabilities response' default='NO'/>"
     112             :         "  <Option name='EMPTY_AS_NULL' type='boolean' description='Force "
     113             :         "empty fields to be reported as NULL. Set to NO so that not-nullable "
     114             :         "fields can be exposed' default='YES'/>"
     115             :         "  <Option name='INVERT_AXIS_ORDER_IF_LAT_LONG' type='boolean' "
     116             :         "description='Whether to present SRS and coordinate ordering in "
     117             :         "traditional GIS order' default='YES'/>"
     118             :         "  <Option name='CONSIDER_EPSG_AS_URN' type='string-select' "
     119             :         "description='Whether to consider srsName like EPSG:XXXX as respecting "
     120             :         "EPSG axis order' default='AUTO'>"
     121             :         "    <Value>AUTO</Value>"
     122             :         "    <Value>YES</Value>"
     123             :         "    <Value>NO</Value>"
     124             :         "  </Option>"
     125             :         "  <Option name='EXPOSE_GML_ID' type='boolean' description='Whether to "
     126             :         "make feature gml:id as a gml_id attribute.' default='YES'/>"
     127        1219 :         "</OpenOptionList>");
     128             : 
     129        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     130        1219 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
     131             : 
     132        1219 :     poDriver->pfnIdentify = OGRWFSDriverIdentify;
     133        1219 :     poDriver->pfnOpen = OGRWFSDriverOpen;
     134             : 
     135        1219 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     136             : }

Generated by: LCOV version 1.14