Skip to content

Commit c19839e

Browse files
authored
Merge pull request #94 from PDAL/absolute-paths
Fix absolute paths detection
2 parents 39a090d + 78b87dd commit c19839e

4 files changed

Lines changed: 36 additions & 34 deletions

File tree

‎src/vpc.cpp‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void geometryToJson(const Geometry &geom, const BOX3D &bbox, nlohmann::json &jso
306306
}
307307
}
308308

309-
bool VirtualPointCloud::write(std::string filename, bool forceAbsolutePaths)
309+
bool VirtualPointCloud::write(std::string filename)
310310
{
311311
if (!isVpcFilename(filename))
312312
filename += ".vpz";
@@ -319,6 +319,38 @@ bool VirtualPointCloud::write(std::string filename, bool forceAbsolutePaths)
319319

320320
fs::path outputPath = fs::path(filenameAbsolute).parent_path();
321321

322+
bool forceAbsolutePaths = false;
323+
for (const File &f : files)
324+
{
325+
fs::path fRelative = fs::relative(f.filename, outputPath);
326+
if (fRelative.empty()) {
327+
forceAbsolutePaths = true;
328+
std::cerr << "Warning: failed to make filename relative to output path: "
329+
<< f.filename
330+
<< " ; using absolute paths in the output VPC file"
331+
<< std::endl;
332+
break;
333+
}
334+
335+
for (size_t i = 0; i < f.overviewFilenames.size(); ++i)
336+
{
337+
std::string ovFilename(f.overviewFilenames[i]);
338+
if (!pdal::Utils::isRemote(ovFilename))
339+
{
340+
const fs::path fRelative = fs::relative(ovFilename, outputPath);
341+
if (fRelative.empty())
342+
{
343+
forceAbsolutePaths = true;
344+
std::cerr << "Warning: failed to make overview filename relative to output path: "
345+
<< ovFilename
346+
<< " ; using absolute paths in the output VPC file"
347+
<< std::endl;
348+
break;
349+
}
350+
}
351+
}
352+
}
353+
322354
std::vector<nlohmann::ordered_json> jFiles;
323355
for ( const File &f : files )
324356
{
@@ -580,7 +612,6 @@ void buildVpc(std::vector<std::string> args)
580612
int max_threads = -1;
581613
bool verbose = false;
582614
bool help = false;
583-
bool forceAbsolutePaths = false;
584615

585616
ProgramArgs programArgs;
586617
programArgs.add("help,h", "Output command help.", help);
@@ -596,7 +627,6 @@ void buildVpc(std::vector<std::string> args)
596627

597628
pdal::Arg& argThreads = programArgs.add("threads", "Max number of concurrent threads for parallel runs", max_threads);
598629
programArgs.add("verbose", "Print extra debugging output", verbose);
599-
programArgs.add("use-absolute-paths", "Store absolute file paths instead of relative paths in the output VPC", forceAbsolutePaths);
600630

601631
try
602632
{
@@ -970,7 +1000,7 @@ void buildVpc(std::vector<std::string> args)
9701000
}
9711001
}
9721002

973-
vpc.write(outputFile, forceAbsolutePaths);
1003+
vpc.write(outputFile);
9741004

9751005
// TODO: for now hoping that all files have the same file type + CRS + point format + scaling
9761006
// "dataformat_id"

‎src/vpc.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct VirtualPointCloud
7878
void clear();
7979
void dump();
8080
bool read(std::string filename);
81-
bool write(std::string filename, bool forceAbsolutePaths = false);
81+
bool write(std::string filename);
8282

8383
point_count_t totalPoints() const;
8484
BOX3D box3d() const;

‎tests/test_clip.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_input_file_output_file(
5151
(utils.test_data_filepath("data_copc.vpc"), utils.test_data_filepath("clipped-vpc-copc-files.copc.laz"), 66911),
5252
(utils.test_data_filepath("data_copc.vpz"), utils.test_data_filepath("clipped-vpz-copc-files.vpc"), 66911),
5353
(utils.test_data_filepath("data_copc.vpz"), utils.test_data_filepath("clipped-vpz-copc-files.copc.laz"), 66911),
54-
("https://raw.githubusercontent.com/PDAL/wrench/f4b156c5081dd9a1d44fccfdb67f2c36e91e3566/tests/data/stadium.vpc", utils.test_data_filepath("clipped-vpz-copc-files.copc.laz"), 66905),
54+
("https://raw.githubusercontent.com/PDAL/wrench/refs/heads/main/tests/data/stadium.vpc", utils.test_data_filepath("clipped-vpz-copc-files.copc.laz"), 66905),
5555
],
5656
)
5757
def test_clip_vpc(

‎tests/test_vpc.py‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,6 @@
77
import utils
88

99

10-
def test_build_vpc_absolute_paths(laz_files):
11-
"""Paths stored in VPC use absolute paths when --use-absolute-paths is passed."""
12-
with tempfile.TemporaryDirectory() as tmp_dir:
13-
output_vpc = Path(tmp_dir) / "out.vpc"
14-
15-
res = subprocess.run(
16-
[
17-
utils.pdal_wrench_path(),
18-
"build_vpc",
19-
"--use-absolute-paths",
20-
f"--output={output_vpc.as_posix()}",
21-
*laz_files,
22-
],
23-
check=True,
24-
)
25-
26-
assert res.returncode == 0
27-
assert output_vpc.exists()
28-
29-
data = json.loads(output_vpc.read_text())
30-
assert data["type"] == "FeatureCollection"
31-
32-
for feature in data["features"]:
33-
for asset in feature["assets"].values():
34-
href = asset["href"]
35-
assert Path(href).is_absolute(), f"Expected absolute path, got: {href}"
36-
37-
3810
def test_build_vpc_relative_paths_default(laz_files):
3911
"""Paths stored in VPC are relative by default (no --absolute-paths)."""
4012
with tempfile.TemporaryDirectory() as tmp_dir:

0 commit comments

Comments
 (0)