isciences / exactextract

Fast and accurate raster zonal statistics
Apache License 2.0
246 stars 32 forks source link

Incorrect result with very narrow polygon #26

Closed dbaston closed 2 years ago

dbaston commented 2 years ago

The following polygon/grid should produce coverage fractions that are very close to zero:

auto context = init_geos();

Grid<bounded_extent> ex{{487800, 492800, 5813800, 5818800}, 100, 100};

auto g = GEOSGeom_read_r(context, "POLYGON ((492094.9283999996 5816959.8553, 492374.9335527361 5816811.352641133, 492374.9335527363 5816811.352641133, 492094.9283999996 5816959.8553)))");

auto result = raster_cell_intersection(ex, context, g.get());

Instead it produces coverage fractions that are very close to one. It looks like this happens because the addition of calculated intersection points where the polygon crosses cell boundaries actually causes the polygon to flip from CCW to CW orientation.

dbaston commented 2 years ago

Candidate fix at https://gitlab.com/isciences/exactextract/-/merge_requests/32