Skip to content

Commit b46ed2d

Browse files
committed
Merge branch 'dev'
2 parents 12d99be + be42914 commit b46ed2d

25 files changed

+906
-124
lines changed

DEM.Net.Core/Configuration/DEMNetOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class DEMNetOptions
1111

1212
public float RenderGpxTrailWidthMeters { get; set; } = 15f;
1313
public List<ImageryProvider> ImageryProviders { get; set; } = new List<ImageryProvider>();
14+
15+
public bool UseImageryDiskCache { get; set; } = true;
16+
public float ImageryDiskCacheExpirationHours { get; set; } = 5f;
17+
1418
public float ImageryCacheExpirationMinutes { get; set; } = 5f;
1519
}
1620
}

DEM.Net.Core/Configuration/ServiceCollectionExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using DEM.Net.Core.Datasets;
22
using DEM.Net.Core.EarthData;
33
using DEM.Net.Core.Imagery;
4+
using DEM.Net.Core.Services.Imagery;
45
using Microsoft.Extensions.Caching.Memory;
56
using Microsoft.Extensions.DependencyInjection;
67
using System;
@@ -16,6 +17,7 @@ public static class ServiceCollectionExtension
1617
public static IServiceCollection AddDemNetCore(this IServiceCollection services)
1718
{
1819
services.AddMemoryCache();
20+
services.AddHttpClient();
1921

2022
services.AddSingleton<GDALVRTFileService>();
2123
services.AddSingleton<LocalFileSystemIndex>();
@@ -42,8 +44,10 @@ public static IServiceCollection AddDemNetCore(this IServiceCollection services)
4244
.AddSingleton<RasterService>()
4345
.AddTransient<ElevationService>()
4446
.AddTransient<MeshService>()
47+
.AddTransient<ImageryCache>()
4548
.AddSingleton<ImageryService>();
4649

50+
4751
return services;
4852
}
4953
}

DEM.Net.Core/DEM.Net.Core.csproj

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<PackageId>DEM.Net.Core</PackageId>
5-
<Version>0.2.7.1</Version>
5+
<Version>0.2.7.2</Version>
66
<Authors>Xavier Fischer, Frédéric Aubin</Authors>
77
<Copyright>Xavier Fischer, Frédéric Aubin and Contributors</Copyright>
88
<Owners>Xavier Fischer</Owners>
99
<PackageProjectUrl>https://github.com/dem-net/DEM.Net</PackageProjectUrl>
10-
<PackageReleaseNotes>Various bug fixes, OSM pipeline, glTF models centered on origin</PackageReleaseNotes>
10+
<PackageReleaseNotes>
11+
Code refactor (removed useless interfaces, readability)
12+
Lines bulk elevation (better performance)
13+
Imagery disk cache
14+
Procedural mesh generation for axis, cylinder, cones
15+
</PackageReleaseNotes>
1116
<PackageTags>DEM, Terrain, Elevation</PackageTags>
1217
<Title>DEM.Net</Title>
1318
<Product>DEM.Net</Product>
@@ -19,8 +24,8 @@
1924
</PackageLicenseExpression>
2025
<PackageIconUrl>https://raw.githubusercontent.com/dem-net/Resources/master/images/DEMnet_512.png</PackageIconUrl>
2126
<PackageIcon>DEMnet_64.png</PackageIcon>
22-
<AssemblyVersion>0.2.7.1</AssemblyVersion>
23-
<FileVersion>0.2.7.1</FileVersion>
27+
<AssemblyVersion>0.2.7.2</AssemblyVersion>
28+
<FileVersion>0.2.7.2</FileVersion>
2429
<UserSecretsId>a9a5d6e1-3bb8-4dfd-ac6a-861f60dada50</UserSecretsId>
2530
<TargetFramework>netstandard2.0</TargetFramework>
2631
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
@@ -59,9 +64,9 @@
5964
</ItemGroup>
6065
<!-- .NET Standard 2.0 references, compilation flags and build options -->
6166
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
62-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
63-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
64-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
67+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.5" />
68+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.1.5" />
69+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.5" />
6570
</ItemGroup>
6671
<ItemGroup>
6772
<Compile Remove="Services\Voronoi\BeanTopologie\**" />
@@ -89,14 +94,15 @@
8994
<PackageReference Include="DotSpatial.Projections.NetStandard" Version="1.0.0" />
9095
<PackageReference Include="GeoAPI.CoordinateSystems" Version="1.7.5" />
9196
<PackageReference Include="GeoAPI.Core" Version="1.7.5" />
92-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
93-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.2.0" />
94-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
95-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
96-
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
9797
<PackageReference Include="NetTopologySuite" Version="1.15.3" />
98+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.5" />
99+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.5" />
100+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.5" />
101+
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.5" />
102+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.5" />
103+
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.5" />
98104
<PackageReference Include="NetTopologySuite.Diagnostics.Tracing" Version="0.0.3" />
99-
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
105+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
100106
<PackageReference Include="SDSLite" Version="1.4.0" />
101107
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta0007" />
102108
<PackageReference Include="SixLabors.Shapes" Version="1.0.0-beta0009" />

