Skip to content

Commit 53a5812

Browse files
committed
GEOSSubdivideByGrid: rename include_exterior argument, add test
1 parent c080c52 commit 53a5812

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

capi/geos_c.h.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ extern GEOSGeometry GEOS_DLL *GEOSSubdivideByGrid_r(
11751175
double xmin, double ymin,
11761176
double xmax, double ymax,
11771177
unsigned nx, unsigned ny,
1178-
int include_exterior);
1178+
int includeExterior);
11791179

11801180
/** \see GEOSGridIntersectionFractions */
11811181
extern int GEOS_DLL GEOSGridIntersectionFractions_r(
@@ -4040,7 +4040,7 @@ extern GEOSGeometry GEOS_DLL *GEOSClipByRect(
40404040
* \param ymax Upper bound of grid
40414041
* \param nx number of columns in grid
40424042
* \param ny number of rows in grid
4043-
* \param include_exterior whether to include portions of the
4043+
* \param includeExterior whether to include portions of the
40444044
input geometry that do not intersect the grid in
40454045
the returned result.
40464046
* \return A geometry collection whose components represent the
@@ -4055,7 +4055,7 @@ extern GEOSGeometry GEOS_DLL *GEOSSubdivideByGrid(
40554055
double xmin, double ymin,
40564056
double xmax, double ymax,
40574057
unsigned nx, unsigned ny,
4058-
int include_exterior);
4058+
int includeExterior);
40594059

40604060
/**
40614061
* Determine the fraction of each cell in a rectangular grid

src/operation/grid/GridIntersection.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,6 @@ GridIntersection::subdividePolygon(const Grid<bounded_extent>& p_grid, const Geo
569569
const geom::GeometryFactory& gfact = *g.getFactory();
570570

571571
const auto cropped_grid = p_grid.shrinkToFit(p_grid.getExtent().intersection(*g.getEnvelopeInternal()), false);
572-
//const auto cropped_grid = p_grid;
573572

574573
geom::Envelope gridExtent = *g.getEnvelopeInternal();
575574
gridExtent.expandBy(1);
@@ -619,6 +618,8 @@ GridIntersection::subdividePolygon(const Grid<bounded_extent>& p_grid, const Geo
619618
if (!edge_geoms.empty()) {
620619
auto edge_coll = gfact.createGeometryCollection(std::move(edge_geoms));
621620
geoms.push_back(overlayng::CoverageUnion::geomunion(edge_coll.get()));
621+
// Polygon generated here may have extra nodes that do not match adjacent polygons not processed through
622+
// subdividePolygon.
622623
}
623624

624625
return gfact.createGeometryCollection(std::move(geoms));

tests/unit/operation/grid/GridIntersectionTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,4 +976,26 @@ void object::test<52>()
976976
check_subdivided_polygon(*g, *subd);
977977
}
978978

979+
template<>
980+
template<>
981+
void object::test<53>() {
982+
set_test_name("includeExterior = true");
983+
984+
Envelope e(0, 10, 0, 10);
985+
Grid<bounded_extent> ext(e, 1, 1);
986+
987+
auto g = wkt_reader_.read("POLYGON ((9.5 9.5, 11 9.5, 11 11, 9.5 11, 9.5 9.5))");
988+
989+
auto subd = GridIntersection::subdividePolygon(ext, *g, true);
990+
991+
auto inside = wkt_reader_.read("POLYGON ((9.5 9.5, 10 9.5, 10 10, 9.5 10, 9.5 9.5))");
992+
auto outside = wkt_reader_.read("POLYGON ((9.5 10, 10 10, 10 9.5, 11 9.5, 11 11, 9.5 11, 9.5 10))");
993+
994+
ensure_equals(subd->getNumGeometries(), 2u);
995+
996+
// ensure_equals_geometry would fail here because the generated results have extra nodes at grid cell boundaries
997+
ensure(subd->getGeometryN(0)->equals(inside.get()));
998+
ensure(subd->getGeometryN(1)->equals(outside.get()));
999+
}
1000+
9791001
}

0 commit comments

Comments
 (0)