@@ -512,12 +512,14 @@ GridIntersection::subdividePolygon(const Grid<bounded_extent>& p_grid, const Geo
512512
513513 const geom::GeometryFactory& gfact = *g.getFactory ();
514514
515- Grid<infinite_extent> grid = make_infinite (p_grid, *g.getEnvelopeInternal ());
516- Matrix<std::unique_ptr<Cell>> cells (grid.getNumRows (), grid.getNumCols ());
515+ const auto cropped_grid = p_grid.crop (*g.getEnvelopeInternal ());
517516
518- traverse_polygons (cells, grid, g);
517+ const Grid<infinite_extent> cell_grid = make_infinite (cropped_grid, *g.getEnvelopeInternal ());
518+ Matrix<std::unique_ptr<Cell>> cells (cell_grid.getNumRows (), cell_grid.getNumCols ());
519519
520- const auto areas = collectAreas (cells, p_grid, g);
520+ traverse_polygons (cells, cell_grid, g);
521+
522+ const auto areas = collectAreas (cells, cropped_grid, g);
521523
522524 std::vector<std::unique_ptr<Geometry>> geoms;
523525 std::vector<std::unique_ptr<Geometry>> edge_geoms;
@@ -545,7 +547,7 @@ GridIntersection::subdividePolygon(const Grid<bounded_extent>& p_grid, const Geo
545547 }
546548 } else if (!edge && areas (i - 1 , j - 1 ) == fill_values<float >::INTERIOR) {
547549 // Cell is entirely covered by polygon
548- Envelope env = grid .getCellEnvelope (i, j);
550+ Envelope env = cell_grid .getCellEnvelope (i, j);
549551 geoms.push_back (gfact.toGeometry (&env));
550552 }
551553 }
0 commit comments