Ejemplo n.º 1
0
        /// <inheritdoc />
        public IObservable <string> Get(Tile tile)
        {
            // TODO tile can cross more than one srtm cell: need load more.
            var prefix   = GetFileNamePrefix(tile.BoundingBox.Center());
            var filePath = Path.Combine(_elePath, prefix);

            if (_fileSystemService.Exists(filePath))
            {
                return(Observable.Return(filePath));
            }

            return(Download(prefix).Select(bytes =>
            {
                lock (_lock)
                {
                    if (!_fileSystemService.Exists(filePath))
                    {
                        _trace.Info(TraceCategory, "Unzipping {0} bytes", bytes.Length.ToString());
                        var hgtData = CompressionUtils.Unzip(bytes).Single().Value;
                        using (var stream = _fileSystemService.WriteStream(filePath))
                            stream.Write(hgtData, 0, hgtData.Length);
                    }
                }

                return filePath;
            }));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        protected override void WriteBytes(Stream stream, byte[] bytes)
        {
            _trace.Info(TraceCategory, "Unzipping {0} bytes", bytes.Length.ToString());
            var hgtData = CompressionUtils.Unzip(bytes).Single().Value;

            stream.Write(hgtData, 0, hgtData.Length);
        }
Ejemplo n.º 3
0
        private IObservable <Unit> Download(GeoCoordinate coordinate)
        {
            _trace.Info(TraceCategory, "downloading data for {0}", coordinate.ToString());
            return(_downloader.Download(coordinate).SelectMany(bytes =>
            {
                _trace.Info(TraceCategory, "downloaded {0} bytes", bytes.Length.ToString());
                _hgtData = CompressionUtils.Unzip(bytes).Single().Value;
                InitData((int)coordinate.Latitude, (int)coordinate.Longitude);
                // store data to disk
                var path = GetFilePath(_srtmLat, _srtmLon);
                _trace.Info(TraceCategory, "storing as {0}", path);
                using (var stream = _fileSystemService.WriteStream(path))
                    stream.Write(_hgtData, 0, _hgtData.Length);

                return Observable.Return <Unit>(Unit.Default);
            }));
        }