示例#1
0
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            var geoCodingService = new GeoCodingService();

            var output = ComponentMetaData.OutputCollection["Output"];

            while (buffer.NextRow())
            {
                bool   modified = false;
                string address  = GetFullAddressFromBuffer(buffer);

                if (!string.IsNullOrWhiteSpace(address))
                {
                    var coordinates = geoCodingService.GeoCodeAddress(address);
                    if (coordinates != null)
                    {
                        if (_columnIndices.ContainsKey(LatitudeColumnName))
                        {
                            buffer.SetDecimal(_columnIndices[LatitudeColumnName], coordinates.Latitude);
                            modified = true;
                        }

                        if (_columnIndices.ContainsKey(LongitudeColumnName))
                        {
                            buffer.SetDecimal(_columnIndices[LongitudeColumnName], coordinates.Longitude);
                            modified = true;
                        }

                        if (_columnIndices.ContainsKey(LocationColumnName))
                        {
                            var pointTaggedText = new SqlChars(string.Format("POINT({0} {1})", coordinates.Longitude, coordinates.Latitude));
                            var sqlGeography    = SqlGeography.STPointFromText(pointTaggedText, 4326);

                            _tmpMemoryStream.SetLength(0);
                            sqlGeography.Write(_tmpBinaryWriter);
                            _tmpBinaryWriter.Flush();

                            buffer.AddBlobData(_columnIndices[LocationColumnName], _tmpMemoryStream.GetBuffer(), (int)_tmpMemoryStream.Length);
                            modified = true;
                        }
                    }
                }

                if (modified)
                {
                    // send buffered row to output
                    buffer.DirectRow(output.ID);
                }
            }
        }
        public override void ProcessInput(int inputID, PipelineBuffer buffer) {
            var geoCodingService = new GeoCodingService();

            var output = ComponentMetaData.OutputCollection["Output"];

            while (buffer.NextRow())
            {
                bool modified = false;
                string address = GetFullAddressFromBuffer(buffer);

                if (!string.IsNullOrWhiteSpace(address))
                {
                    var coordinates = geoCodingService.GeoCodeAddress(address);
                    if (coordinates != null)
                    {
                        if (_columnIndices.ContainsKey(LatitudeColumnName))
                        {
                            buffer.SetDecimal(_columnIndices[LatitudeColumnName], coordinates.Latitude);
                            modified = true;
                        }

                        if (_columnIndices.ContainsKey(LongitudeColumnName))
                        {
                            buffer.SetDecimal(_columnIndices[LongitudeColumnName], coordinates.Longitude);
                            modified = true;
                        }

                        if (_columnIndices.ContainsKey(LocationColumnName))
                        {
                            var pointTaggedText = new SqlChars(string.Format("POINT({0} {1})", coordinates.Longitude, coordinates.Latitude));
	                        var sqlGeography = SqlGeography.STPointFromText(pointTaggedText, 4326);
                            
                            _tmpMemoryStream.SetLength(0);
                            sqlGeography.Write(_tmpBinaryWriter);
                            _tmpBinaryWriter.Flush();

                            buffer.AddBlobData(_columnIndices[LocationColumnName], _tmpMemoryStream.GetBuffer(), (int)_tmpMemoryStream.Length);
                            modified = true;
                        }
                    }
                }

                if (modified)
                {
                    // send buffered row to output
                    buffer.DirectRow(output.ID);
                }
            }
        }