Skip to content
25 changes: 22 additions & 3 deletions src/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static std::unique_ptr<PipelineManager> pipeline(ParallelJobInfo *tile, const pd
else
{
// Reader can't do the filtering - do it with a filter
last = &manager->makeFilter( "filters.crop", *last, filter_opts);
last = &manager->makeFilter("filters.crop", *last, filter_opts);
}
}
if (!tile->filterExpression.empty())
Expand All @@ -162,6 +162,25 @@ void Clip::preparePipelines(std::vector<std::unique_ptr<PipelineManager>>& pipel
if (!loadPolygons(polygonFile, crop_opts, bbox))
return;

// equal combinedBox to the polygon bounds
// it is never necessary to read more from the input than this
BOX2D combinedBox = BOX2D(bbox);

// if filterBounds is set, combine it with the polygon bounds
if (!filterBounds.empty()) {
BOX2D filterBoundsBox;
std::string::size_type pos = 0;
filterBoundsBox.parse(filterBounds, pos);

// combinedBox is the intersection of the polygon bounds and the filter bounds
combinedBox.clip(filterBoundsBox);
}

if (!combinedBox.valid()) {
std::cerr << "clip bounds are empty or polygon and filter bounds do not overlap" << std::endl;
return;
}

if (isVpcFilename(inputFile))
{
// for /tmp/hello.vpc we will use /tmp/hello dir for all results
Expand All @@ -187,7 +206,7 @@ void Clip::preparePipelines(std::vector<std::unique_ptr<PipelineManager>>& pipel
std::cout << "using " << f.filename << std::endl;
}

ParallelJobInfo tile(ParallelJobInfo::FileBased, BOX2D(), filterExpression, filterBounds);
ParallelJobInfo tile(ParallelJobInfo::FileBased, BOX2D(), filterExpression, box_to_pdal_bounds(combinedBox));
tile.inputFilenames.push_back(f.filename);

tile.outputFilename = tileOutputFileName(outputFile, outputFormatVpc, outputSubdir, f.filename);
Expand All @@ -203,7 +222,7 @@ void Clip::preparePipelines(std::vector<std::unique_ptr<PipelineManager>>& pipel
{
isStreaming = false;
}
ParallelJobInfo tile(ParallelJobInfo::Single, BOX2D(), filterExpression, filterBounds);
ParallelJobInfo tile(ParallelJobInfo::Single, BOX2D(), filterExpression, box_to_pdal_bounds(combinedBox));
tile.inputFilenames.push_back(inputFile);
tile.outputFilename = outputFile;
pipelines.push_back(pipeline(&tile, crop_opts));
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/refs/heads/fix-remote-vpc/tests/data/stadium.vpc", utils.test_data_filepath("clipped-vpz-copc-files.copc.laz"), 66905),
("https://raw.githubusercontent.com/PDAL/wrench/f4b156c5081dd9a1d44fccfdb67f2c36e91e3566/tests/data/stadium.vpc", utils.test_data_filepath("clipped-vpz-copc-files.copc.laz"), 66905),
],
)
def test_clip_vpc(
Expand Down
Loading