Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dem-net/DEM.Net
Browse files Browse the repository at this point in the history
  • Loading branch information
xfischer committed Sep 27, 2020
2 parents df1b18e + 468e653 commit 1675fd0
Show file tree
Hide file tree
Showing 19 changed files with 822 additions and 289 deletions.
14 changes: 7 additions & 7 deletions DEM.Net.Core/DEM.Net.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>DEM.Net.Core</PackageId>
<Version>0.2.7.3</Version>
<Version>0.2.7.4</Version>
<Authors>Xavier Fischer, Frédéric Aubin</Authors>
<Copyright>Xavier Fischer, Frédéric Aubin and Contributors</Copyright>
<Owners>Xavier Fischer</Owners>
<PackageProjectUrl>https://github.com/dem-net/DEM.Net</PackageProjectUrl>
<PackageReleaseNotes>- Code refactor (removed useless interfaces, readability)
- Lines bulk elevation (better performance)
- Imagery disk cache
- Procedural mesh generation for axis, cylinder, cones</PackageReleaseNotes>
<PackageReleaseNotes>- OpenTopography endpoints updated
- Disabled GEBCO 2020
- New STL transforms
- Triangulation Clone()</PackageReleaseNotes>
<PackageTags>DEM, Terrain, Elevation</PackageTags>
<Title>DEM.Net</Title>
<Product>DEM.Net</Product>
Expand All @@ -21,8 +21,8 @@
<PackageLicenseExpression></PackageLicenseExpression>
<PackageIconUrl>https://raw.githubusercontent.com/dem-net/Resources/master/images/DEMnet_512.png</PackageIconUrl>
<PackageIcon>DEMnet_64.png</PackageIcon>
<AssemblyVersion>0.2.7.3</AssemblyVersion>
<FileVersion>0.2.7.3</FileVersion>
<AssemblyVersion>0.2.7.4</AssemblyVersion>
<FileVersion>0.2.7.4</FileVersion>
<UserSecretsId>a9a5d6e1-3bb8-4dfd-ac6a-861f60dada50</UserSecretsId>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
Expand Down
30 changes: 22 additions & 8 deletions DEM.Net.Core/Helpers/HeightMapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static HeightMap CenterOnOrigin(this HeightMap heightMap, GeoPoint origin
/// Centers height map on origin
/// </summary>
/// <param name="heightMap"></param>
/// <param name="centerOnZ"></param>
/// <returns></returns>
/// <remarks>This can be used in an height map processing pipeline, as coordinates are changed only on enumeration</remarks>
public static HeightMap CenterOnOrigin(this HeightMap heightMap, bool centerOnZ = false)
Expand All @@ -91,22 +92,29 @@ public static HeightMap CenterOnOrigin(this HeightMap heightMap, bool centerOnZ

double xOriginOffset = bbox.xMax - (bbox.xMax - bbox.xMin) / 2d;
double yOriginOffset = bbox.yMax - (bbox.yMax - bbox.yMin) / 2d;
double zOriginOffset = bbox.zMax - (bbox.zMax - bbox.zMin) / 2d;
heightMap.Coordinates = heightMap.Coordinates.Translate(-xOriginOffset, -yOriginOffset, centerOnZ ? -bbox.zMin : 0);

heightMap.BoundingBox = new BoundingBox(bbox.xMin - xOriginOffset, bbox.xMax - xOriginOffset
, bbox.yMin - yOriginOffset, bbox.yMax - yOriginOffset
, 0, bbox.zMax - bbox.zMin);
return heightMap;
}
public static BoundingBox CenterOnOrigin(this BoundingBox bbox, bool centerOnZ = false)
{
double xOriginOffset = bbox.xMax - (bbox.xMax - bbox.xMin) / 2d;
double yOriginOffset = bbox.yMax - (bbox.yMax - bbox.yMin) / 2d;
return new BoundingBox(bbox.xMin - xOriginOffset, bbox.xMax - xOriginOffset
, bbox.yMin - yOriginOffset, bbox.yMax - yOriginOffset
, 0, bbox.zMax - bbox.zMin);

}

public static HeightMap CenterOnOrigin(this HeightMap heightMap, BoundingBox bbox, bool centerOnZ = false)
{
//Logger.Info("CenterOnOrigin...");

double xOriginOffset = bbox.xMax - (bbox.xMax - bbox.xMin) / 2d;
double yOriginOffset = bbox.yMax - (bbox.yMax - bbox.yMin) / 2d;
double zOriginOffset = bbox.zMax - (bbox.zMax - bbox.zMin) / 2d;
heightMap.Coordinates = heightMap.Coordinates.Translate(-xOriginOffset, -yOriginOffset, centerOnZ ? -bbox.zMin : 0);

heightMap.BoundingBox = new BoundingBox(bbox.xMin - xOriginOffset, bbox.xMax - xOriginOffset
Expand Down Expand Up @@ -248,7 +256,11 @@ public static HeightMap Scale(this HeightMap heightMap, float x = 1f, float y =
/// <returns></returns>
public static HeightMap FitInto(this HeightMap heightMap, float maxSize)
{
float scale = 1f;
return FitInto(heightMap, maxSize, out float scale);
}
public static HeightMap FitInto(this HeightMap heightMap, float maxSize, out float scale)
{
scale = 1f;
if (heightMap.BoundingBox.Width > heightMap.BoundingBox.Height)
{
scale = (float)(maxSize / heightMap.BoundingBox.Width);
Expand Down Expand Up @@ -403,11 +415,13 @@ public static HeightMap Downsample(this HeightMap heightMap, int step)
if (step == 0 || step % 2 != 0)
throw new ArgumentOutOfRangeException("step", "Step must be a factor of 2");

HeightMap hMap = new HeightMap(heightMap.Width / step, heightMap.Height / step);
hMap.Maximum = heightMap.Maximum;
hMap.Minimum = heightMap.Minimum;
hMap.BoundingBox = heightMap.BoundingBox;
hMap.Coordinates = DownsampleCoordinates(heightMap.Coordinates.ToList(), heightMap.Width, heightMap.Height, step).ToList();
HeightMap hMap = new HeightMap(heightMap.Width / step, heightMap.Height / step)
{
Maximum = heightMap.Maximum,
Minimum = heightMap.Minimum,
BoundingBox = heightMap.BoundingBox,
Coordinates = DownsampleCoordinates(heightMap.Coordinates.ToList(), heightMap.Width, heightMap.Height, step).ToList()
};

return hMap;
}
Expand Down
16 changes: 16 additions & 0 deletions DEM.Net.Core/Helpers/PointsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static class PointsExtensions
/// Assumes that the provided list is a "line string"
/// </summary>
/// <param name="points"></param>
/// <param name="noDataValue"></param>
/// <returns></returns>
public static ElevationMetrics ComputeMetrics(this IList<GeoPoint> points, double? noDataValue = null)
{
Expand Down Expand Up @@ -44,5 +45,20 @@ public static List<GeoPoint> Simplify(this IReadOnlyList<GeoPoint> points, doubl
{
return DouglasPeucker.DouglasPeuckerReduction(points, toleranceMeters);
}

public static IEnumerable<GeoPoint> FitInto(this IEnumerable<GeoPoint> points, BoundingBox bboxUsedForGeneration, float maxSize)
{
float scale = 1f;
if (bboxUsedForGeneration.Width > bboxUsedForGeneration.Height)
{
scale = (float)(maxSize / bboxUsedForGeneration.Width);
}
else
{
scale = (float)(maxSize / bboxUsedForGeneration.Height);
}

return points.Scale(scale, scale, scale);
}
}
}
8 changes: 4 additions & 4 deletions DEM.Net.Core/Model/Datasets/DEMDataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override string ToString()
Name = nameof(SRTM_GL3),
Description = "Shuttle Radar Topography Mission (SRTM GL3) Global 90m",
PublicUrl = "http://opentopo.sdsc.edu/raster?opentopoID=OTSRTM.042013.4326.1",
DataSource = new VRTDataSource("https://cloud.sdsc.edu/v1/AUTH_opentopography/Raster/SRTM_GL3/SRTM_GL3_srtm.vrt"),
DataSource = new VRTDataSource("https://opentopography.s3.sdsc.edu/raster/SRTM_GL3/SRTM_GL3_srtm.vrt"),
FileFormat = new DEMFileDefinition("Nasa SRTM HGT", DEMFileType.SRTM_HGT, ".hgt", DEMFileRegistrationMode.Grid),
ResolutionMeters = 90,
ResolutionArcSeconds = 3,
Expand All @@ -87,7 +87,7 @@ public override string ToString()
Name = nameof(SRTM_GL1),
Description = "Shuttle Radar Topography Mission (SRTM GL1) Global 30m",
PublicUrl = "http://opentopo.sdsc.edu/raster?opentopoID=OTSRTM.082015.4326.1",
DataSource = new VRTDataSource("https://cloud.sdsc.edu/v1/AUTH_opentopography/Raster/SRTM_GL1/SRTM_GL1_srtm.vrt"),
DataSource = new VRTDataSource("https://opentopography.s3.sdsc.edu/raster/SRTM_GL1/SRTM_GL1_srtm.vrt"),
FileFormat = new DEMFileDefinition("Nasa SRTM HGT", DEMFileType.SRTM_HGT, ".hgt", DEMFileRegistrationMode.Grid),
ResolutionMeters = 30,
ResolutionArcSeconds = 1,
Expand All @@ -99,7 +99,7 @@ public override string ToString()
Name = nameof(AW3D30),
Description = "ALOS World 3D - 30m (nicest but contain void areas)",
PublicUrl = "http://opentopo.sdsc.edu/raster?opentopoID=OTALOS.112016.4326.2",
DataSource = new VRTDataSource("https://cloud.sdsc.edu/v1/AUTH_opentopography/Raster/AW3D30/AW3D30_alos.vrt"),
DataSource = new VRTDataSource("https://opentopography.s3.sdsc.edu/raster/AW3D30/AW3D30_alos.vrt"),
FileFormat = new DEMFileDefinition("GeoTiff file", DEMFileType.GEOTIFF, ".tif", DEMFileRegistrationMode.Cell),
ResolutionMeters = 30,
ResolutionArcSeconds = 1,
Expand Down Expand Up @@ -216,7 +216,7 @@ public override string ToString()
/// Global medium res coverage with bathymetry (500m resolution)
/// </summary>
public static DEMDataSet GEBCO_2019 => Datasets.Value[nameof(GEBCO_2019)];
public static DEMDataSet GEBCO_2020 => Datasets.Value[nameof(GEBCO_2020)];
//public static DEMDataSet GEBCO_2020 => Datasets.Value[nameof(GEBCO_2020)];

/// <summary>
/// ASTER GDEM V3 https://cmr.earthdata.nasa.gov/search/concepts/C1575726572-LPDAAC_ECS/11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void Setup(DEMDataSet dataSet, string dataSetLocalDir)
pageIndex++;
logger.LogInformation($"Getting entries on page {pageIndex} with page size of {PAGE_SIZE} ({(pageIndex - 1) * PAGE_SIZE} entries so far)...");
var url = dataSource.GetUrl(PAGE_SIZE, pageIndex);

var json = httpClient.GetStringAsync(url).GetAwaiter().GetResult();
hasData = !string.IsNullOrWhiteSpace(json);
if (hasData)
Expand Down
5 changes: 3 additions & 2 deletions DEM.Net.Core/Services/Mesh/MeshService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public IEnumerable<Vector3> ComputeNormals(HeightMap heightMap)
return normals;
}

public TriangulationList<Vector3> GenerateTriangleMesh_Line(IEnumerable<GeoPoint> points, float width)
public TriangulationList<Vector3> GenerateTriangleMesh_Line(IEnumerable<GeoPoint> points, float width, Matrix4x4 transform)
{
try
{
Expand All @@ -357,7 +357,8 @@ public TriangulationList<Vector3> GenerateTriangleMesh_Line(IEnumerable<GeoPoint

// https://gist.github.com/gszauer/5718441
// Line triangle mesh
List<Vector3> sections = points.Select(pt => pt.ToVector3GlTFSpace())
transform = transform == default ? Matrix4x4.Identity : transform;
List<Vector3> sections = points.Select(pt => Vector3.Transform(pt.ToVector3GlTFSpace(), transform))
.FilterConsecutiveSame()
.ToList();

Expand Down
7 changes: 7 additions & 0 deletions DEM.Net.Core/Services/Mesh/Triangulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
// THE SOFTWARE.

using DEM.Net.Core;
using NetTopologySuite.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -92,6 +94,11 @@ public TriangulationList(List<T> positions, List<Vector4> colors, List<int> indi
colors: a.Colors.Concat(b.Colors).ToList(),
indices: a.Indices.Concat(b.Indices.Select(i => i + a.NumPositions)).ToList());
}

public TriangulationList<T> Clone()
{
return new TriangulationList<T>(new List<T>(Positions), new List<Vector4>(Colors), new List<int>(Indices));
}
}

public class Triangulation<T>
Expand Down
6 changes: 3 additions & 3 deletions DEM.Net.Core/Services/Raster/RasterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class RasterService : IRasterDownloader
internal const string MANIFEST_DIR = "manifest";
private readonly RasterIndexServiceResolver _rasterIndexServiceResolver;
private readonly ILogger<RasterService> _logger;
private NamedMonitor monitor = new NamedMonitor();
private readonly NamedMonitor monitor = new NamedMonitor();

private string _localDirectory;
private ConcurrentDictionary<string, List<FileMetadata>> _metadataCatalogCache = new ConcurrentDictionary<string, List<FileMetadata>>();
Expand Down Expand Up @@ -128,11 +128,11 @@ public string GetLocalDEMFilePath(DEMDataSet dataset, string fileTitle)
{
return Path.Combine(GetLocalDEMPath(dataset), fileTitle);
}
public FileMetadata ParseMetadata(IRasterFile rasterFile, DEMFileDefinition format, bool makeRelativePath = false)
public FileMetadata ParseMetadata(IRasterFile rasterFile, DEMFileDefinition format)
{
return rasterFile.ParseMetaData(format);
}
public FileMetadata ParseMetadata(string fileName, DEMFileDefinition fileFormat, bool makeRelativePath = true)
public FileMetadata ParseMetadata(string fileName, DEMFileDefinition fileFormat)
{
FileMetadata metadata = null;

Expand Down
76 changes: 76 additions & 0 deletions DEM.Net.TestWinForm/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,82 @@
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.FileProviders.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.FileSystemGlobbing" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.FileProviders.Physical" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Caching.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Options" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration.FileExtensions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration.Json" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.5.0" newVersion="3.1.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

0 comments on commit 1675fd0

Please sign in to comment.