Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xfischer committed Sep 4, 2020
2 parents 12d99be + be42914 commit b46ed2d
Show file tree
Hide file tree
Showing 25 changed files with 906 additions and 124 deletions.
4 changes: 4 additions & 0 deletions DEM.Net.Core/Configuration/DEMNetOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class DEMNetOptions

public float RenderGpxTrailWidthMeters { get; set; } = 15f;
public List<ImageryProvider> ImageryProviders { get; set; } = new List<ImageryProvider>();

public bool UseImageryDiskCache { get; set; } = true;
public float ImageryDiskCacheExpirationHours { get; set; } = 5f;

public float ImageryCacheExpirationMinutes { get; set; } = 5f;
}
}
4 changes: 4 additions & 0 deletions DEM.Net.Core/Configuration/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DEM.Net.Core.Datasets;
using DEM.Net.Core.EarthData;
using DEM.Net.Core.Imagery;
using DEM.Net.Core.Services.Imagery;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using System;
Expand All @@ -16,6 +17,7 @@ public static class ServiceCollectionExtension
public static IServiceCollection AddDemNetCore(this IServiceCollection services)
{
services.AddMemoryCache();
services.AddHttpClient();

services.AddSingleton<GDALVRTFileService>();
services.AddSingleton<LocalFileSystemIndex>();
Expand All @@ -42,8 +44,10 @@ public static IServiceCollection AddDemNetCore(this IServiceCollection services)
.AddSingleton<RasterService>()
.AddTransient<ElevationService>()
.AddTransient<MeshService>()
.AddTransient<ImageryCache>()
.AddSingleton<ImageryService>();


return services;
}
}
Expand Down
32 changes: 19 additions & 13 deletions DEM.Net.Core/DEM.Net.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>DEM.Net.Core</PackageId>
<Version>0.2.7.1</Version>
<Version>0.2.7.2</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>Various bug fixes, OSM pipeline, glTF models centered on origin</PackageReleaseNotes>
<PackageReleaseNotes>
Code refactor (removed useless interfaces, readability)
Lines bulk elevation (better performance)
Imagery disk cache
Procedural mesh generation for axis, cylinder, cones
</PackageReleaseNotes>
<PackageTags>DEM, Terrain, Elevation</PackageTags>
<Title>DEM.Net</Title>
<Product>DEM.Net</Product>
Expand All @@ -19,8 +24,8 @@
</PackageLicenseExpression>
<PackageIconUrl>https://raw.githubusercontent.com/dem-net/Resources/master/images/DEMnet_512.png</PackageIconUrl>
<PackageIcon>DEMnet_64.png</PackageIcon>
<AssemblyVersion>0.2.7.1</AssemblyVersion>
<FileVersion>0.2.7.1</FileVersion>
<AssemblyVersion>0.2.7.2</AssemblyVersion>
<FileVersion>0.2.7.2</FileVersion>
<UserSecretsId>a9a5d6e1-3bb8-4dfd-ac6a-861f60dada50</UserSecretsId>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
Expand Down Expand Up @@ -59,9 +64,9 @@
</ItemGroup>
<!-- .NET Standard 2.0 references, compilation flags and build options -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.5" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Services\Voronoi\BeanTopologie\**" />
Expand Down Expand Up @@ -89,14 +94,15 @@
<PackageReference Include="DotSpatial.Projections.NetStandard" Version="1.0.0" />
<PackageReference Include="GeoAPI.CoordinateSystems" Version="1.7.5" />
<PackageReference Include="GeoAPI.Core" Version="1.7.5" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageReference Include="NetTopologySuite" Version="1.15.3" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.5" />
<PackageReference Include="NetTopologySuite.Diagnostics.Tracing" Version="0.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="SDSLite" Version="1.4.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta0007" />
<PackageReference Include="SixLabors.Shapes" Version="1.0.0-beta0009" />
Expand Down
68 changes: 67 additions & 1 deletion DEM.Net.Core/Helpers/HeightMapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using DEM.Net.Core.Gpx;
using SixLabors.ImageSharp.ColorSpaces;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -62,6 +64,20 @@ public static HeightMap CenterOnOrigin(this HeightMap heightMap, out Matrix4x4 t
, bbox.zMin - zOriginOffset, bbox.zMax - zOriginOffset);
return heightMap;
}
public static HeightMap CenterOnOrigin(this HeightMap heightMap, GeoPoint origin)
{
//Logger.Info("CenterOnOrigin...");
var bbox = heightMap.BoundingBox;

heightMap.Coordinates = heightMap.Coordinates.Translate(-origin.Longitude, -origin.Latitude, -origin.Elevation ?? 0);



heightMap.BoundingBox = new BoundingBox(bbox.xMin - origin.Longitude, bbox.xMax - origin.Longitude
, bbox.yMin - origin.Latitude, bbox.yMax - origin.Latitude
, bbox.zMin - origin.Elevation ?? 0, bbox.zMax - origin.Elevation ?? 0);
return heightMap;
}
/// <summary>
/// Centers height map on origin
/// </summary>
Expand Down Expand Up @@ -113,6 +129,10 @@ public static IEnumerable<GeoPoint> CenterOnOrigin(this IEnumerable<GeoPoint> po

return points.CenterOnOrigin(bbox);
}
public static IEnumerable<GeoPoint> CenterOnOrigin(this IEnumerable<GeoPoint> points, GeoPoint origin)
{
return points.Translate(-origin.Longitude, -origin.Latitude, -origin.Elevation ?? 0);
}

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

return points;
}

