LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/geojson - ogrgeojsondriver.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 48 33 68.8 %
Date: 2012-04-28 Functions: 12 8 66.7 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrgeojsondriver.cpp 19489 2010-04-21 21:39:05Z rouault $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  Implementation of OGRGeoJSONDriver class (OGR GeoJSON Driver).
       6                 :  * Author:   Mateusz Loskot, mateusz@loskot.net
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2007, Mateusz Loskot
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : #include "ogr_geojson.h"
      30                 : #include <cpl_conv.h>
      31                 : 
      32                 : /************************************************************************/
      33                 : /*                           OGRGeoJSONDriver()                         */
      34                 : /************************************************************************/
      35                 : 
      36             389 : OGRGeoJSONDriver::OGRGeoJSONDriver()
      37                 : {
      38             389 : }
      39                 : 
      40                 : /************************************************************************/
      41                 : /*                          ~OGRGeoJSONDriver()                         */
      42                 : /************************************************************************/
      43                 : 
      44             369 : OGRGeoJSONDriver::~OGRGeoJSONDriver()
      45                 : {
      46             369 : }
      47                 : 
      48                 : /************************************************************************/
      49                 : /*                           GetName()                                  */
      50                 : /************************************************************************/
      51                 : 
      52           23729 : const char* OGRGeoJSONDriver::GetName()
      53                 : {
      54           23729 :     return "GeoJSON";
      55                 : }
      56                 : 
      57                 : /************************************************************************/
      58                 : /*                           Open()                                     */
      59                 : /************************************************************************/
      60                 : 
      61             850 : OGRDataSource* OGRGeoJSONDriver::Open( const char* pszName, int bUpdate )
      62                 : {
      63             850 :     return Open( pszName, bUpdate, NULL );
      64                 : }
      65                 : 
      66                 : /************************************************************************/
      67                 : /*                           Open()                                     */
      68                 : /************************************************************************/
      69                 : 
      70             850 : OGRDataSource* OGRGeoJSONDriver::Open( const char* pszName, int bUpdate,
      71                 :                                        char** papszOptions )
      72                 : {
      73                 :     UNREFERENCED_PARAM(papszOptions);
      74                 : 
      75             850 :     OGRGeoJSONDataSource* poDS = NULL;
      76             850 :     poDS = new OGRGeoJSONDataSource();
      77                 : 
      78                 : /* -------------------------------------------------------------------- */
      79                 : /*      Processing configuration options.                               */
      80                 : /* -------------------------------------------------------------------- */
      81                 : 
      82                 :     // TODO: Currently, options are based on environment variables.
      83                 :     //       This is workaround for not yet implemented Andrey's concept
      84                 :     //       described in document 'RFC 10: OGR Open Parameters'.
      85                 : 
      86             850 :     poDS->SetGeometryTranslation( OGRGeoJSONDataSource::eGeometryPreserve );
      87             850 :     const char* pszOpt = CPLGetConfigOption("GEOMETRY_AS_COLLECTION", NULL);
      88             850 :     if( NULL != pszOpt && EQUALN(pszOpt, "YES", 3) )
      89                 :     {
      90                 :             poDS->SetGeometryTranslation(
      91               0 :                 OGRGeoJSONDataSource::eGeometryAsCollection );
      92                 :     }
      93                 : 
      94             850 :     poDS->SetAttributesTranslation( OGRGeoJSONDataSource::eAtributesPreserve );
      95             850 :     pszOpt = CPLGetConfigOption("ATTRIBUTES_SKIP", NULL);
      96             850 :     if( NULL != pszOpt && EQUALN(pszOpt, "YES", 3) )
      97                 :     {
      98                 :         poDS->SetAttributesTranslation( 
      99               0 :             OGRGeoJSONDataSource::eAtributesSkip );
     100                 :     }
     101                 : 
     102                 : /* -------------------------------------------------------------------- */
     103                 : /*      Open and start processing GeoJSON datasoruce to OGR objects.    */
     104                 : /* -------------------------------------------------------------------- */
     105             850 :     if( !poDS->Open( pszName ) )
     106                 :     {
     107             768 :         delete poDS;
     108             768 :         poDS= NULL;
     109                 :     }
     110                 : 
     111             850 :     if( NULL != poDS && bUpdate )
     112                 :     {
     113                 :         CPLError( CE_Failure, CPLE_OpenFailed, 
     114               0 :                   "GeoJSON Driver doesn't support update." );
     115               0 :         delete poDS;
     116               0 :         return NULL;
     117                 :     }
     118                 : 
     119             850 :     return poDS;
     120                 : }
     121                 : 
     122                 : /************************************************************************/
     123                 : /*                           CreateDataSource()                         */
     124                 : /************************************************************************/
     125                 : 
     126              30 : OGRDataSource* OGRGeoJSONDriver::CreateDataSource( const char* pszName,
     127                 :                                                    char** papszOptions )
     128                 : {
     129              30 :     OGRGeoJSONDataSource* poDS = new OGRGeoJSONDataSource();
     130                 : 
     131              30 :     if( !poDS->Create( pszName, papszOptions ) )
     132                 :     {
     133               0 :         delete poDS;
     134               0 :         poDS = NULL;
     135                 :     }
     136                 : 
     137              30 :     return poDS;
     138                 : }
     139                 : 
     140                 : /************************************************************************/
     141                 : /*                           DeleteDataSource()                         */
     142                 : /************************************************************************/
     143                 : 
     144              12 : OGRErr OGRGeoJSONDriver::DeleteDataSource( const char* pszName )
     145                 : {
     146              12 :     if( VSIUnlink( pszName ) == 0 )
     147                 :     {
     148              12 :         return OGRERR_NONE;
     149                 :     }
     150                 :     
     151               0 :     CPLDebug( "GeoJSON", "Failed to delete \'%s\'", pszName);
     152                 : 
     153               0 :     return OGRERR_FAILURE;
     154                 : }
     155                 : 
     156                 : /************************************************************************/
     157                 : /*                           TestCapability()                           */
     158                 : /************************************************************************/
     159                 : 
     160               0 : int OGRGeoJSONDriver::TestCapability( const char* pszCap )
     161                 : {
     162               0 :     if( EQUAL( pszCap, ODrCCreateDataSource ) )
     163               0 :         return TRUE;
     164               0 :     else if( EQUAL(pszCap, ODrCDeleteDataSource) )
     165               0 :         return TRUE;
     166                 :     else
     167               0 :         return FALSE;
     168                 : }
     169                 : 
     170                 : /************************************************************************/
     171                 : /*                           RegisterOGRGeoJSON()                       */
     172                 : /************************************************************************/
     173                 : 
     174             389 : void RegisterOGRGeoJSON()
     175                 : {
     176             389 :     if( GDAL_CHECK_VERSION("OGR/GeoJSON driver") )
     177                 :     {
     178                 :         OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( 
     179             389 :             new OGRGeoJSONDriver );
     180                 :     }
     181             389 : }
     182                 : 

Generated by: LCOV version 1.7