public void Buffer3() { var geometry = reader.Read( @"LINESTRING(1250.7665 446.9385,1137.8786 170.4488,1136.3666106287267 166.74557327980631,1139.485009866369 125.36515638486206,1137.8786 121.7019)"); Assert.IsNotNull(geometry); Assert.IsTrue(geometry.IsValid); BufferParameters parameters = new BufferParameters() { EndCapStyle = EndCapStyle.Round }; var curveBuilder = new OffsetCurveBuilder( geometry.PrecisionModel, parameters); var curveSetBuilder = new OffsetCurveSetBuilder(geometry, 5, curveBuilder); var bufferSegStrList = curveSetBuilder.GetCurves(); Assert.AreEqual(1, bufferSegStrList.Count); var segmentString = (NodedSegmentString)bufferSegStrList[0]; Assert.AreEqual(45, segmentString.Count); for (var i = 0; i < segmentString.Coordinates.Length; i++) { var coord = segmentString.Coordinates[i]; Debug.WriteLine(String.Format("{1:R} {2:R}", i, coord.X, coord.Y)); } }
public static IGeometry SingleSidedBufferCurve(IGeometry geom, double distance) { var bufParam = new BufferParameters(); bufParam.IsSingleSided = true; var ocb = new OffsetCurveBuilder( geom.Factory.PrecisionModel, bufParam ); var pts = ocb.GetLineCurve(geom.Coordinates, distance); var curve = geom.Factory.CreateLineString(pts); return(curve); }
private static IGeometry BuildCurveSet(IGeometry g, double dist, IBufferParameters bufParams) { // --- now construct curve var ocb = new OffsetCurveBuilder(g.Factory.PrecisionModel, bufParams); var ocsb = new OffsetCurveSetBuilder(g, dist, ocb); var curves = ocsb.GetCurves(); var lines = new List <IGeometry>(); foreach (var ss in curves) { var pts = ss.Coordinates; lines.Add(g.Factory.CreateLineString(pts)); } IGeometry curve = g.Factory.BuildGeometry(lines); return(curve); }
/// <summary> /// /// </summary> /// <param name="inputGeom"></param> /// <param name="distance"></param> /// <param name="curveBuilder"></param> public OffsetCurveSetBuilder(IGeometry inputGeom, double distance, OffsetCurveBuilder curveBuilder) { _inputGeom = inputGeom; _distance = distance; _curveBuilder = curveBuilder; }
/// <summary> /// /// </summary> /// <param name="g"></param> /// <param name="distance"></param> /// <returns></returns> public IGeometry Buffer(IGeometry g, double distance) { PrecisionModel precisionModel = workingPrecisionModel; if (precisionModel == null) precisionModel = new PrecisionModel(g.PrecisionModel); // factory must be the same as the one used by the input geomFact = g.Factory; OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, quadrantSegments); curveBuilder.EndCapStyle = endCapStyle; OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder); IList bufferSegStrList = curveSetBuilder.GetCurves(); // short-circuit test if (bufferSegStrList.Count <= 0) { IGeometry emptyGeom = geomFact.CreateGeometryCollection(new Geometry[0]); return emptyGeom; } ComputeNodedEdges(bufferSegStrList, precisionModel); graph = new PlanarGraph(new OverlayNodeFactory()); graph.AddEdges(edgeList.Edges); IList subgraphList = CreateSubgraphs(graph); PolygonBuilder polyBuilder = new PolygonBuilder(geomFact); BuildSubgraphs(subgraphList, polyBuilder); IList resultPolyList = polyBuilder.Polygons; IGeometry resultGeom = geomFact.BuildGeometry(resultPolyList); return resultGeom; }