DEM.Net.Core/Helpers/HeightMapExtensions.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
// THE SOFTWARE.
2525

26+
using DEM.Net.Core.Gpx;
27+
using SixLabors.ImageSharp.ColorSpaces;
2628
using System;
2729
using System.Collections.Generic;
2830
using System.Linq;
@@ -62,6 +64,20 @@ public static HeightMap CenterOnOrigin(this HeightMap heightMap, out Matrix4x4 t
6264
, bbox.zMin - zOriginOffset, bbox.zMax - zOriginOffset);
6365
return heightMap;
6466
}
67+
public static HeightMap CenterOnOrigin(this HeightMap heightMap, GeoPoint origin)
68+
{
69+
//Logger.Info("CenterOnOrigin...");
70+
var bbox = heightMap.BoundingBox;
71+
72+
heightMap.Coordinates = heightMap.Coordinates.Translate(-origin.Longitude, -origin.Latitude, -origin.Elevation ?? 0);
73+
74+
75+
76+
heightMap.BoundingBox = new BoundingBox(bbox.xMin - origin.Longitude, bbox.xMax - origin.Longitude
77+
, bbox.yMin - origin.Latitude, bbox.yMax - origin.Latitude
78+
, bbox.zMin - origin.Elevation ?? 0, bbox.zMax - origin.Elevation ?? 0);
79+
return heightMap;
80+
}
6581
/// <summary>
6682
/// Centers height map on origin
6783
/// </summary>
@@ -113,6 +129,10 @@ public static IEnumerable<GeoPoint> CenterOnOrigin(this IEnumerable<GeoPoint> po
113129

114130
return points.CenterOnOrigin(bbox);
115131
}
132+
public static IEnumerable<GeoPoint> CenterOnOrigin(this IEnumerable<GeoPoint> points, GeoPoint origin)
133+
{
134+
return points.Translate(-origin.Longitude, -origin.Latitude, -origin.Elevation ?? 0);
135+
}
116136

117137
/// <summary>
118138
/// Centers a set of points on origin, when their bbox is known
@@ -130,6 +150,17 @@ public static IEnumerable<GeoPoint> CenterOnOrigin(this IEnumerable<GeoPoint> po
130150

131151
return points;
132152
}
153+
154+
public static GeoPoint CenterOnOrigin(this GeoPoint point, BoundingBox bbox, bool centerOnZ = false)
155+
{
156+
//Logger.Info("CenterOnOrigin...");
157+
double xOriginOffset = bbox.xMax - (bbox.xMax - bbox.xMin) / 2d;
158+
double yOriginOffset = bbox.yMax - (bbox.yMax - bbox.yMin) / 2d;
159+
//double zOriginOffset = bbox.zMax - (bbox.zMax - bbox.zMin) / 2d;
160+
point = point.Translate(-xOriginOffset, -yOriginOffset, centerOnZ ? -bbox.zMin : 0); // Set minZ = 0
161+
162+
return point;
163+
}
133164
/// <summary>
134165
/// Translate points
135166
/// </summary>
@@ -138,7 +169,7 @@ public static IEnumerable<GeoPoint> CenterOnOrigin(this IEnumerable<GeoPoint> po
138169
/// <param name="y"></param>
139170
/// <param name="z"></param>
140171
/// <returns></returns>
141-
private static IEnumerable<GeoPoint> Translate(this IEnumerable<GeoPoint> points, double x, double y, double z = 0)
172+
public static IEnumerable<GeoPoint> Translate(this IEnumerable<GeoPoint> points, double x, double y, double z = 0)
142173
{
143174
//Logger.Info("Translate...");
144175
foreach (var pt in points)
@@ -151,6 +182,18 @@ private static IEnumerable<GeoPoint> Translate(this IEnumerable<GeoPoint> points
151182
}
152183
//Logger.Info("Translate done...");
153184
}
185+
public static GeoPoint Translate(this GeoPoint point, double x, double y, double z = 0)
186+
{
187+
//Logger.Info("Translate...");
188+
189+
var p = point.Clone();
190+
p.Latitude += y;
191+
p.Longitude += x;
192+
p.Elevation += z;
193+
return p;
194+
195+
//Logger.Info("Translate done...");
196+
}
154197

155198
/// <summary>
156199
/// Helper to get an in memory coordinate list
@@ -254,6 +297,21 @@ public static IEnumerable<GeoPoint> Scale(this IEnumerable<GeoPoint> points, flo
254297
}
255298
//Logger.Info("Scale done...");
256299

300+
}/// <summary>
301+
/// Scale given points
302+
/// </summary>
303+
/// <param name="points"></param>
304+
/// <param name="x"></param>
305+
/// <param name="y"></param>
306+
/// <param name="z"></param>
307+
/// <returns></returns>
308+
public static GeoPoint Scale(this GeoPoint pt, float x = 1f, float y = 1f, float z = 1f)
309+
{
310+
var pout = pt.Clone();
311+
pout.Longitude *= x;
312+
pout.Latitude *= y;
313+
pout.Elevation *= z;
314+
return pout;
257315
}
258316

