Coverage Report

Created: 2026-08-14 09:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrsf_frmts/jsonfg/ogrjsonfgstreamingparser.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  OpenGIS Simple Features Reference Implementation
4
 * Purpose:  Implementation of OGC Features and Geometries JSON (JSON-FG)
5
 * Author:   Even Rouault <even.rouault at spatialys.com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2023, Even Rouault <even.rouault at spatialys.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#include "ogr_jsonfg.h"
14
15
/************************************************************************/
16
/*              OGRJSONFGStreamingParserGetMaxObjectSize()              */
17
/************************************************************************/
18
19
static size_t OGRJSONFGStreamingParserGetMaxObjectSize()
20
269
{
21
269
    const double dfTmp =
22
269
        CPLAtof(CPLGetConfigOption("OGR_JSONFG_MAX_OBJ_SIZE", "200"));
23
269
    return dfTmp > 0 ? static_cast<size_t>(dfTmp * 1024 * 1024) : 0;
24
269
}
25
26
/************************************************************************/
27
/*                      OGRJSONFGStreamingParser()                      */
28
/************************************************************************/
29
30
OGRJSONFGStreamingParser::OGRJSONFGStreamingParser(OGRJSONFGReader &oReader,
31
                                                   bool bFirstPass,
32
                                                   bool bHasTopLevelMeasures)
33
269
    : OGRJSONCollectionStreamingParser(
34
269
          bFirstPass, /*bStoreNativeData=*/false,
35
269
          OGRJSONFGStreamingParserGetMaxObjectSize()),
36
269
      m_oReader(oReader)
37
269
{
38
269
    m_bHasTopLevelMeasures = bHasTopLevelMeasures;
39
269
}
40
41
/************************************************************************/
42
/*                     ~OGRJSONFGStreamingParser()                      */
43
/************************************************************************/
44
45
269
OGRJSONFGStreamingParser::~OGRJSONFGStreamingParser() = default;
46
47
/************************************************************************/
48
/*                  OGRJSONFGStreamingParser::Clone()                   */
49
/************************************************************************/
50
51
std::unique_ptr<OGRJSONFGStreamingParser> OGRJSONFGStreamingParser::Clone()
52
0
{
53
0
    auto poRet = std::make_unique<OGRJSONFGStreamingParser>(
54
0
        m_oReader, IsFirstPass(), m_bHasTopLevelMeasures);
55
0
    poRet->m_osRequestedLayer = m_osRequestedLayer;
56
0
    return poRet;
57
0
}
58
59
/************************************************************************/
60
/*                           GetNextFeature()                           */
61
/************************************************************************/
62
63
std::pair<std::unique_ptr<OGRFeature>, OGRLayer *>
64
OGRJSONFGStreamingParser::GetNextFeature()
65
73
{
66
73
    if (m_nCurFeatureIdx < m_apoFeatures.size())
67
28
    {
68
28
        auto poRet = std::move(m_apoFeatures[m_nCurFeatureIdx]);
69
28
        m_apoFeatures[m_nCurFeatureIdx].first = nullptr;
70
28
        m_apoFeatures[m_nCurFeatureIdx].second = nullptr;
71
28
        m_nCurFeatureIdx++;
72
28
        return poRet;
73
28
    }
74
45
    m_nCurFeatureIdx = 0;
75
45
    m_apoFeatures.clear();
76
45
    return std::pair(nullptr, nullptr);
77
73
}
78
79
/************************************************************************/
80
/*                           AnalyzeFeature()                           */
81
/************************************************************************/
82
83
void OGRJSONFGStreamingParser::GotFeature(json_object *poObj, bool bFirstPass,
84
                                          const std::string & /*osJson*/)
85
365
{
86
365
    if (bFirstPass)
87
337
    {
88
337
        m_oReader.GenerateLayerDefnFromFeature(poObj);
89
337
    }
90
28
    else
91
28
    {
92
28
        OGRJSONFGStreamedLayer *poStreamedLayer = nullptr;
93
28
        auto poFeat = m_oReader.ReadFeature(poObj, m_osRequestedLayer.c_str(),
94
28
                                            m_bHasTopLevelMeasures, nullptr,
95
28
                                            &poStreamedLayer);
96
28
        if (poFeat)
97
28
        {
98
28
            CPLAssert(poStreamedLayer);
99
28
            m_apoFeatures.emplace_back(
100
28
                std::pair(std::move(poFeat), poStreamedLayer));
101
28
        }
102
28
    }
103
365
}
104
105
/************************************************************************/
106
/*                             TooComplex()                             */
107
/************************************************************************/
108
109
void OGRJSONFGStreamingParser::TooComplex()
110
0
{
111
0
    if (!ExceptionOccurred())
112
0
        EmitException("JSON object too complex/large. You may define the "
113
0
                      "OGR_JSONFG_MAX_OBJ_SIZE configuration option to "
114
0
                      "a value in megabytes to allow "
115
0
                      "for larger features, or 0 to remove any size limit.");
116
0
}