public static GeoPoint CenterOnOrigin(this GeoPoint point, 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;
point = point.Translate(-xOriginOffset, -yOriginOffset, centerOnZ ? -bbox.zMin : 0); // Set minZ = 0

return point;
}
/// <summary>
/// Translate points
/// </summary>
Expand All @@ -138,7 +169,7 @@ public static IEnumerable<GeoPoint> CenterOnOrigin(this IEnumerable<GeoPoint> po
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns></returns>
private static IEnumerable<GeoPoint> Translate(this IEnumerable<GeoPoint> points, double x, double y, double z = 0)
public static IEnumerable<GeoPoint> Translate(this IEnumerable<GeoPoint> points, double x, double y, double z = 0)
{
//Logger.Info("Translate...");
foreach (var pt in points)
Expand All @@ -151,6 +182,18 @@ private static IEnumerable<GeoPoint> Translate(this IEnumerable<GeoPoint> points
}
//Logger.Info("Translate done...");
}
public static GeoPoint Translate(this GeoPoint point, double x, double y, double z = 0)
{
//Logger.Info("Translate...");

var p = point.Clone();
p.Latitude += y;
p.Longitude += x;
p.Elevation += z;
return p;

//Logger.Info("Translate done...");
}

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

}/// <summary>
/// Scale given points
/// </summary>
/// <param name="points"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns></returns>
public static GeoPoint Scale(this GeoPoint pt, float x = 1f, float y = 1f, float z = 1f)
{
var pout = pt.Clone();
pout.Longitude *= x;
pout.Latitude *= y;
pout.Elevation *= z;
return pout;
}

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

return heightMap;
}
public static HeightMap Translate(this HeightMap heightMap, GeoPoint pt)
{
heightMap.Coordinates = heightMap.Coordinates.Translate(pt.Longitude, pt.Latitude, pt.Elevation ?? 0);
heightMap.Minimum += (float)(pt.Elevation ?? 0);
heightMap.Maximum += (float)(pt.Elevation ?? 0);

return heightMap;
}

/// <summary>
/// Verticaly translates points
Expand Down
42 changes: 42 additions & 0 deletions DEM.Net.Core/Helpers/Reprojection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using DEM.Net.Core.Imagery;
Expand Down Expand Up @@ -109,6 +110,47 @@ public static IEnumerable<GeoPoint> ReprojectTo(this IEnumerable<GeoPoint> point

}
}
public static TriangulationList<Vector3> ReprojectTo(this TriangulationList<Vector3> triangulation, int sourceEpsgCode, int destinationEpsgCode)
{
if (sourceEpsgCode == destinationEpsgCode)
return triangulation;


// Defines the starting coordiante system
ProjectionInfo pSource = ProjectionInfo.FromEpsgCode(sourceEpsgCode);
// Defines the starting coordiante system
ProjectionInfo pTarget = ProjectionInfo.FromEpsgCode(destinationEpsgCode);


double[] inputPoints = triangulation.Positions.SelectMany(pt => new double[] { pt.X, pt.Y }).ToArray();
Reproject.ReprojectPoints(inputPoints, null, pSource, pTarget, 0, triangulation.NumPositions);

for(int i = 0; i< triangulation.NumPositions; i++)
{
triangulation.Positions[i] = new Vector3((float)inputPoints[2 * i], (float)inputPoints[2 * i + 1], triangulation.Positions[i].Z);
}
return triangulation;

}
public static TriangulationList<Vector3> ZScale(this TriangulationList<Vector3> triangulation, float zScale)
{
for (int i = 0; i < triangulation.NumPositions; i++)
{
Vector3 pos = triangulation.Positions[i];
pos.Z *= zScale;
triangulation.Positions[i] = pos;
}
return triangulation;
}
public static TriangulationList<Vector3> ToGlTFSpace(this TriangulationList<Vector3> triangulation)
{
for (int i = 0; i < triangulation.NumPositions; i++)
{
triangulation.Positions[i] = triangulation.Positions[i].ToGlTFSpace();
}
return triangulation;

}
public static IEnumerable<(int Key, GeoPoint Point)> ReprojectTo(this IEnumerable<(int Key, GeoPoint Point)> points, int sourceEpsgCode, int destinationEpsgCode, int pointCount)
{
if (sourceEpsgCode == destinationEpsgCode)
Expand Down
18 changes: 5 additions & 13 deletions DEM.Net.Core/Helpers/System/StopwatchLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace DEM.Net.Core
public class StopwatchLog : Stopwatch
{
private readonly ILogger _logger;
private TimeSpan _lastTime = TimeSpan.Zero;
public static StopwatchLog StartNew(ILogger logger)
{
StopwatchLog sw = new StopwatchLog(logger);
Expand All @@ -39,29 +40,20 @@ public static StopwatchLog StartNew(ILogger logger)
}
public StopwatchLog(ILogger logger)
{
this._logger = logger;
this._logger = logger;
}

public void LogTime(string operationName = "Operation", LogLevel level = LogLevel.Information)
{
this.Stop();
if (_logger.IsEnabled(level))
{
_logger.Log(level, $"{operationName} completed in {this.Elapsed:g}");
_logger.Log(level, $"{operationName} completed in {(this.Elapsed - _lastTime).TotalMilliseconds:N1} ms (Total: {this.ElapsedMilliseconds:N1} ms)");
}
_lastTime = this.Elapsed;
this.Start();
}
public void LogTime(string operationName, bool reset, LogLevel level = LogLevel.Information)
{
this.Stop();
if (_logger.IsEnabled(level))
{
_logger.Log(level, $"{operationName} completed in {this.Elapsed:g}");
}

if (reset) this.Restart(); else this.Start();

}

}

}

0 comments on commit b46ed2d

Please sign in to comment.