Skip to content

Commit 278f853

Browse files
authored
Remove json from esri reader headers (PDAL#4722)
* Remove private functions from stac reader header. * Move interface functions out of EsriReader. * Add missed file.
1 parent 96f610e commit 278f853

File tree

8 files changed

+174
-97
lines changed

8 files changed

+174
-97
lines changed

io/EsriReader.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,13 @@
3737

3838
#include <Eigen/Geometry>
3939

40-
4140
#include <pdal/util/Algorithm.hpp>
4241
#include <pdal/util/ThreadPool.hpp>
4342
#include <pdal/private/MathUtils.hpp>
4443
#include <pdal/private/SrsTransform.hpp>
4544

46-
47-
48-
4945
#include "private/esri/Obb.hpp"
46+
#include "private/esri/Interface.hpp"
5047
#include "lepcc/src/include/lepcc_types.h"
5148

5249
namespace pdal
@@ -124,7 +121,8 @@ class EsriReader::TileContents
124121
std::string m_error;
125122
};
126123

127-
EsriReader::EsriReader() : m_args(new Args)
124+
EsriReader::EsriReader(std::unique_ptr<Interface> interface) :
125+
m_interface(std::move(interface)), m_args(new Args)
128126
{}
129127

130128

@@ -154,8 +152,6 @@ void EsriReader::initialize(PointTableRef table)
154152
for (std::string& s : m_args->dimensions)
155153
s = Utils::toupper(s);
156154

157-
m_arbiter.reset(new arbiter::Arbiter());
158-
159155
//adjust filename string
160156
const std::string pre("i3s://");
161157
if (Utils::startsWith(m_filename, pre))
@@ -170,15 +166,15 @@ void EsriReader::initialize(PointTableRef table)
170166
//personalize for slpk or i3s
171167
try
172168
{
173-
m_info = initInfo();
169+
m_interface->initInfo();
174170
}
175171
catch (std::exception& e)
176172
{
177173
throwError(std::string("Failed to fetch info: ") + e.what());
178174
}
179175

180176
//create const for looking into
181-
const NL::json jsonBody = m_info;
177+
const NL::json jsonBody = m_interface->getInfo();
182178

183179
//find version
184180
if (jsonBody["store"].contains("version"))
@@ -215,7 +211,7 @@ void EsriReader::initialize(PointTableRef table)
215211
}
216212

