public IGeometry Union() { PointLocator locater = new PointLocator(); // use a set to eliminate duplicates, as required for union var exteriorCoords = new HashSet <Coordinate>(); foreach (IPoint point in PointExtracter.GetPoints(_pointGeom)) { Coordinate coord = point.Coordinate; Location loc = locater.Locate(coord, _otherGeom); if (loc == Location.Exterior) { exteriorCoords.Add(coord); } } // if no points are in exterior, return the other geom if (exteriorCoords.Count == 0) { return(_otherGeom); } // make a puntal geometry of appropriate size var exteriorCoordsArray = new Coordinate[exteriorCoords.Count]; exteriorCoords.CopyTo(exteriorCoordsArray, 0); Array.Sort(exteriorCoordsArray); ICoordinateSequence coords = _geomFact.CoordinateSequenceFactory.Create(exteriorCoordsArray); IGeometry ptComp = coords.Count == 1 ? (IGeometry)_geomFact.CreatePoint(coords.GetCoordinate(0)) : _geomFact.CreateMultiPoint(coords); // add point component to the other geometry return(GeometryCombiner.Combine(ptComp, _otherGeom)); }
private void Extract(IGeometry geom) { if (_geomFact == null) { _geomFact = geom.Factory; } /* * PolygonExtracter.getPolygons(geom, polygons); * LineStringExtracter.getLines(geom, lines); * PointExtracter.getPoints(geom, points); */ _polygons.AddRange(PolygonExtracter.GetPolygons(geom).Cast <IPolygon>()); _lines.AddRange(LinearComponentExtracter.GetLines(geom).Cast <ILineString>()); _points.AddRange(PointExtracter.GetPoints(geom).Cast <IPoint>()); }
/* * /// <summary> * /// * /// </summary> * /// <param name="locs"></param> * /// <param name="polys"></param> * /// <param name="locPtPoly"></param> * private void ComputeInside(IEnumerable<GeometryLocation> locs, IEnumerable<IPolygon> polys, GeometryLocation[] locPtPoly) * { * foreach (GeometryLocation loc in locs) * { * foreach (IPolygon poly in polys) * { * ComputeInside(loc, poly, locPtPoly); * if (_minDistance <= _terminateDistance) * return; * } * } * } * * /// <summary> * /// * /// </summary> * /// <param name="ptLoc"></param> * /// <param name="poly"></param> * /// <param name="locPtPoly"></param> * private void ComputeInside(GeometryLocation ptLoc, IPolygon poly, GeometryLocation[] locPtPoly) * { * Coordinate pt = ptLoc.Coordinate; * // if pt is not in exterior, distance to geom is 0 * if (Location.Exterior != _ptLocator.Locate(pt, poly)) * { * _minDistance = 0.0; * locPtPoly[0] = ptLoc; * GeometryLocation locPoly = new GeometryLocation(poly, pt); * locPtPoly[1] = locPoly; * return; * } * } * */ /// <summary> /// Computes distance between facets (lines and points) of input geometries. /// </summary> private void ComputeFacetDistance() { var locGeom = new GeometryLocation[2]; /* * Geometries are not wholely inside, so compute distance from lines and points * of one to lines and points of the other */ var lines0 = LinearComponentExtracter.GetLines(_geom[0]); var lines1 = LinearComponentExtracter.GetLines(_geom[1]); var pts0 = PointExtracter.GetPoints(_geom[0]); var pts1 = PointExtracter.GetPoints(_geom[1]); // exit whenever minDistance goes LE than terminateDistance ComputeMinDistanceLines(lines0, lines1, locGeom); UpdateMinDistance(locGeom, false); if (_minDistance <= _terminateDistance) { return; } locGeom[0] = null; locGeom[1] = null; ComputeMinDistanceLinesPoints(lines0, pts1, locGeom); UpdateMinDistance(locGeom, false); if (_minDistance <= _terminateDistance) { return; } locGeom[0] = null; locGeom[1] = null; ComputeMinDistanceLinesPoints(lines1, pts0, locGeom); UpdateMinDistance(locGeom, true); if (_minDistance <= _terminateDistance) { return; } locGeom[0] = null; locGeom[1] = null; ComputeMinDistancePoints(pts0, pts1, locGeom); UpdateMinDistance(locGeom, false); }
/// <summary> /// /// </summary> private void ComputeLineDistance() { GeometryLocation[] locGeom = new GeometryLocation[2]; /* * Geometries are not wholely inside, so compute distance from lines and points * of one to lines and points of the other */ IList lines0 = LinearComponentExtracter.GetLines(geom[0]); IList lines1 = LinearComponentExtracter.GetLines(geom[1]); IList pts0 = PointExtracter.GetPoints(geom[0]); IList pts1 = PointExtracter.GetPoints(geom[1]); // bail whenever minDistance goes to zero, since it can't get any less ComputeMinDistanceLines(lines0, lines1, locGeom); UpdateMinDistance(locGeom, false); if (minDistance <= terminateDistance) { return; } locGeom[0] = null; locGeom[1] = null; ComputeMinDistanceLinesPoints(lines0, pts1, locGeom); UpdateMinDistance(locGeom, false); if (minDistance <= terminateDistance) { return; } locGeom[0] = null; locGeom[1] = null; ComputeMinDistanceLinesPoints(lines1, pts0, locGeom); UpdateMinDistance(locGeom, true); if (minDistance <= terminateDistance) { return; } locGeom[0] = null; locGeom[1] = null; ComputeMinDistancePoints(pts0, pts1, locGeom); UpdateMinDistance(locGeom, false); }
private void LoadClick(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "NTS Geometry File|*.nts"; if (dialog.ShowDialog() == true) { using (var stream = dialog.OpenFile()) { var reader = new WKTReader(); try { var geom = reader.Read(stream); if (geom != null && !geom.IsEmpty) { var polygons = PolygonExtracter.GetPolygons(geom).OfType <Polygon>().Select(p => new DrawingPolygon(p)); foreach (var polygon in polygons) { polygon.Render(DrawingCanvas.DefaultPen); canvas.AddVisual(polygon); } var lineStrings = LineStringExtracter.GetLines(geom).OfType <LineString>().Select(p => new DrawingLineString(p)); foreach (var lineString in lineStrings) { lineString.Render(DrawingCanvas.DefaultPen); canvas.AddVisual(lineString); } var points = PointExtracter.GetPoints(geom).OfType <NetTopologySuite.Geometries.Point>() .Select(p => new DrawingPoint(new System.Windows.Point(p.X, p.Y))); foreach (var point in points) { point.Render(DrawingCanvas.DefaultPen); canvas.AddVisual(point); } } } catch { MessageBox.Show("Read failed! The file may have been corrupted!"); } } } }
public IGeometry Union() { PointLocator locater = new PointLocator(); // use a set to eliminate duplicates, as required for union #if Goletas HashSet <ICoordinate> exteriorCoords = new HashSet <ICoordinate>(); #else TreeSet exteriorCoords = new TreeSet(); #endif foreach (IPoint point in PointExtracter.GetPoints(_pointGeom)) { ICoordinate coord = point.Coordinate; Locations loc = locater.Locate(coord, _otherGeom); if (loc == Locations.Exterior) { exteriorCoords.Add(coord); } } // if no points are in exterior, return the other geom if (exteriorCoords.Count == 0) { return(_otherGeom); } // make a puntal geometry of appropriate size IGeometry ptComp = null; ICoordinateSequence coords = _geomFact.CoordinateSequenceFactory.Create(exteriorCoords.ToArray()); ptComp = coords.Count == 1 ? (IGeometry)_geomFact.CreatePoint(coords.GetCoordinate(0)) : _geomFact.CreateMultiPoint(coords); // add point component to the other geometry return(GeometryCombiner.Combine(ptComp, _otherGeom)); }