Exemplo n.º 1
0
 protected override byte[] LoadHgtDataFromFile(HgtCellCoords coords, string filePath)
 {
     using (var fileStream = File.Open(filePath,FileMode.Open,FileAccess.Read,FileShare.Read))
     {
         return LoadHgtDataFromStream(fileStream);
     }
 }
Exemplo n.º 2
0
 protected override async Task<byte[]> LoadHgtDataFromFileAsync(HgtCellCoords coords, string filePath)
 {
     using (var fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         return await LoadHgtDataFromStreamAsync(fileStream);
     }
 }
Exemplo n.º 3
0
 private IHgtDataCell buildCellFor(HgtCellCoords coords)
 {
     try
     {
         return _cellFactory.GetCellFor(coords);
     }
     catch (HgtFileException)
     {
         return HgtDataCellInvalid.Invalid;
     }
 }
Exemplo n.º 4
0
        protected override async Task<byte[]> LoadHgtDataFromFileAsync(HgtCellCoords coords, string filePath)
        {
            using (var zipArchive = ZipFile.OpenRead(filePath))
            {
                var entry = zipArchive.Entries.Single();

                long length = entry.Length;
                if (!HgtUtils.IsDataLengthValid(length))
                    throw new HgtFileInvalidException(coords, string.Format("Invalid length - {0} bytes", length));

                using (var zipStream = entry.Open())
                {
                    return await LoadHgtDataFromStreamAsync(zipStream);
                }
            }
        }
Exemplo n.º 5
0
        private async Task<double> buildAndCacheCellAndReturnElevationAsync(HgtCellCoords coords, double latitude, double longitude)
        {
            IHgtDataCell ret;
            try
            {
                ret = await _cellFactory.GetCellForAsync(coords);
            }
            catch (HgtFileException)
            {
                ret = HgtDataCellInvalid.Invalid;
            }

            var cell = _cache.GetOrAdd(coords, ret);

            return await cell.GetElevationAsync(latitude, longitude);
        }
Exemplo n.º 6
0
        public IHgtDataCell GetCellFor(HgtCellCoords coords)
        {
            var path = _pathResolver.FindFilePath(coords);

            FileStream file = null;
            try
            {
                int fileSize = (int)new FileInfo(path).Length;
                file = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                return new HgtDataCellInFile(file, HgtUtils.PointsPerCellFromDataLength(fileSize), coords);
            }
            catch (Exception)
            {
                if (file != null) file.Dispose();
                throw;
            }
        }
Exemplo n.º 7
0
        private string findPathForFile(HgtCellCoords coords)
        {
            string filename = coordsToFilename(coords);
            string[] potentialPaths =
            {
                Path.Combine(_directory, filename),
                Path.Combine(_directory, "Eurasia", filename),
                Path.Combine(_directory, "Africa", filename),
                Path.Combine(_directory, "South_America", filename),
                Path.Combine(_directory, "North_America", filename),
                Path.Combine(_directory, "Islands", filename),
            };

            var path = potentialPaths.FirstOrDefault(File.Exists);
            if (path != null) return path;

            var foundfile = new DirectoryInfo(_directory).EnumerateFiles(filename, SearchOption.AllDirectories)
                                                        .FirstOrDefault();
            if (foundfile != null) return foundfile.FullName;
            else throw new HgtFileNotFoundException(coords);
        }
Exemplo n.º 8
0
 protected HgtDataCellBase(int pointsPerCell, HgtCellCoords coords)
 {
     _pointsPerCell = pointsPerCell;
     _coords = coords;
 }
Exemplo n.º 9
0
 protected abstract string coordsToFilename(HgtCellCoords coords);
Exemplo n.º 10
0
 public string FindFilePath(HgtCellCoords coords)
 {
     return _cache.GetOrAdd(coords, findPathForFile);
 }
Exemplo n.º 11
0
        {
        }
    }
}
Exemplo n.º 12
0
 public HgtFileInvalidException(HgtCellCoords coords, string reason)
     : base(coords, string.Format("Invalid file ({2}) for coordinates [{0}, {1}]", coords.Lat, coords.Lon, reason))
 {
 }
Exemplo n.º 13
0
 protected abstract Task<byte[]> LoadHgtDataFromFileAsync(HgtCellCoords coords, [NotNull] string filePath);
Exemplo n.º 14
0
 protected override string coordsToFilename(HgtCellCoords coords)
 {
     return coords.ToBaseName() + ".hgt";
 }
Exemplo n.º 15
0
 internal HgtDataCellInFile([NotNull] FileStream file, int fileSize, HgtCellCoords coords)
     : base(fileSize, coords)
 {
     _file = file;
 }
Exemplo n.º 16
0
 public Task<IHgtDataCell> GetCellForAsync(HgtCellCoords coords)
 {
     return Task.FromResult(GetCellFor(coords));
 }
Exemplo n.º 17
0
 public HgtFileNotFoundException(HgtCellCoords coords)
     : base(coords, string.Format("Cannot find file for coordinates [{0}, {1}]", coords.Lat, coords.Lon))
 {
 }
Exemplo n.º 18
0
 protected HgtFileException(HgtCellCoords coords, [NotNull] string message)
     : base(message)
 {
     _coords = coords;
 }
Exemplo n.º 19
0
 public HgtFileException(HgtCellCoords coords, string message, Exception innerException)
     : base(message, innerException)
 {
     _coords = coords;
 }
Exemplo n.º 20
0
        public async Task<IHgtDataCell> GetCellForAsync(HgtCellCoords coords)
        {
            var data = await _loader.LoadFromFileAsync(coords);

            return new HgtDataCellInMemory(data, HgtUtils.PointsPerCellFromDataLength(data.Length), coords);
        }
Exemplo n.º 21
0
        public Task<byte[]> LoadFromFileAsync(HgtCellCoords coords)
        {
            var filePath = _pathResolver.FindFilePath(coords);

            return LoadHgtDataFromFileAsync(coords, filePath);
        }
Exemplo n.º 22
0
 public IHgtDataCell GetCellFor(HgtCellCoords coords)
 {
     var data = _loader.LoadFromFile(coords);
     return new HgtDataCellInMemory(data, HgtUtils.PointsPerCellFromDataLength(data.Length), coords);
 }
Exemplo n.º 23
0
 protected abstract byte[] LoadHgtDataFromFile(HgtCellCoords coords, [NotNull] string filePath);
Exemplo n.º 24
0
 internal HgtDataCellInMemory([NotNull] byte[] hgtData, int pointsPerCell, HgtCellCoords coords) : base(pointsPerCell, coords)
 {
     _hgtData = hgtData;
 }
Exemplo n.º 25
0
        public byte[] LoadFromFile(HgtCellCoords coords)
        {
            var filePath = _pathResolver.FindFilePath(coords);

            return LoadHgtDataFromFile(coords, filePath);
        }