217213
//create spatial reference objects
218-
NL::json wkid = m_info["spatialReference"]["wkid"];
214+
NL::json wkid = jsonBody["spatialReference"]["wkid"];
219215
int system(0);
220216
if (wkid.is_string())
221217
{
@@ -254,9 +250,10 @@ void EsriReader::addDimensions(PointLayoutPtr layout)
254250
{
255251
using namespace Dimension;
256252

257-
if (!m_info.contains("attributeStorageInfo"))
253+
const NL::json& jsonBody = m_interface->getInfo();
254+
if (!jsonBody.contains("attributeStorageInfo"))
258255
throwError("Attributes do not exist for this object");
259-
const NL::json& attributes = m_info["attributeStorageInfo"];
256+
const NL::json& attributes = jsonBody["attributeStorageInfo"];
260257

261258
layout->registerDims({Id::X, Id::Y, Id::Z});
262259

@@ -353,8 +350,8 @@ void EsriReader::ready(PointTableRef table)
353350
// actual page number, so we use the page size (m_nodeCap) as a factor from the page
354351
// index to get the proper filename for a page.
355352
int indexFactor = m_version >= Version("2.0") ? 1 : m_nodeCap;
356-
i3s::FetchFunction fetch = std::bind(&EsriReader::fetchJson, this, std::placeholders::_1);
357-
m_pageManager.reset(new PageManager(100, 4, indexFactor, fetch));
353+
m_pageManager.reset(new PageManager(100, 4, indexFactor,
354+
[this](std::string src) { return m_interface->fetchJson(src); }));
358355
PagePtr p = m_pageManager->getPage(0);
359356
traverseTree(p, 0);
360357
m_pool->await();
@@ -661,7 +658,7 @@ EsriReader::TileContents EsriReader::loadPath(const std::string& filepath)
661658
TileContents tile(filepath, m_extraDimCount);
662659

663660
const std::string geomUrl = filepath + "/geometries/";
664-
auto xyzFetch = fetchBinary(geomUrl, "0", ".bin.pccxyz");
661+
auto xyzFetch = m_interface->fetchBinary(geomUrl, "0", ".bin.pccxyz");
665662
tile.m_xyz = i3s::decompressXYZ(&xyzFetch);
666663

667664
size_t size = tile.m_xyz.size();
@@ -670,22 +667,22 @@ EsriReader::TileContents EsriReader::loadPath(const std::string& filepath)
670667
{
671668
if (dim.name == "RGB")
672669
{
673-
auto data = fetchBinary(attrUrl, std::to_string(dim.key),
670+
auto data = m_interface->fetchBinary(attrUrl, std::to_string(dim.key),
674671
".bin.pccrgb");
675672
tile.m_rgb = i3s::decompressRGB(&data);
676673
tile.m_error = checkSize(dim, size, tile.m_rgb.size());
677674
}
678675
else if (dim.name == "INTENSITY")
679676
{
680-
auto data = fetchBinary(attrUrl, std::to_string(dim.key),
677+
auto data = m_interface->fetchBinary(attrUrl, std::to_string(dim.key),
681678
".bin.pccint");
682679
tile.m_intensity = i3s::decompressIntensity(&data);
683680
tile.m_error = checkSize(dim, size, tile.m_intensity.size());
684681
}
685682
else
686683
{
687684
std::vector<char>& data = tile.m_data[dim.pos];
688-
data = fetchBinary(attrUrl, std::to_string(dim.key), ".bin.gz");
685+
data = m_interface->fetchBinary(attrUrl, std::to_string(dim.key), ".bin.gz");
689686
tile.m_error = checkSize(dim, size * Dimension::size(dim.type),
690687
data.size());
691688
}

io/EsriReader.hpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,40 +48,30 @@
4848
#include "private/esri/EsriUtil.hpp"
4949
#include "private/esri/PageManager.hpp"
5050

51-
#include <nlohmann/json.hpp>
52-
5351
namespace pdal
5452
{
5553

56-
namespace arbiter
57-
{
58-
class Arbiter;
59-
}
60-
6154
class SrsTransform;
6255
class ThreadPool;
6356

57+
namespace i3s
58+
{
59+
struct Interface;
60+
};
61+
6462
class PDAL_EXPORT EsriReader : public Reader, public Streamable
6563
{
6664
public:
67-
EsriReader();
65+
EsriReader(std::unique_ptr<i3s::Interface> interface);
6866
~EsriReader();
6967

70-
protected:
71-
std::unique_ptr<arbiter::Arbiter> m_arbiter;
72-
73-
virtual NL::json initInfo() = 0;
74-
virtual std::vector<char> fetchBinary(std::string url, std::string attNum,
75-
std::string ext) const = 0;
76-
virtual std::string fetchJson(std::string) = 0;
77-
7868
private:
7969
struct Args;
8070
struct DimData;
8171
class TileContents;
8272

73+
std::unique_ptr<i3s::Interface> m_interface;
8374
std::unique_ptr<Args> m_args;
84-
NL::json m_info;
8575
int m_nodeCap;
8676
i3s::Version m_version;
8777
SpatialReference m_nativeSrs;

io/I3SReader.cpp

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <arbiter/arbiter.hpp>
3636
#include "I3SReader.hpp"
3737
#include "private/esri/EsriUtil.hpp"
38+
#include "private/esri/Interface.hpp"
3839

3940
#include <thread>
4041

@@ -52,52 +53,75 @@ static PluginInfo const i3sInfo
5253

5354
CREATE_STATIC_STAGE(I3SReader, i3sInfo)
5455

56+
namespace
57+
{
58+
59+
struct I3SInterface : public i3s::Interface
60+
{
61+
I3SInterface(const std::string& filename) : m_filename(filename)
62+
{}
63+
~I3SInterface() override
64+
{}
65+
66+
void initInfo() override;
67+
std::vector<char> fetchBinary(std::string url, std::string attNum,
68+
std::string ext) const override;
69+
std::string fetchJson(std::string) override;
70+
NL::json getInfo() override
71+
{ return m_info; }
72+
73+
NL::json m_info;
74+
const std::string& m_filename;
75+
arbiter::Arbiter m_arbiter;
76+
};
77+
78+
}
79+
5580
std::string I3SReader::getName() const { return i3sInfo.name; }
5681

57-
NL::json I3SReader::initInfo()
82+
I3SReader::I3SReader() : EsriReader(std::make_unique<I3SInterface>(m_filename))
83+
{}
84+
85+
void I3SInterface::initInfo()
5886
{
59-
NL::json info;
6087
try
6188
{
62-
std::string s = fetchJson("");
63-
info = i3s::parse(s, "Invalid JSON in file '" + m_filename + "'.");
89+
std::string s = m_arbiter.get(m_filename);
90+
NL::json info = i3s::parse(s, "Invalid JSON in file '" + m_filename + "'.");
6491

6592
if (info.empty())
66-
throwError(std::string("Incorrect Json object"));
93+
throw pdal_error(std::string("Incorrect Json object"));
6794
if (!info.contains("layers"))
68-
throwError(std::string("Json object contains no layers"));
95+
throw pdal_error(std::string("Json object contains no layers"));
6996

70-
info = info["layers"][0];
97+
m_info = info["layers"][0];
7198
}
7299
catch(i3s::EsriError& e)
73100
{
74-
throwError(std::string("Error parsing Json object: ") + e.what());
101+
throw pdal_error(std::string("Error parsing Json object: ") + e.what());
75102
}
76-
77-
m_filename += "/layers/0";
78-
return info;
79103
}
80104

81105

82-
std::string I3SReader::fetchJson(std::string filepath)
106+
std::string I3SInterface::fetchJson(std::string filepath)
83107
{
84-
filepath = m_filename + "/" + filepath;
85-
return m_arbiter->get(filepath);
108+
filepath = m_filename + "/layers/0/" + filepath;
109+
return m_arbiter.get(filepath);
86110
}
87111

88112

89-
std::vector<char> I3SReader::fetchBinary(std::string url,
113+
std::vector<char> I3SInterface::fetchBinary(std::string url,
90114
std::string attNum, std::string ext) const
91115
{
92116
const int NumRetries(5);
93117
int retry = 0;
94118

95-
std::string filepath = m_filename + "/" + url + attNum;
119+
std::string filepath = m_filename + "/layers/0/" + url + attNum;
96120
// For the REST I3S endpoint there are no file extensions.
97121
std::vector<char> result;
98122
while (true)
99123
{
100-
auto data = m_arbiter->tryGetBinary(filepath);
124+
auto data = m_arbiter.tryGetBinary(filepath);
101125
if (data)
102126
{
103127
result = std::move(*data);

io/I3SReader.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,9 @@ namespace pdal
4141
class PDAL_EXPORT I3SReader : public EsriReader
4242
{
4343
public:
44-
std::string getName() const override;
44+
I3SReader();
4545

46-
protected:
47-
virtual NL::json initInfo() override;
48-
virtual std::vector<char> fetchBinary(std::string url, std::string attNum,
49-
std::string ext) const override;
50-
virtual std::string fetchJson(std::string) override;
46+
std::string getName() const override;
5147
};
5248

5349
} // namespace pdal

0 commit comments

Comments
 (0)