Ejemplo n.º 1
0
        static SocketConnection()
        {
            // validated styles for known OSes
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // zero-length receive works fine
                _bufferStyle = BufferStyle.UseZeroLengthBuffer;
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ||
                     RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                // zero-length receive is unreliable
                _bufferStyle = BufferStyle.UseSmallBuffer;
            }
            else
            {
                // default to "figure it out based on what happens"
                _bufferStyle = BufferStyle.Unknown;
            }

            if (_bufferStyle != BufferStyle.UseZeroLengthBuffer)
            {
                // we're going to need to use small buffers for awaiting input
                _smallBuffers = new MicroBufferPool(SmallBufferSize, ushort.MaxValue);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Computes the buffer of a point for a given buffer distance,
 /// using the given Cap Style for borders of the point.
 /// </summary>
 /// <param name="g">The point to buffer.</param>
 /// <param name="distance">The buffer distance.</param>        
 /// <param name="endCapStyle">Cap Style to use for compute buffer.</param>
 /// <returns> The buffer of the input point.</returns>
 public static IGeometry Buffer(IGeometry g, double distance, BufferStyle endCapStyle)
 {
     BufferOp gBuf = new BufferOp(g);
     gBuf.EndCapStyle = endCapStyle;
     IGeometry geomBuf = gBuf.GetResultGeometry(distance);
     return geomBuf;
 }
Ejemplo n.º 3
0
        static SocketConnection()
        {

            // validated styles for known OSes
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // zero-length receive works fine
                _bufferStyle = BufferStyle.UseZeroLengthBuffer;
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
                || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                // zero-length receive is unreliable
                _bufferStyle = BufferStyle.UseSmallBuffer;
            }
            else
            {
                // default to "figure it out based on what happens"
                _bufferStyle = BufferStyle.Unknown;
            }

            if (_bufferStyle != BufferStyle.UseZeroLengthBuffer)
            {
                // we're going to need to use small buffers for awaiting input
                _smallBuffers = new MicroBufferPool(SmallBufferSize, ushort.MaxValue);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Computes the buffer of a point for a given buffer distance,
        /// using the given Cap Style for borders of the point.
        /// </summary>
        /// <param name="g">The point to buffer.</param>
        /// <param name="distance">The buffer distance.</param>
        /// <param name="endCapStyle">Cap Style to use for compute buffer.</param>
        /// <returns> The buffer of the input point.</returns>
        public static IGeometry Buffer(IGeometry g, double distance, BufferStyle endCapStyle)
        {
            BufferOp gBuf = new BufferOp(g);

            gBuf.EndCapStyle = endCapStyle;
            IGeometry geomBuf = gBuf.GetResultGeometry(distance);

            return(geomBuf);
        }
Ejemplo n.º 5
0
        public static IGeometry Buffer(IGeometry g, double distance,
                                       int quadrantSegments,
                                       BufferStyle endCapStyle)
        {
            var bufOp = new BufferOp(g);

            bufOp.QuadrantSegments = quadrantSegments;
            bufOp.BufferStyle      = endCapStyle;
            var geomBuf = bufOp.GetResultGeometry(distance);

            return(geomBuf);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Generates a buffer, but also adds the newly created feature to the specified output featureset.
        /// This will also compare the field names of the input featureset with the destination featureset.
        /// If a column name exists in both places, it will copy those values to the destination featureset.
        /// </summary>
        /// <param name="self">The feature to calcualate the buffer for.</param>
        /// <param name="distance">The double distance to use for calculating the buffer</param>
        /// <param name="endCapStyle">The end cap style to use</param>
        /// <param name="destinationFeatureset">The output featureset to add this feature to and use
        /// as a reference for determining which data columns to copy.</param>
        /// <returns>The IFeature that represents the buffer feature.</returns>
        public static IFeature Buffer(this IFeature self, double distance, BufferStyle endCapStyle, IFeatureSet destinationFeatureset)
        {
            IFeature f = Buffer(self, distance, endCapStyle);

            destinationFeatureset.Features.Add(f);
            foreach (DataColumn dc in destinationFeatureset.DataTable.Columns)
            {
                if (self.DataRow[dc.ColumnName] != null)
                {
                    f.DataRow[dc.ColumnName] = self.DataRow[dc.ColumnName];
                }
            }
            return(f);
        }
Ejemplo n.º 7
0
        /// returns null if the caller should redo from start; returns
        /// a non-null result to preocess the data
        private async Task <ArraySegment <byte> > ReceiveInitialDataUnknownStrategyAsync(SocketAsyncEventArgs args)
        {
            // to prove that it works OK, we need (after a read):
            // - have seen return 0 and Available > 0
            // - have reen return <= 0 and Available == 0 and is true EOF
            //
            // if we've seen both, we can switch to the simpler approach;
            // until then, if we just see return 0 and Available > 0, well...
            // we're happy
            //
            // note: if we see return 0 and available == 0 and not EOF,
            // then we know that zero-length receive is not supported

            try
            {
                args.SetBuffer(_zeroLengthBuffer, 0, 0);
                // we'll do a receive and see what happens
                await Socket.ReceiveSignalAsync(args);
            }
            catch
            {
                // well, it didn't like that... switch to small buffers
                _bufferStyle = BufferStyle.UseSmallBuffer;
                return(default);
Ejemplo n.º 8
0
 /// <summary>
 /// Returns a buffer region around this <c>Geometry</c> having the given width.
 /// The buffer of a Geometry is the Minkowski sum or difference of the Geometry with a disc of radius <c>distance</c>.
 /// </summary>
 /// <param name="distance">
 /// The width of the buffer, interpreted according to the
 /// <c>PrecisionModel</c> of the <c>Geometry</c>.
 /// </param>
 /// <param name="endCapStyle">Cap Style to use for compute buffer.</param>
 /// <returns>
 /// All points whose distance from this <c>Geometry</c>
 /// are less than or equal to <c>distance</c>.
 /// </returns>
 public virtual IGeometry Buffer(double distance, BufferStyle endCapStyle)
 {
     return BufferOp.Buffer(this, distance, endCapStyle);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Returns a buffer region around this <c>Geometry</c> having the given
 /// width and with a specified number of segments used to approximate curves.
 /// The buffer of a Geometry is the Minkowski sum of the Geometry with
 /// a disc of radius <c>distance</c>.  Curves in the buffer polygon are
 /// approximated with line segments.  This method allows specifying the
 /// accuracy of that approximation.
 /// </summary>
 /// <param name="distance">
 /// The width of the buffer, interpreted according to the
 /// <c>PrecisionModel</c> of the <c>Geometry</c>.
 /// </param>
 /// <param name="quadrantSegments">The number of segments to use to approximate a quadrant of a circle.</param>
 /// <param name="endCapStyle">Cap Style to use for compute buffer.</param>
 /// <returns>
 /// All points whose distance from this <c>Geometry</c>
 /// are less than or equal to <c>distance</c>.
 /// </returns>
 public virtual IGeometry Buffer(double distance, int quadrantSegments, BufferStyle endCapStyle)
 {
     return BufferOp.Buffer(this, distance, quadrantSegments, endCapStyle);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Computes the buffer for a point for a given buffer distance
 /// and accuracy of approximation.
 /// </summary>
 /// <param name="g">The point to buffer.</param>
 /// <param name="distance">The buffer distance.</param>
 /// <param name="quadrantSegments">The number of segments used to approximate a quarter circle.</param>
 /// <param name="endCapStyle">Cap Style to use for compute buffer.</param>
 /// <returns>The buffer of the input point.</returns>
 public static IGeometry Buffer(IGeometry g, double distance, int quadrantSegments, BufferStyle endCapStyle)
 {
     BufferOp bufOp = new BufferOp(g);
     bufOp.EndCapStyle = endCapStyle;
     bufOp.QuadrantSegments = quadrantSegments;
     IGeometry geomBuf = bufOp.GetResultGeometry(distance);
     return geomBuf;
 }
Ejemplo n.º 11
0
        public Layer CreateBufferLayer(PointF[] moBufferPts, float BufferRadius, BufferStyle eBufferStyle, string BufferName)
        {
            int i;

            //*** BugFix 11 Feb 2006 Error on Double clicking on same point
            if (moBufferPts.Length > 1)
            {
                if (moBufferPts[moBufferPts.Length - 1].Equals(moBufferPts[moBufferPts.Length - 2]))
                {
                    // ERROR: Not supported in C#: ReDimStatement
                }
            }

            //*** BugFix 02 Feb 2006 If user double click on first point itself for line buffer then create point buffer
            if (eBufferStyle == BufferStyle.Line & moBufferPts.Length == 1)
                eBufferStyle = BufferStyle.Point;

            //*** Transform Buffer Points to Latitude and Longitude
            for (i = 0; i <= moBufferPts.Length - 1; i++)
            {
                moBufferPts[i] = PointToClient(moBufferPts[i]);
            }

            //*** Create buffer
            Shape TempShp = new Shape();
            Layer BufferLayer = new Layer();
            GraphicsPath TempGp = new GraphicsPath();

            PointF[] PolyPts;
            if (eBufferStyle == BufferStyle.Point)
            {
                //*** Point Buffer
                GraphicsPath LyrGp = new GraphicsPath();
                for (i = 0; i <= moBufferPts.Length - 1; i++)
                {
                    TempShp = new Shape();
                    TempShp.AreaId = BufferName + "_" + i + 1;
                    TempShp.AreaName = BufferName + "_" + i + 1;
                    TempShp.Centroid = moBufferPts[i];
                    PolyPts = GetPointBuffer(moBufferPts[i], BufferRadius);
                    TempShp.Parts.Add(PolyPts);
                    TempGp.Reset();
                    TempGp.AddPolygon(PolyPts);
                    TempShp.Extent = TempGp.GetBounds();
                    BufferLayer.Records.Add(TempShp.AreaId, TempShp);
                    LyrGp.AddPolygon(PolyPts);
                }
                BufferLayer.Extent = LyrGp.GetBounds();
                LyrGp.Dispose();
            }
            else
            {
                //*** Line Buffer
                TempShp.AreaId = BufferName;
                TempShp.AreaName = BufferName;
                TempShp.Centroid = moBufferPts[(int)moBufferPts.Length / 2];
                PolyPts = GetLineBuffer(moBufferPts, BufferRadius);
                TempShp.Parts.Add(PolyPts);
                TempGp.AddPolygon(PolyPts);
                TempShp.Extent = TempGp.GetBounds();
                BufferLayer.Extent = TempGp.GetBounds();
                BufferLayer.Records.Add(TempShp.AreaId, TempShp);
            }

            TempGp.Dispose();
            TempShp = null;

            BufferLayer.LayerType = ShapeType.PolygonBuffer;
            BufferLayer.FillColor = Color.FromArgb(40, 255, 0, 0);
            BufferLayer.BorderColor = Color.Transparent;

            return BufferLayer;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Generates a new feature from the buffer of this feature.  The DataRow of
 /// the new feature will be null.
 /// </summary>
 /// <param name="self">This feature</param>
 /// <param name="distance">The double distance</param>
 /// <param name="quadrantSegments">The number of segments to use to approximate a quadrant of a circle</param>
 /// <param name="endCapStyle">The end cap style to use</param>
 /// <returns>An IFeature representing the output from the buffer operation</returns>
 public static IFeature Buffer(this IFeature self, double distance, int quadrantSegments, BufferStyle endCapStyle)
 {
     IGeometry g = Geometry.FromBasicGeometry(self.BasicGeometry).Buffer(distance, quadrantSegments, endCapStyle);
     return new Feature(g);
 }
Ejemplo n.º 13
0
 public IGeometry Buffer(Double distance, BufferStyle endCapStyle)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Generates a new feature from the buffer of this feature.  The DataRow of
        /// the new feature will be null.
        /// </summary>
        /// <param name="self">This feature</param>
        /// <param name="distance">The double distance</param>
        /// <param name="quadrantSegments">The number of segments to use to approximate a quadrant of a circle</param>
        /// <param name="endCapStyle">The end cap style to use</param>
        /// <returns>An IFeature representing the output from the buffer operation</returns>
        public static IFeature Buffer(this IFeature self, double distance, int quadrantSegments, BufferStyle endCapStyle)
        {
            IGeometry g = Geometry.FromBasicGeometry(self.BasicGeometry).Buffer(distance, quadrantSegments, endCapStyle);

            return(new Feature(g));
        }
Ejemplo n.º 15
0
        /// returns null if the caller should redo from start; returns
        /// a non-null result to preocess the data
        private async Task<ArraySegment<byte>> ReceiveInitialDataUnknownStrategyAsync(SocketAsyncEventArgs args)
        {

            // to prove that it works OK, we need (after a read):
            // - have seen return 0 and Available > 0
            // - have reen return <= 0 and Available == 0 and is true EOF
            //
            // if we've seen both, we can switch to the simpler approach;
            // until then, if we just see return 0 and Available > 0, well...
            // we're happy
            //
            // note: if we see return 0 and available == 0 and not EOF,
            // then we know that zero-length receive is not supported

            try
            {
                args.SetBuffer(_zeroLengthBuffer, 0, 0);
                // we'll do a receive and see what happens
                await Socket.ReceiveSignalAsync(args);
            }
            catch
            {
                // well, it didn't like that... switch to small buffers
                _bufferStyle = BufferStyle.UseSmallBuffer;
                return default(ArraySegment<byte>);
            }
            if (args.SocketError != SocketError.Success)
            {   // let the calling code explode
                return new ArraySegment<byte>(_zeroLengthBuffer);
            }

            if (Socket.Available > 0)
            {
                _seenReceiveZeroWithAvailable = true;
                if (_seenReceiveZeroWithEOF)
                {
                    _bufferStyle = BufferStyle.UseZeroLengthBuffer;
                }
                // we'll let the calling method pull the data out
                return new ArraySegment<byte>(_zeroLengthBuffer);
            }

            // so now we need to detect if this is a genuine EOF; if it isn't,
            // that isn't conclusive, because could just be timing; but if it is: great
            var buffer = LeaseSmallBuffer();
            try
            {
                args.SetBuffer(buffer.Array, buffer.Offset, buffer.Count);
                // we'll do a receive and see what happens
                await Socket.ReceiveSignalAsync(args);

                if (args.SocketError != SocketError.Success)
                {   // we can't actually conclude  anything
                    RecycleSmallBuffer(ref buffer);
                    throw new SocketException((int)args.SocketError);
                }
                if (args.BytesTransferred <= 0)
                {
                    RecycleSmallBuffer(ref buffer);
                    _seenReceiveZeroWithEOF = true;
                    if (_seenReceiveZeroWithAvailable)
                    {
                        _bufferStyle = BufferStyle.UseZeroLengthBuffer;
                    }
                    // we'll let the calling method shut everything down
                    return new ArraySegment<byte>(_zeroLengthBuffer);
                }

                // otherwise, we got something that looked like an EOF from receive,
                // but which wasn't really; we'll have to do things the hard way :(
                _bufferStyle = BufferStyle.UseSmallBuffer;
                return buffer;
            }
            catch
            {
                // already recycled (or not) correctly in the success cases
                RecycleSmallBuffer(ref buffer);
                throw;
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Computes the buffer for a point for a given buffer distance
 /// and accuracy of approximation.
 /// </summary>
 /// <param name="g">The point to buffer.</param>
 /// <param name="distance">The buffer distance.</param>
 /// <param name="quadrantSegments">The number of segments used to approximate a quarter circle.</param>
 /// <param name="endCapStyle">Cap Style to use for compute buffer.</param>
 /// <returns>The buffer of the input point.</returns>
 public static IGeometry Buffer(IGeometry g, double distance, int quadrantSegments, BufferStyle endCapStyle)
 {
     var bufOp = new BufferOp(g) {EndCapStyle = endCapStyle, QuadrantSegments = quadrantSegments};
     var geomBuf = bufOp.GetResultGeometry(distance);
     return geomBuf;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Generates a buffer, but also adds the newly created feature to the specified output featureset.
 /// This will also compare the field names of the input featureset with the destination featureset.
 /// If a column name exists in both places, it will copy those values to the destination featureset.
 /// </summary>
 /// <param name="self">The feature to calcualate the buffer for.</param>
 /// <param name="distance">The double distance to use for calculating the buffer</param>
 /// <param name="quadrantSegments">The number of segments to use to approximate a quadrant of a circle</param>
 /// <param name="endCapStyle">The end cap style to use</param>
 /// <param name="destinationFeatureset">The output featureset to add this feature to and use
 /// as a reference for determining which data columns to copy.</param>
 /// <returns>The IFeature that represents the buffer feature.</returns>
 public static IFeature Buffer(this IFeature self, double distance, int quadrantSegments, BufferStyle endCapStyle, IFeatureSet destinationFeatureset)
 {
     IFeature f = Buffer(self, distance, quadrantSegments, endCapStyle);
     destinationFeatureset.Features.Add(f);
     foreach (DataColumn dc in destinationFeatureset.DataTable.Columns)
     {
         if (self.DataRow[dc.ColumnName] != null)
         {
             f.DataRow[dc.ColumnName] = self.DataRow[dc.ColumnName];
         }
     }
     return f;
 }
Ejemplo n.º 18
0
        /// returns null if the caller should redo from start; returns
        /// a non-null result to preocess the data
        private async Task <ArraySegment <byte> > ReceiveInitialDataUnknownStrategyAsync(SocketAsyncEventArgs args)
        {
            // to prove that it works OK, we need (after a read):
            // - have seen return 0 and Available > 0
            // - have reen return <= 0 and Available == 0 and is true EOF
            //
            // if we've seen both, we can switch to the simpler approach;
            // until then, if we just see return 0 and Available > 0, well...
            // we're happy
            //
            // note: if we see return 0 and available == 0 and not EOF,
            // then we know that zero-length receive is not supported

            try
            {
                args.SetBuffer(_zeroLengthBuffer, 0, 0);
                // we'll do a receive and see what happens
                await Socket.ReceiveSignalAsync(args);
            }
            catch
            {
                // well, it didn't like that... switch to small buffers
                _bufferStyle = BufferStyle.UseSmallBuffer;
                return(default(ArraySegment <byte>));
            }
            if (args.SocketError != SocketError.Success)
            {   // let the calling code explode
                return(new ArraySegment <byte>(_zeroLengthBuffer));
            }

            if (Socket.Available > 0)
            {
                _seenReceiveZeroWithAvailable = true;
                if (_seenReceiveZeroWithEOF)
                {
                    _bufferStyle = BufferStyle.UseZeroLengthBuffer;
                }
                // we'll let the calling method pull the data out
                return(new ArraySegment <byte>(_zeroLengthBuffer));
            }

            // so now we need to detect if this is a genuine EOF; if it isn't,
            // that isn't conclusive, because could just be timing; but if it is: great
            var buffer = LeaseSmallBuffer();

            try
            {
                args.SetBuffer(buffer.Array, buffer.Offset, buffer.Count);
                // we'll do a receive and see what happens
                await Socket.ReceiveSignalAsync(args);

                if (args.SocketError != SocketError.Success)
                {   // we can't actually conclude  anything
                    RecycleSmallBuffer(ref buffer);
                    throw new SocketException((int)args.SocketError);
                }
                if (args.BytesTransferred <= 0)
                {
                    RecycleSmallBuffer(ref buffer);
                    _seenReceiveZeroWithEOF = true;
                    if (_seenReceiveZeroWithAvailable)
                    {
                        _bufferStyle = BufferStyle.UseZeroLengthBuffer;
                    }
                    // we'll let the calling method shut everything down
                    return(new ArraySegment <byte>(_zeroLengthBuffer));
                }

                // otherwise, we got something that looked like an EOF from receive,
                // but which wasn't really; we'll have to do things the hard way :(
                _bufferStyle = BufferStyle.UseSmallBuffer;
                return(buffer);
            }
            catch
            {
                // already recycled (or not) correctly in the success cases
                RecycleSmallBuffer(ref buffer);
                throw;
            }
        }
Ejemplo n.º 19
0
 public IGeometry Buffer(double distance, BufferStyle endCapStyle)
 {
     return BufferOp.Buffer(this, distance, BufferParameters.DefaultQuadrantSegments, endCapStyle);
 }