diff --git a/src/clip.cpp b/src/clip.cpp index c6b1231..4e5d5af 100644 --- a/src/clip.cpp +++ b/src/clip.cpp @@ -137,7 +137,7 @@ static std::unique_ptr 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()) @@ -162,6 +162,25 @@ void Clip::preparePipelines(std::vector>& 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 @@ -187,7 +206,7 @@ void Clip::preparePipelines(std::vector>& 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); @@ -203,7 +222,7 @@ void Clip::preparePipelines(std::vector>& 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)); diff --git a/tests/test_clip.py b/tests/test_clip.py index 95fa8df..8e78f04 100644 --- a/tests/test_clip.py +++ b/tests/test_clip.py @@ -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(