private void DownloadDEMTile_HttpClient(string url, DEMFileFormat fileFormat, string localFileName) { // Create directories if not existing new FileInfo(localFileName).Directory.Create(); _logger?.LogInformation($"Downloading file {url}..."); using (HttpClient client = new HttpClient()) { //using (HttpResponseMessage response = client.GetAsync(url).Result) //{ // if (response.IsSuccessStatusCode) // { // using (HttpContent content = response.Content) // { // using (FileStream fs = new FileStream(localFileName, FileMode.Create, FileAccess.Write)) // { // var contentbytes = content.ReadAsByteArrayAsync().Result; // fs.Write(contentbytes, 0, contentbytes.Length); // } // } // } //} var contentbytes = client.GetByteArrayAsync(url).Result; using (FileStream fs = new FileStream(localFileName, FileMode.Create, FileAccess.Write)) { fs.Write(contentbytes, 0, contentbytes.Length); } } _IRasterService.GenerateFileMetadata(localFileName, fileFormat, false); }
public HeightMap GetHeightMap(BoundingBox bbox, string rasterFilePath, DEMFileFormat format) { HeightMap heightMap = null; using (IRasterFile raster = _IRasterService.OpenFile(rasterFilePath, format)) { var metaData = raster.ParseMetaData(); heightMap = raster.GetHeightMapInBBox(bbox, metaData, NO_DATA_OUT); } return(heightMap); }
public FileMetadata ParseMetadata(string fileName, DEMFileFormat fileFormat, bool makeRelativePath = true) { FileMetadata metadata = null; fileName = Path.GetFullPath(fileName); using (IRasterFile rasterFile = OpenFile(fileName, fileFormat)) { metadata = rasterFile.ParseMetaData(); } Uri fullPath = new Uri(metadata.Filename, UriKind.Absolute); Uri relRoot = new Uri(Path.GetFullPath(_localDirectory) + Path.DirectorySeparatorChar, UriKind.Absolute); metadata.Filename = Uri.UnescapeDataString(relRoot.MakeRelativeUri(fullPath).ToString()); return(metadata); }
/// <summary> /// Open specified file /// </summary> /// <param name="filePath">If path is rooted (full file name), the specified file will be openened, /// otherwise the file path will be relative to <see cref="LocalDirectory"/></param> /// <param name="fileFormat"><see cref="DEMFileFormat"/> enumeration indicating the file type</param> /// <returns><see cref="IRasterFile"/> interface for accessing file contents</returns> public IRasterFile OpenFile(string filePath, DEMFileFormat fileFormat) { if (!Path.IsPathRooted(filePath)) { filePath = Path.Combine(_localDirectory, filePath); } if (fileFormat.Name == DEMFileFormat.GEOTIFF.Name) { return(new GeoTiff(filePath)); } else if (fileFormat.Name == DEMFileFormat.SRTM_HGT.Name) { return(new HGTFile(filePath)); } else { throw new NotImplementedException($"{fileFormat} file format not implemented."); } }
public void GenerateFileMetadata(string rasterFileName, DEMFileFormat fileFormat, bool force) { if (!File.Exists(rasterFileName)) { throw new FileNotFoundException($"File {rasterFileName} does not exists !"); } string outDirPath = GetManifestDirectory(rasterFileName); string bmpPath = GetMetadataFileName(rasterFileName, outDirPath, ".bmp"); string jsonPath = GetMetadataFileName(rasterFileName, outDirPath, ".json"); // Output directory "manifest" if (!Directory.Exists(outDirPath)) { Directory.CreateDirectory(outDirPath); } if (force) { if (File.Exists(jsonPath)) { File.Delete(jsonPath); } if (File.Exists(bmpPath)) { File.Delete(bmpPath); } } // Json manifest if (File.Exists(jsonPath) == false) { Trace.TraceInformation($"Generating manifest for file {rasterFileName}."); FileMetadata metadata = this.ParseMetadata(rasterFileName, fileFormat); File.WriteAllText(jsonPath, JsonConvert.SerializeObject(metadata, Formatting.Indented)); Trace.TraceInformation($"Manifest generated for file {rasterFileName}."); } }
public FileMetadata(string filename, DEMFileFormat fileFormat, string version = FILEMETADATA_VERSION) { this.Filename = filename; this.fileFormat = fileFormat; this.Version = version; }