public void MeasureBufferFactoryMappedPerformance() { const int iterations = 100; IEnumerable <IGeometry> sources = GetBufferInput(iterations); var input = new List <KeyValuePair <int, IGeometry> >(); int i = 0; foreach (IGeometry geometry in sources) { input.Add(new KeyValuePair <int, IGeometry>(i, geometry)); i++; } var factory = new BufferFactory(); var watch = new Stopwatch(); watch.Start(); var result = new List <KeyValuePair <int, IPolygon> >(factory.Buffer(input, 10)); watch.Stop(); Console.Out.WriteLine( "BufferFactory.Buffer(IEnumerable<KeyValuePair>): {0:N2} ms per geoemtry", (double)watch.ElapsedMilliseconds / iterations); Assert.AreEqual(iterations, result.Count, "Unexptected buffer output count"); }
public IPolygon CreateBuffer(double distance) { const bool forceCreation = false; IPolyline polyLine = GetPolyline(forceCreation); IPolyline bufferInput; if (GeometryUtils.HasNonLinearSegments(polyLine)) { if (polyLine.Length > 0) { bufferInput = GeometryFactory.Clone(polyLine); double xyTolerance = GeometryUtils.GetXyTolerance(polyLine); double xyResolution = GeometryUtils.GetXyResolution(polyLine); // note: buffering a non-linear segments always results in a densified buffer // apparently, the input is first densified with a large max. densify deviation // --> the input may not be contained in the buffer for small buffer distances // --> we need to densify the input ourselves to an appropriate max. deviation value double densifyDeviation = Math.Min(xyTolerance / 2, distance / 2); double minimumAllowedDeviation = xyResolution * 2.01; if (densifyDeviation < minimumAllowedDeviation) { densifyDeviation = minimumAllowedDeviation; } bufferInput.Densify(0, densifyDeviation); } else { bufferInput = GeometryFactory.CreateLine(polyLine.FromPoint, polyLine.ToPoint); } } else { bufferInput = polyLine; } using (var factory = new BufferFactory(explodeBuffers: false, densify: false)) { IPolygon result = null; foreach (IPolygon polygon in factory.Buffer(bufferInput, distance)) { Assert.Null(result, "more than 1 buffer geometry found"); result = polygon; } return(Assert.NotNull(result, "no buffer geometry found")); } }
public void MeasureBufferFactoryPerformance() { const int iterations = 100; IEnumerable <IGeometry> sources = GetBufferInput(iterations); var factory = new BufferFactory(); var watch = new Stopwatch(); watch.Start(); var result = new List <IPolygon>(factory.Buffer(sources, 10)); watch.Stop(); Console.Out.WriteLine("BufferFactory.Buffer(): {0:N2} ms per geoemtry", (double)watch.ElapsedMilliseconds / iterations); Assert.AreEqual(iterations, result.Count, "Unexptected buffer output count"); }
private IPolygon GetBufferedSmallRings([NotNull] IPolyline tooSmallRings, double bufferDistance) { IList <IPolygon> bufferOutput = _bufferFactory.Buffer(tooSmallRings, bufferDistance); Assert.AreEqual(1, bufferOutput.Count, "Unexpected buffer output (distance: {0})", bufferDistance); IPolygon result = bufferOutput[0]; if (!((IZAware)result).ZAware) { tooSmallRings.QueryEnvelope(_envelopeTemplateBuffer); ((IZAware)result).ZAware = true; ((IZ)result).SetConstantZ(_envelopeTemplateBuffer.ZMin); } return(result); }
public static IPolygon GetOutlineBuffer( [NotNull] IGeometry oneOrTwoDimensionalGeometry, double tolerance) { Assert.ArgumentCondition( oneOrTwoDimensionalGeometry.GeometryType == esriGeometryType.esriGeometryPolygon || oneOrTwoDimensionalGeometry.GeometryType == esriGeometryType.esriGeometryRing || oneOrTwoDimensionalGeometry.GeometryType == esriGeometryType.esriGeometryPolyline || oneOrTwoDimensionalGeometry.GeometryType == esriGeometryType.esriGeometryPath, "Input Geometry must be Polyline/Path or Polygon/Ring"); // TODO: for performance reduce the geometry to be buffered Stopwatch watch = _msg.DebugStartTiming("Buffering geometry with {0}...", tolerance); IGeometry sourcePolyline = oneOrTwoDimensionalGeometry as IPolyline ?? GeometryFactory.CreatePolyline( oneOrTwoDimensionalGeometry); const bool explodeBuffers = false; const bool densify = true; var bufferFactory = new BufferFactory(explodeBuffers, densify); IList <IPolygon> buffers = bufferFactory.Buffer(sourcePolyline, tolerance); // Expected: one (possibly multipart) polygon Assert.AreEqual(1, buffers.Count, "Unexpected number of buffer polygons"); IPolygon result = buffers[0]; if (sourcePolyline != oneOrTwoDimensionalGeometry) { Marshal.ReleaseComObject(sourcePolyline); } _msg.DebugStopTiming(watch, "Buffered"); return(result); }