LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/arrow - ogrfeatherwriterdataset.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 31 36 86.1 %
Date: 2024-05-13 13:33:37 Functions: 7 8 87.5 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  Feather Translator
       4             :  * Purpose:  Implements OGRFeatherDriver.
       5             :  * Author:   Even Rouault, <even.rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2022, Planet Labs
       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_feather.h"
      30             : 
      31             : #include "../arrow_common/ograrrowwriterlayer.hpp"
      32             : 
      33             : /************************************************************************/
      34             : /*                       OGRFeatherWriterDataset()                      */
      35             : /************************************************************************/
      36             : 
      37         138 : OGRFeatherWriterDataset::OGRFeatherWriterDataset(
      38             :     const char *pszFilename,
      39         138 :     const std::shared_ptr<arrow::io::OutputStream> &poOutputStream)
      40             :     : m_osFilename(pszFilename),
      41             :       m_poMemoryPool(arrow::MemoryPool::CreateDefault()),
      42         138 :       m_poOutputStream(poOutputStream)
      43             : {
      44         138 : }
      45             : 
      46             : /************************************************************************/
      47             : /*                           GetLayerCount()                            */
      48             : /************************************************************************/
      49             : 
      50         330 : int OGRFeatherWriterDataset::GetLayerCount()
      51             : {
      52         330 :     return m_poLayer ? 1 : 0;
      53             : }
      54             : 
      55             : /************************************************************************/
      56             : /*                             GetLayer()                               */
      57             : /************************************************************************/
      58             : 
      59         110 : OGRLayer *OGRFeatherWriterDataset::GetLayer(int idx)
      60             : {
      61         110 :     return idx == 0 ? m_poLayer.get() : nullptr;
      62             : }
      63             : 
      64             : /************************************************************************/
      65             : /*                         TestCapability()                             */
      66             : /************************************************************************/
      67             : 
      68         366 : int OGRFeatherWriterDataset::TestCapability(const char *pszCap)
      69             : {
      70         366 :     if (EQUAL(pszCap, ODsCCreateLayer))
      71         133 :         return m_poLayer == nullptr;
      72         233 :     if (EQUAL(pszCap, ODsCAddFieldDomain))
      73           6 :         return m_poLayer != nullptr;
      74         227 :     return false;
      75             : }
      76             : 
      77             : /************************************************************************/
      78             : /*                          ICreateLayer()                              */
      79             : /************************************************************************/
      80             : 
      81             : OGRLayer *
      82         145 : OGRFeatherWriterDataset::ICreateLayer(const char *pszName,
      83             :                                       const OGRGeomFieldDefn *poGeomFieldDefn,
      84             :                                       CSLConstList papszOptions)
      85             : {
      86         145 :     if (m_poLayer)
      87             :     {
      88           7 :         CPLError(CE_Failure, CPLE_NotSupported,
      89             :                  "Can write only one layer in a Feather file");
      90           7 :         return nullptr;
      91             :     }
      92             : 
      93         138 :     const auto eGType = poGeomFieldDefn ? poGeomFieldDefn->GetType() : wkbNone;
      94             :     const auto poSpatialRef =
      95         138 :         poGeomFieldDefn ? poGeomFieldDefn->GetSpatialRef() : nullptr;
      96             : 
      97         138 :     m_poLayer = std::make_unique<OGRFeatherWriterLayer>(
      98         138 :         this, m_poMemoryPool.get(), m_poOutputStream, pszName);
      99         138 :     if (!m_poLayer->SetOptions(m_osFilename, papszOptions, poSpatialRef,
     100             :                                eGType))
     101             :     {
     102           9 :         m_poLayer.reset();
     103           9 :         return nullptr;
     104             :     }
     105         129 :     return m_poLayer.get();
     106             : }
     107             : 
     108             : /************************************************************************/
     109             : /*                          AddFieldDomain()                            */
     110             : /************************************************************************/
     111             : 
     112           6 : bool OGRFeatherWriterDataset::AddFieldDomain(
     113             :     std::unique_ptr<OGRFieldDomain> &&domain, std::string &failureReason)
     114             : {
     115           6 :     if (m_poLayer == nullptr)
     116             :     {
     117           0 :         failureReason = "Layer must be created";
     118           0 :         return false;
     119             :     }
     120           6 :     return m_poLayer->AddFieldDomain(std::move(domain), failureReason);
     121             : }
     122             : 
     123             : /************************************************************************/
     124             : /*                          GetFieldDomainNames()                       */
     125             : /************************************************************************/
     126             : 
     127             : std::vector<std::string>
     128           0 : OGRFeatherWriterDataset::GetFieldDomainNames(CSLConstList) const
     129             : {
     130           0 :     return m_poLayer ? m_poLayer->GetFieldDomainNames()
     131           0 :                      : std::vector<std::string>();
     132             : }
     133             : 
     134             : /************************************************************************/
     135             : /*                          GetFieldDomain()                            */
     136             : /************************************************************************/
     137             : 
     138             : const OGRFieldDomain *
     139           9 : OGRFeatherWriterDataset::GetFieldDomain(const std::string &name) const
     140             : {
     141           9 :     return m_poLayer ? m_poLayer->GetFieldDomain(name) : nullptr;
     142             : }

Generated by: LCOV version 1.14