Skip to content

Commit 6c67d9c

Browse files
authored
Support /vsi content with readers.copc and readers.ept (PDAL#4741)
* defer to FileUtils to support /vsi content with readers.copc and readers.ept * add a /vsi test for readers.copc to test both code paths
1 parent d488926 commit 6c67d9c

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

io/private/connector/Connector.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,20 @@ std::vector<char> Connector::getBinary(uint64_t offset, int32_t size) const
180180
if (size <= 0)
181181
return std::vector<char>();
182182

183-
if (m_arbiter->isLocal(m_filename))
183+
if (Utils::startsWith(Utils::toupper(m_filename), "/VSI") || m_arbiter->isLocal(m_filename))
184184
{
185185
std::vector<char> buf(size);
186-
std::ifstream in(m_filename, std::ios::binary);
187-
if (in.fail() )
186+
std::istream* in = FileUtils::openFile(m_filename);
187+
if (in->fail() )
188188
{
189189
std::string message = "Unable to open '" + m_filename + "'.";
190190
if (!pdal::FileUtils::fileExists(m_filename))
191191
message += " File does not exist.";
192192
throw pdal_error(message);
193193
}
194-
in.seekg(offset);
195-
in.read(buf.data(), size);
194+
in->seekg(offset);
195+
in->read(buf.data(), size);
196+
delete in;
196197
return buf;
197198
}
198199
else

test/unit/io/CopcReaderTest.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,4 +698,48 @@ TEST(CopcReaderTest, boundedpreview)
698698
EXPECT_EQ(pdal::Bounds(bounds).to2d(), pdal::Bounds(bounds3d).to2d());
699699
}
700700

701+
void testURLs(const std::string& url, const BOX2D& bounds)
702+
{
703+
704+
CopcReader reader;
705+
{
706+
Options options;
707+
options.add("bounds", bounds);
708+
options.add("filename", url);
709+
options.add("resolution", 1000);
710+
711+
reader.setOptions(options);
712+
}
713+
714+
pdal::QuickInfo qi(reader.preview());
715+
EXPECT_EQ(61201, qi.m_pointCount);
716+
717+
pdal::BOX3D bounds3d = qi.m_bounds;
718+
EXPECT_EQ(pdal::Bounds(bounds).to2d(), pdal::Bounds(bounds3d).to2d());
719+
720+
}
721+
722+
723+
TEST(CopcReaderTest, vsi)
724+
{
725+
726+
/*
727+
"maxx": 639003.73,
728+
"maxy": 853534.37,
729+
"maxz": 615.26,
730+
"minx": 635579.2,
731+
"miny": 848887.49,
732+
"minz": 406.56
733+
*/
734+
735+
BOX2D bounds(635700,848900, 637000, 853300);
736+
std::string url( "https://github.com/PDAL/data/raw/refs/heads/main/autzen/autzen-classified.copc.laz");
737+
std::string vsi ("/vsicurl/"+url);
738+
739+
testURLs(url, bounds);
740+
testURLs(vsi, bounds);
741+
742+
743+
}
744+
701745
} // namespace pdal

0 commit comments

Comments
 (0)