public static Geometry AddHole(Geometry polyGeom, Geometry hole) { var factory = polyGeom.Factory; // input checks if (!(polyGeom is Polygon polygon)) { throw new ArgumentException("A is not a polygon"); } if (!(hole is Polygon || hole is LineString)) { throw new ArgumentException("B must be a polygon or line"); } var holePts = ExtractLine(hole); if (!CoordinateArrays.IsRing(holePts)) { throw new ArgumentException("B is not a valid ring"); } var shell = (LinearRing)polygon.ExteriorRing.Copy(); var holes = new LinearRing[polygon.NumInteriorRings + 1]; for (int i = 0; i < polygon.NumInteriorRings; i++) { holes[i] = (LinearRing)polygon.GetInteriorRingN(i).Copy(); } holes[holes.Length - 1] = factory.CreateLinearRing(holePts); return(factory.CreatePolygon(shell, holes)); }
private void AddLineString(Geometry line) { if (_curveBuilder.IsLineOffsetEmpty(_distance)) { return; } var coord = CoordinateArrays.RemoveRepeatedPoints(line.Coordinates); /* * Rings (closed lines) are generated with a continuous curve, * with no end arcs. This produces better quality linework, * and avoids noding issues with arcs around almost-parallel end segments. * See JTS #523 and #518. * * Singled-sided buffers currently treat rings as if they are lines. */ if (CoordinateArrays.IsRing(coord) && !_curveBuilder.BufferParameters.IsSingleSided) { AddRingBothSides(coord, _distance); } else { var curve = _curveBuilder.GetLineCurve(coord, _distance); AddCurve(curve, Location.Exterior, Location.Interior); } }