Skip to content
Merged
38 changes: 34 additions & 4 deletions src/vpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void geometryToJson(const Geometry &geom, const BOX3D &bbox, nlohmann::json &jso
}
}

bool VirtualPointCloud::write(std::string filename, bool forceAbsolutePaths)
bool VirtualPointCloud::write(std::string filename)
{
if (!isVpcFilename(filename))
filename += ".vpz";
Expand All @@ -319,6 +319,38 @@ bool VirtualPointCloud::write(std::string filename, bool forceAbsolutePaths)

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

bool forceAbsolutePaths = false;
for (const File &f : files)
{
fs::path fRelative = fs::relative(f.filename, outputPath);
if (fRelative.empty()) {
forceAbsolutePaths = true;
std::cerr << "Warning: failed to make filename relative to output path: "
<< f.filename
<< " ; using absolute paths in the output VPC file"
<< std::endl;
break;
}

for (size_t i = 0; i < f.overviewFilenames.size(); ++i)
{
std::string ovFilename(f.overviewFilenames[i]);
if (!pdal::Utils::isRemote(ovFilename))
{
const fs::path fRelative = fs::relative(ovFilename, outputPath);
if (fRelative.empty())
{
forceAbsolutePaths = true;
std::cerr << "Warning: failed to make overview filename relative to output path: "
<< ovFilename
<< " ; using absolute paths in the output VPC file"
<< std::endl;
break;
}
}
}
}

std::vector<nlohmann::ordered_json> jFiles;
for ( const File &f : files )
{
Expand Down Expand Up @@ -580,7 +612,6 @@ void buildVpc(std::vector<std::string> args)
int max_threads = -1;
bool verbose = false;
bool help = false;
bool forceAbsolutePaths = false;

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

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

try
{
Expand Down Expand Up @@ -970,7 +1000,7 @@ void buildVpc(std::vector<std::string> args)
}
}

vpc.write(outputFile, forceAbsolutePaths);
vpc.write(outputFile);

// TODO: for now hoping that all files have the same file type + CRS + point format + scaling
// "dataformat_id"
Expand Down
2 changes: 1 addition & 1 deletion src/vpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct VirtualPointCloud
void clear();
void dump();
bool read(std::string filename);
bool write(std::string filename, bool forceAbsolutePaths = false);
bool write(std::string filename);

point_count_t totalPoints() const;
BOX3D box3d() const;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_input_file_output_file(
(utils.test_data_filepath("data_copc.vpc"), utils.test_data_filepath("clipped-vpc-copc-files.copc.laz"), 66911),
(utils.test_data_filepath("data_copc.vpz"), utils.test_data_filepath("clipped-vpz-copc-files.vpc"), 66911),
(utils.test_data_filepath("data_copc.vpz"), utils.test_data_filepath("clipped-vpz-copc-files.copc.laz"), 66911),
("https://raw.githubusercontent.com/PDAL/wrench/f4b156c5081dd9a1d44fccfdb67f2c36e91e3566/tests/data/stadium.vpc", utils.test_data_filepath("clipped-vpz-copc-files.copc.laz"), 66905),
("https://raw.githubusercontent.com/PDAL/wrench/refs/heads/main/tests/data/stadium.vpc", utils.test_data_filepath("clipped-vpz-copc-files.copc.laz"), 66905),
],
)
def test_clip_vpc(
Expand Down
28 changes: 0 additions & 28 deletions tests/test_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,6 @@
import utils


def test_build_vpc_absolute_paths(laz_files):
"""Paths stored in VPC use absolute paths when --use-absolute-paths is passed."""
with tempfile.TemporaryDirectory() as tmp_dir:
output_vpc = Path(tmp_dir) / "out.vpc"

res = subprocess.run(
[
utils.pdal_wrench_path(),
"build_vpc",
"--use-absolute-paths",
f"--output={output_vpc.as_posix()}",
*laz_files,
],
check=True,
)

assert res.returncode == 0
assert output_vpc.exists()

data = json.loads(output_vpc.read_text())
assert data["type"] == "FeatureCollection"

for feature in data["features"]:
for asset in feature["assets"].values():
href = asset["href"]
assert Path(href).is_absolute(), f"Expected absolute path, got: {href}"


def test_build_vpc_relative_paths_default(laz_files):
"""Paths stored in VPC are relative by default (no --absolute-paths)."""
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down
Loading