Beispiel #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);
     }
 }
Beispiel #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);
     }
 }
 private IHgtDataCell buildCellFor(HgtCellCoords coords)
 {
     try
     {
         return _cellFactory.GetCellFor(coords);
     }
     catch (HgtFileException)
     {
         return HgtDataCellInvalid.Invalid;
     }
 }
Beispiel #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);
                }
            }
        }
        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);
        }
        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;
            }
        }
Beispiel #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);
        }
Beispiel #8
0
 protected HgtDataCellBase(int pointsPerCell, HgtCellCoords coords)
 {
     _pointsPerCell = pointsPerCell;
     _coords = coords;
 }
Beispiel #9
0
 protected abstract string coordsToFilename(HgtCellCoords coords);
Beispiel #10
0
 public string FindFilePath(HgtCellCoords coords)
 {
     return _cache.GetOrAdd(coords, findPathForFile);
 }
Beispiel #11
0
        {
        }
    }
}
Beispiel #12
0
 public HgtFileInvalidException(HgtCellCoords coords, string reason)
     : base(coords, string.Format("Invalid file ({2}) for coordinates [{0}, {1}]", coords.Lat, coords.Lon, reason))
 {
 }
 protected abstract Task<byte[]> LoadHgtDataFromFileAsync(HgtCellCoords coords, [NotNull] string filePath);
Beispiel #14
0
 protected override string coordsToFilename(HgtCellCoords coords)
 {
     return coords.ToBaseName() + ".hgt";
 }
 internal HgtDataCellInFile([NotNull] FileStream file, int fileSize, HgtCellCoords coords)
     : base(fileSize, coords)
 {
     _file = file;
 }
 public Task<IHgtDataCell> GetCellForAsync(HgtCellCoords coords)
 {
     return Task.FromResult(GetCellFor(coords));
 }
Beispiel #17
0
 public HgtFileNotFoundException(HgtCellCoords coords)
     : base(coords, string.Format("Cannot find file for coordinates [{0}, {1}]", coords.Lat, coords.Lon))
 {
 }
Beispiel #18
0
 protected HgtFileException(HgtCellCoords coords, [NotNull] string message)
     : base(message)
 {
     _coords = coords;
 }
Beispiel #19
0
 public HgtFileException(HgtCellCoords coords, string message, Exception innerException)
     : base(message, innerException)
 {
     _coords = coords;
 }
        public async Task<IHgtDataCell> GetCellForAsync(HgtCellCoords coords)
        {
            var data = await _loader.LoadFromFileAsync(coords);

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

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

            return LoadHgtDataFromFile(coords, filePath);
        }