259317
/// <summary>
@@ -270,6 +328,14 @@ public static HeightMap ZTranslate(this HeightMap heightMap, float distance)
270328

271329
return heightMap;
272330
}
331+
public static HeightMap Translate(this HeightMap heightMap, GeoPoint pt)
332+
{
333+
heightMap.Coordinates = heightMap.Coordinates.Translate(pt.Longitude, pt.Latitude, pt.Elevation ?? 0);
334+
heightMap.Minimum += (float)(pt.Elevation ?? 0);
335+
heightMap.Maximum += (float)(pt.Elevation ?? 0);
336+
337+
return heightMap;
338+
}
273339

274340
/// <summary>
275341
/// Verticaly translates points

DEM.Net.Core/Helpers/Reprojection.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using System.Collections.Generic;
2828
using System.Diagnostics;
2929
using System.Linq;
30+
using System.Numerics;
3031
using System.Text;
3132
using System.Threading.Tasks;
3233
using DEM.Net.Core.Imagery;
@@ -109,6 +110,47 @@ public static IEnumerable<GeoPoint> ReprojectTo(this IEnumerable<GeoPoint> point
109110

110111
}
111112
}
113+
public static TriangulationList<Vector3> ReprojectTo(this TriangulationList<Vector3> triangulation, int sourceEpsgCode, int destinationEpsgCode)
114+
{
115+
if (sourceEpsgCode == destinationEpsgCode)
116+
return triangulation;
117+
118+
119+
// Defines the starting coordiante system
120+
ProjectionInfo pSource = ProjectionInfo.FromEpsgCode(sourceEpsgCode);
121+
// Defines the starting coordiante system
122+
ProjectionInfo pTarget = ProjectionInfo.FromEpsgCode(destinationEpsgCode);
123+
124+
125+
double[] inputPoints = triangulation.Positions.SelectMany(pt => new double[] { pt.X, pt.Y }).ToArray();
126+
Reproject.ReprojectPoints(inputPoints, null, pSource, pTarget, 0, triangulation.NumPositions);
127+
128+
for(int i = 0; i< triangulation.NumPositions; i++)
129+
{
130+
triangulation.Positions[i] = new Vector3((float)inputPoints[2 * i], (float)inputPoints[2 * i + 1], triangulation.Positions[i].Z);
131+
}
132+
return triangulation;
133+
134+
}
135+
public static TriangulationList<Vector3> ZScale(this TriangulationList<Vector3> triangulation, float zScale)
136+
{
137+
for (int i = 0; i < triangulation.NumPositions; i++)
138+
{
139+
Vector3 pos = triangulation.Positions[i];
140+
pos.Z *= zScale;
141+
triangulation.Positions[i] = pos;
142+
}
143+
return triangulation;
144+
}
145+
public static TriangulationList<Vector3> ToGlTFSpace(this TriangulationList<Vector3> triangulation)
146+
{
147+
for (int i = 0; i < triangulation.NumPositions; i++)
148+
{
149+
triangulation.Positions[i] = triangulation.Positions[i].ToGlTFSpace();
150+
}
151+
return triangulation;
152+
153+
}
112154
public static IEnumerable<(int Key, GeoPoint Point)> ReprojectTo(this IEnumerable<(int Key, GeoPoint Point)> points, int sourceEpsgCode, int destinationEpsgCode, int pointCount)
113155
{
114156
if (sourceEpsgCode == destinationEpsgCode)

DEM.Net.Core/Helpers/System/StopwatchLog.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace DEM.Net.Core
3131
public class StopwatchLog : Stopwatch
3232
{
3333
private readonly ILogger _logger;
34+
private TimeSpan _lastTime = TimeSpan.Zero;
3435
public static StopwatchLog StartNew(ILogger logger)
3536
{
3637
StopwatchLog sw = new StopwatchLog(logger);
@@ -39,29 +40,20 @@ public static StopwatchLog StartNew(ILogger logger)
3940
}
4041
public StopwatchLog(ILogger logger)
4142
{
42-
this._logger = logger;
43+
this._logger = logger;
4344
}
4445

4546
public void LogTime(string operationName = "Operation", LogLevel level = LogLevel.Information)
4647
{
4748
this.Stop();
4849
if (_logger.IsEnabled(level))
4950
{
50-
_logger.Log(level, $"{operationName} completed in {this.Elapsed:g}");
51+
_logger.Log(level, $"{operationName} completed in {(this.Elapsed - _lastTime).TotalMilliseconds:N1} ms (Total: {this.ElapsedMilliseconds:N1} ms)");
5152
}
53+
_lastTime = this.Elapsed;
5254
this.Start();
5355
}
54-
public void LogTime(string operationName, bool reset, LogLevel level = LogLevel.Information)
55-
{
56-
this.Stop();
57-
if (_logger.IsEnabled(level))
58-
{
59-
_logger.Log(level, $"{operationName} completed in {this.Elapsed:g}");
60-
}
61-
62-
if (reset) this.Restart(); else this.Start();
63-
64-
}
56+
6557
}
6658

6759
}

0 commit comments

Comments
 (0)