using System; using GeoAPI.Geometries; using GisSharpBlog.NetTopologySuite.Geometries; namespace GisSharpBlog.NetTopologySuite.Algorithm { /// /// Computes a point in the interior of an point point. /// Algorithm: /// Find a point which is closest to the centroid of the point. /// public class InteriorPointPoint { private ICoordinate centroid; private double minDistance = Double.MaxValue; private ICoordinate interiorPoint = null; /// /// /// /// public InteriorPointPoint(IGeometry g) { centroid = g.Centroid.Coordinate; Add(g); } /// /// Tests the point(s) defined by a Geometry for the best inside point. /// If a Geometry is not of dimension 0 it is not tested. /// /// The point to add. private void Add(IGeometry geom) { if (geom is IPoint) Add(geom.Coordinate); else if (geom is IGeometryCollection) { IGeometryCollection gc = (IGeometryCollection) geom; foreach (IGeometry geometry in gc.Geometries) Add(geometry); } } /// /// /// /// private void Add(ICoordinate point) { double dist = point.Distance(centroid); if (dist < minDistance) { interiorPoint = new Coordinate(point); minDistance = dist; } } /// /// /// public ICoordinate InteriorPoint { get { return interiorPoint; } } } }