Skip to content

Commit

Permalink
Add support for EPT prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Jul 14, 2020
1 parent 9f13fa0 commit 22d5951
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
37 changes: 29 additions & 8 deletions io/EptReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,16 @@ void EptReader::initialize()
setForwards(headers, query);
m_connector.reset(new Connector(headers, query));

m_info.reset(new EptInfo(m_filename, *m_connector));
setSpatialReference(m_info->srs());
m_addons = Addon::load(*m_connector, m_args->m_addons);
try
{
m_info.reset(new EptInfo(m_filename, *m_connector));
setSpatialReference(m_info->srs());
m_addons = Addon::load(*m_connector, m_args->m_addons);
}
catch (const arbiter::ArbiterError& err)
{
throwError(err.what());
}

if (!m_args->m_ogr.is_null())
{
Expand Down Expand Up @@ -271,7 +278,15 @@ void EptReader::handleOriginQuery()
std::endl;

std::string filename = m_info->sourcesDir() + "list.json";
const NL::json sources(m_connector->getJson(filename));
NL::json sources;
try
{
sources = m_connector->getJson(filename);
}
catch (const arbiter::ArbiterError& err)
{
throwError(err.what());
}
log()->get(LogLevel::Debug) << "Fetched sources list" << std::endl;

if (!sources.is_array())
Expand Down Expand Up @@ -547,10 +562,16 @@ void EptReader::overlaps(Hierarchy& target, const NL::json& hier,
// hierarchy subtree corresponding to this root.
m_pool->add([this, &target, key]()
{
std::string filename =
m_info->hierarchyDir() + key.toString() + ".json";
const auto subRoot(m_connector->getJson(filename));
overlaps(target, subRoot, key);
try
{
std::string filename = m_info->hierarchyDir() + key.toString() + ".json";
const auto subRoot(m_connector->getJson(filename));
overlaps(target, subRoot, key);
}
catch (const arbiter::ArbiterError& err)
{
throwError(err.what());
}
});
}
else if (numPoints < 0)
Expand Down
6 changes: 6 additions & 0 deletions io/private/ept/EptInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ EptInfo::EptInfo(const std::string& info)
EptInfo::EptInfo(const std::string& filename, const Connector& connector) :
m_filename(filename)
{
if (Utils::startsWith(m_filename, "ept://"))
{
m_filename = m_filename.substr(6);
if (!Utils::endsWith(m_filename, "/ept.json"))
m_filename += "/ept.json";
}
m_info = connector.getJson(m_filename);
initialize();
}
Expand Down
39 changes: 6 additions & 33 deletions pdal/StageFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,6 @@
namespace pdal
{

namespace
{

const std::vector<std::string> protocols { "i3s" };

std::string getDriverProtocol(std::string filename)
{
const auto protocol = std::find_if(protocols.begin(), protocols.end(),
[&filename](std::string protocol)
{
const std::string search(protocol + "://");
return Utils::startsWith(filename, search);
});

if (protocol != protocols.end())
return *protocol;
return "";
}

}

/**
Find the default reader for a file.
Expand All @@ -74,16 +53,14 @@ std::string StageFactory::inferReaderDriver(const std::string& filename)
{
std::string ext;

if (Utils::endsWith(filename, "ept.json"))
if (Utils::endsWith(filename, "ept.json") || Utils::startsWith(filename, "ept://"))
return "readers.ept";
if (Utils::startsWith(filename, "i3s://"))
return "readers.i3s";

const std::string driverProtocol = getDriverProtocol(filename);
if (!driverProtocol.empty())
ext = "." + driverProtocol;
else
ext = FileUtils::extension(filename);
ext = FileUtils::extension(filename);
// Strip off '.' and make lowercase.
if (ext.length())
if (ext.length() > 1)
ext = Utils::tolower(ext.substr(1));

return PluginManager<Stage>::extensions().defaultReader(ext);
Expand All @@ -98,21 +75,17 @@ std::string StageFactory::inferReaderDriver(const std::string& filename)
*/
std::string StageFactory::inferWriterDriver(const std::string& filename)
{
const std::string driverProtocol = getDriverProtocol(filename);

std::string lFilename = Utils::tolower(filename);
if (lFilename == "devnull" || lFilename == "/dev/null")
return "writers.null";

std::string ext;
if (lFilename == "stdout")
ext = ".txt";
else if (!driverProtocol.empty())
ext = "." + driverProtocol;
else
ext = Utils::tolower(FileUtils::extension(lFilename));
// Strip off '.' and make lowercase.
if (ext.length())
if (ext.length() > 1)
ext = Utils::tolower(ext.substr(1));

return PluginManager<Stage>::extensions().defaultWriter(ext);
Expand Down
11 changes: 11 additions & 0 deletions test/unit/io/EptReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ namespace
-8242446, 4966706, 50);
}

TEST(EptReaderTest, protocol)
{
Options opts;
opts.add("filename", "ept://http://testfile");

EptReader reader;
reader.setOptions(opts);

EXPECT_THROW(reader.preview(), pdal_error);
}

TEST(EptReaderTest, inspect)
{
Options options;
Expand Down

0 comments on commit 22d5951

Please sign in to comment.