public static IPoint Calculate(IGeometry geom) { double bufferAmt = -0.001, inc = -.0002, stopper = 0; IGeometry prevBuffer = null, buffer = geom; BufferBuilder bldr = new BufferBuilder(); bldr.EndCapStyle = BufferStyle.CapRound; while (!IsAllCW(buffer)) { buffer = bldr.Buffer(geom, bufferAmt); if (stopper++ > 300) break; prevBuffer = buffer; bufferAmt += inc; } IPoint labelPoint; if (buffer is IGeometryCollection) // It is empty. labelPoint = GetPoint(prevBuffer); else labelPoint = GetPoint(buffer); // Should never happen but just in case we need to have some point. if (labelPoint == null) return geom.Centroid; else return labelPoint; }
/// <summary> /// /// </summary> /// <param name="precisionDigits"></param> private void BufferFixedPrecision(int precisionDigits) { double sizeBasedScaleFactor = PrecisionScaleFactor(_argGeom, _distance, precisionDigits); PrecisionModel fixedPm = new PrecisionModel(sizeBasedScaleFactor); // don't change the precision model of the Geometry, just reduce the precision SimpleGeometryPrecisionReducer reducer = new SimpleGeometryPrecisionReducer(fixedPm); IGeometry reducedGeom = reducer.Reduce(_argGeom); BufferBuilder bufBuilder = new BufferBuilder(); bufBuilder.WorkingPrecisionModel = fixedPm; bufBuilder.QuadrantSegments = _quadrantSegments; // this may throw an exception, if robustness errors are encountered _resultGeometry = bufBuilder.Buffer(reducedGeom, _distance); }
/// <summary> /// /// </summary> private void BufferOriginalPrecision() { try { BufferBuilder bufBuilder = new BufferBuilder(); bufBuilder.QuadrantSegments = _quadrantSegments; bufBuilder.EndCapStyle = _endCapStyle; _resultGeometry = bufBuilder.Buffer(_argGeom, _distance); } catch (TopologyException ex) { _saveException = ex; // don't propagate the exception - it will be detected by fact that resultGeometry is null } }