Skip to content

Commit

Permalink
asc gzip
Browse files Browse the repository at this point in the history
  • Loading branch information
xfischer committed Aug 13, 2021
1 parent b26675e commit 168cd8e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
15 changes: 13 additions & 2 deletions DEM.Net.Core/IO/Raster/AsciiGridFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;

Expand All @@ -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<List<string>> _data = null;
private static Dictionary<string, List<List<string>>> _tempCache = new Dictionary<string, List<List<string>>>();

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)
{
Expand Down Expand Up @@ -250,6 +260,7 @@ protected virtual void Dispose(bool disposing)
//_data = null;
_streamReader?.Dispose();
_fileStream?.Dispose();
_gzipStream?.Dispose();
}

disposedValue = true;
Expand Down
15 changes: 14 additions & 1 deletion DEM.Net.Core/Model/Datasets/DEMDataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ private static Dictionary<string, DEMDataSet> 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),
Expand Down Expand Up @@ -185,7 +198,7 @@ private static Dictionary<string, DEMDataSet> 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),
Expand Down
5 changes: 5 additions & 0 deletions DEM.Net.Core/Model/Raster/DEMFileType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ public enum DEMFileType
/// </summary>
/// <remarks>See https://en.wikipedia.org/wiki/Esri_grid</remarks>
ASCIIGrid,
/// <summary>
/// ESRI ARC/INFO ASCII GRID
/// </summary>
/// <remarks>See https://en.wikipedia.org/wiki/Esri_grid</remarks>
ASCIIGridGzip,
}
}
3 changes: 2 additions & 1 deletion DEM.Net.Core/Services/Raster/RasterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
2 changes: 1 addition & 1 deletion DEM.Net.glTF/gtlfSharp/SharpGltfService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 168cd8e

Please sign in to comment.