I am creating a web application which shows what area is reachable in x amount of minutes inside of the Netherlands. To do this I want to intersect the polygon of the reachable area(s) with the one of the Netherlands.
I am displaying the polygons in the front-end using the leaflet library.
When computing the intersected polygon the polygon will not be a closed polygon of the intersected area, as I would expect.
The polygon of the Netherlands can be seen in this image (I only show the outline in the front-end):
The polygon of the reachable area can be seen in this image:
Then using this method, I form a polygon of the intersection between these polygons and return the coordinates to display in the front-en.
public Coordinate[] GetAreaInTheNetherlands(Point[] area, Coordinate[] border)
{
var geometryFactory = new GeometryFactory();
var borderPolygon = (Geometry)geometryFactory.CreatePolygon(border.Append(border.FirstOrDefault()).ToArray());
borderPolygon = borderPolygon.Buffer(0);
var areaPolygon = (Geometry)geometryFactory.CreatePolygon(area.Select(p => p.Coordinate).ToArray());
areaPolygon = areaPolygon.Buffer(0);
var intersect = areaPolygon.Intersection(borderPolygon);
intersect = intersect.Buffer(0);
return intersect.Coordinates;
}
in this context area is the reachable area, and border is the coordinates of the polygon of the Netherlands.
This will output in the following polygon:
It appear like the coordinates are correct, but maybe it should output a multi-polygon. Does anyone know how to do this or what else might be wrong in my code?