Search code examples
javapoint-in-polygonopengis

Point in opengis Polygon


I have a given opengis-Polygon (org.opengis.geometry.coordinate.Polygon) and I need a method to determine whether a given point is within the area that that Polygon spans up. Up until now I used: polygon.getBoundary().getMbRegion().contains(point). That works fine as long as the polygon is not "tilted" because it checks the max and min latitudes and longitudes and compares them to the point's coordinates. polygon.getSurface() which I would use intuitively returns null for me and polygon.getBoundary() otherwise just gives me access to the points on the boundary of the polygon. Another thing I thought of trying was implementing the Ray casting algorithm. But to implement that I did not yet find the possibility to create rays in opengis/GeoTools.

Thanks for any answers in advance!


Solution

  • Alright for anyone who stumbles upon this problem again, I solved the issue by implementing the algorithm proposed in this answer.