3

Is there an efficient way to find points of type NetTopologySuite.Geometries.Point that are inside given polygon of type NetTopologySuite.Geometries.PointPolygon using .net core 2.2. I tried following the documentation below, but no luck: https://nettopologysuite.github.io/html/class_net_topology_suite_1_1_algorithm_1_1_locate_1_1_indexed_point_in_area_locator.html#ad28b305b77c52327b7787ca8016c0fd7.

grabhints
  • 680
  • 8
  • 23
Goran
  • 43
  • 1
  • 6

1 Answers1

3

For one against many predicate tests use the GeoAPI.Geometries.Prepared.IPreparedGeometry. You can create one using the NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory.

private IList<IPoint> Contains(IGeometry geom, IEnumerable<IPoint> points) {
    var prepGeom = new NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory().Prepare(geom);
    var res = new List<IPoint>();
    foreach(var point in points) {
        if (prepGeom.Contains(point)) res.Add(point);
    }
    return res;
}

See issue on GitHub

FObermaier
  • 832
  • 5
  • 12
  • There is also several options at the bottom of NetTopologySuite issue #264. https://github.com/NetTopologySuite/NetTopologySuite/issues/264 – MBentley Sep 10 '21 at 12:29