From 168cd8e0e277793227f9cacd1cd26310ba495928 Mon Sep 17 00:00:00 2001 From: Xavier Fischer Date: Fri, 13 Aug 2021 18:23:11 +0200 Subject: [PATCH] asc gzip --- DEM.Net.Core/IO/Raster/AsciiGridFile.cs | 15 +++++++++++++-- DEM.Net.Core/Model/Datasets/DEMDataSet.cs | 15 ++++++++++++++- DEM.Net.Core/Model/Raster/DEMFileType.cs | 5 +++++ DEM.Net.Core/Services/Raster/RasterService.cs | 3 ++- DEM.Net.glTF/gtlfSharp/SharpGltfService.cs | 2 +- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/DEM.Net.Core/IO/Raster/AsciiGridFile.cs b/DEM.Net.Core/IO/Raster/AsciiGridFile.cs index 82425cec..3478fe24 100644 --- a/DEM.Net.Core/IO/Raster/AsciiGridFile.cs +++ b/DEM.Net.Core/IO/Raster/AsciiGridFile.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Globalization; using System.IO; +using System.IO.Compression; using System.Linq; using System.Text; @@ -23,17 +24,26 @@ public class ASCIIGridFile : IRasterFile { private FileStream _fileStream; private StreamReader _streamReader; + private GZipStream _gzipStream; private readonly string _filename; private static char[] SEPARATOR = new char[] { ' ' }; List> _data = null; private static Dictionary>> _tempCache = new Dictionary>>(); - public ASCIIGridFile(string fileName) + public ASCIIGridFile(string fileName, bool gzip) { this._filename = fileName; _fileStream = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read); - _streamReader = new StreamReader(_fileStream, Encoding.ASCII); + if (gzip) + { + _gzipStream = new GZipStream(_fileStream, CompressionMode.Decompress); + _streamReader = new StreamReader(_gzipStream, Encoding.ASCII); + } + else + { + _streamReader = new StreamReader(_fileStream, Encoding.ASCII); + } } public float GetElevationAtPoint(FileMetadata metadata, int x, int y) { @@ -250,6 +260,7 @@ protected virtual void Dispose(bool disposing) //_data = null; _streamReader?.Dispose(); _fileStream?.Dispose(); + _gzipStream?.Dispose(); } disposedValue = true; diff --git a/DEM.Net.Core/Model/Datasets/DEMDataSet.cs b/DEM.Net.Core/Model/Datasets/DEMDataSet.cs index 8f09e6a4..4483dc4e 100644 --- a/DEM.Net.Core/Model/Datasets/DEMDataSet.cs +++ b/DEM.Net.Core/Model/Datasets/DEMDataSet.cs @@ -124,6 +124,19 @@ private static Dictionary GetRegisteredDatasets() Attribution = new Attribution(ATTRIBUTION_SUBJECT, "ETOPO1 - NOAA", "https://www.ngdc.noaa.gov/mgg/global/" , "Amante, C. and B.W. Eakins, 2009. ETOPO1 1 Arc-Minute Global Relief Model: Procedures, Data Sources and Analysis. NOAA Technical Memorandum NESDIS NGDC-24. National Geophysical Data Center, NOAA. doi:10.7289/V5C8276M") }); + datasets.Add("IGN_5m", new DEMDataSet() + { + Name = nameof(IGN_5m), + Description = "IGN RGE Alti 5 meter (France only)", + PublicUrl = "https://ign.fr", + DataSource = new LocalFileSystem(localDirectory: Path.Combine("Data", "IGN_5m_GZip")), + FileFormat = new DEMFileDefinition("Esri Ascii Grid (GZipped)", DEMFileType.ASCIIGridGzip, ".asc.gz", DEMFileRegistrationMode.Cell), + ResolutionMeters = 5, + PointsPerDegree = 21600, + NoDataValue = -99999, + SRID = 2154, + Attribution = new Attribution(ATTRIBUTION_SUBJECT, "IGN", "https://ign.fr", "https://www.etalab.gouv.fr/licence-ouverte-open-licence") + }); //datasets.Add("IGN_5m", new DEMDataSet() //{ // Name = nameof(IGN_5m), @@ -185,7 +198,7 @@ private static Dictionary GetRegisteredDatasets() datasets.Add("GEBCO_2019", new DEMDataSet() { Name = nameof(GEBCO_2019), - Description = "GEBCO’s gridded bathymetric data set, a global terrain model for ocean and land at 15 arc-second intervals", + Description = "400m with bathymetry", PublicUrl = "https://www.gebco.net/data_and_products/gridded_bathymetry_data/gebco_2019/gebco_2019_info.html", DataSource = new LocalFileSystem(localDirectory: Path.Combine("Data", "GEBCO_2019")), FileFormat = new DEMFileDefinition("netCDF file", DEMFileType.CF_NetCDF, ".nc", DEMFileRegistrationMode.Cell), diff --git a/DEM.Net.Core/Model/Raster/DEMFileType.cs b/DEM.Net.Core/Model/Raster/DEMFileType.cs index d2039908..8472db27 100644 --- a/DEM.Net.Core/Model/Raster/DEMFileType.cs +++ b/DEM.Net.Core/Model/Raster/DEMFileType.cs @@ -44,5 +44,10 @@ public enum DEMFileType /// /// See https://en.wikipedia.org/wiki/Esri_grid ASCIIGrid, + /// + /// ESRI ARC/INFO ASCII GRID + /// + /// See https://en.wikipedia.org/wiki/Esri_grid + ASCIIGridGzip, } } diff --git a/DEM.Net.Core/Services/Raster/RasterService.cs b/DEM.Net.Core/Services/Raster/RasterService.cs index 8ffbd8c6..f559c70e 100644 --- a/DEM.Net.Core/Services/Raster/RasterService.cs +++ b/DEM.Net.Core/Services/Raster/RasterService.cs @@ -115,7 +115,8 @@ public IRasterFile OpenFile(string filePath, DEMFileType fileFormat) { case DEMFileType.GEOTIFF: return new GeoTiff(filePath); case DEMFileType.SRTM_HGT: return new HGTFile(filePath); - case DEMFileType.ASCIIGrid: return new ASCIIGridFile(filePath); + case DEMFileType.ASCIIGrid: return new ASCIIGridFile(filePath, gzip: false); + case DEMFileType.ASCIIGridGzip: return new ASCIIGridFile(filePath, gzip: true); case DEMFileType.CF_NetCDF: return new NetCdfFile(filePath); default: throw new NotImplementedException($"{fileFormat} file format not implemented."); diff --git a/DEM.Net.glTF/gtlfSharp/SharpGltfService.cs b/DEM.Net.glTF/gtlfSharp/SharpGltfService.cs index 61247fce..daad253d 100644 --- a/DEM.Net.glTF/gtlfSharp/SharpGltfService.cs +++ b/DEM.Net.glTF/gtlfSharp/SharpGltfService.cs @@ -140,7 +140,7 @@ public ModelRoot AddTerrainMesh(ModelRoot model, HeightMap heightMap, PBRTexture { Triangulation triangulation = _meshService.TriangulateHeightMap(heightMap); - triangulation = _meshReducer.Decimate(triangulation, reduceFactor); + triangulation = reduceFactor < 1f ? _meshReducer.Decimate(triangulation, reduceFactor) : triangulation; model = AddTerrainMesh(model, triangulation, textures);