Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xfischer committed Feb 25, 2020
2 parents 1ab63b1 + 754988e commit c45b8e1
Show file tree
Hide file tree
Showing 27 changed files with 1,317 additions and 122 deletions.
1 change: 1 addition & 0 deletions DEM.Net.Core/Configuration/AppSecrets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class AppSecrets
public string NasaEarthDataLogin { get; set; }
public string NasaEarthDataPassword { get; set; }
public string MapBoxToken { get; set; }
public string MapTilerKey { get; set; }
}

}
1 change: 1 addition & 0 deletions DEM.Net.Core/DEM.Net.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Folder Include="Services\Voronoi\FortuneVoronoi\" />
<Folder Include="Model\Enums\" />
<Folder Include="Model\IntervisibilityReport\" />
<Folder Include="Helpers\System\" />
</ItemGroup>
<ItemGroup>
<None Include="DEMnet_64.png" Pack="true" PackagePath="\" />
Expand Down
5 changes: 5 additions & 0 deletions DEM.Net.Core/Helpers/MathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public static void Swap<T>(ref T a, ref T b)
b = temp;
}

public static IEnumerable<double> MetersToKm(this IEnumerable<double> meters)
{
return meters.Select(d => d * 0.001d);
}



}
Expand Down
7 changes: 5 additions & 2 deletions DEM.Net.Core/Helpers/PointsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ public static ElevationMetrics ComputeMetrics(this IList<GeoPoint> points, doubl
/// </summary>
/// <param name="points"></param>
/// <param name="sourceVerticalOffset">Vertical elevation offset at source point. The line of sight will be calculated from this point (set to 1.8 for simulate a human eye height)</param>
/// <param name="targetVerticalOffset"></param>
/// <returns></returns>
public static IntervisibilityMetrics ComputeVisibilityMetrics(this IList<GeoPoint> linePoints
, double sourceVerticalOffset = 0d, double? noDataValue = null)
, double sourceVerticalOffset = 0d
, double targetVerticalOffset = 0d
, double? noDataValue = null)
{
return GeometryService.ComputeVisibilityMetrics(linePoints, visibilityCheck: true, sourceVerticalOffset: sourceVerticalOffset, noDataValue);
return GeometryService.ComputeVisibilityMetrics(linePoints, visibilityCheck: true, sourceVerticalOffset: sourceVerticalOffset, targetVerticalOffset: targetVerticalOffset, noDataValue);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions DEM.Net.Core/Helpers/Reprojection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public static HeightMap ReprojectTo(this HeightMap heightMap, int sourceEpsgCode
return heightMap;
}

public static IEnumerable<GeoPoint> ReprojectGeodeticToCartesian(this IEnumerable<GeoPoint> points)
public static IEnumerable<GeoPoint> ReprojectGeodeticToCartesian(this IEnumerable<GeoPoint> points, int? count = null)
{
return points.ReprojectTo(SRID_GEODETIC, SRID_PROJECTED_MERCATOR, null);
return points.ReprojectTo(SRID_GEODETIC, SRID_PROJECTED_MERCATOR, count);
}
public static List<Gpx.GpxTrackPoint> ReprojectGeodeticToCartesian(this IEnumerable<Gpx.GpxTrackPoint> points)
{
return points.ReprojectTo(SRID_GEODETIC, SRID_PROJECTED_MERCATOR, null);
}


public static IEnumerable<GeoPoint> ReprojectTo(this IEnumerable<GeoPoint> points, int sourceEpsgCode, int destinationEpsgCode, int? pointCount = null)
{
Expand Down Expand Up @@ -208,7 +208,7 @@ private static GeoPoint ReprojectPoint(GeoPoint sourcePoint, ProjectionInfo sour
// Calls the reproject function that will transform the input location to the output locaiton
Reproject.ReprojectPoints(coords, new double[] { sourcePoint.Elevation.GetValueOrDefault(0) }, sourceProj, destProj, 0, 1);

return new GeoPoint(coords[1], coords[0], sourcePoint.Elevation);
return new GeoPoint(sourcePoint.Id, coords[1], coords[0], sourcePoint.Elevation);
}
private static Gpx.GpxTrackPoint ReprojectPoint(Gpx.GpxTrackPoint sourcePoint, ProjectionInfo sourceProj, ProjectionInfo destProj)
{
Expand Down
113 changes: 113 additions & 0 deletions DEM.Net.Core/Helpers/SexagesimalAngle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// SexagesimalAngle.cs
//
// Author:
// Xavier Fischer
//
// Copyright (c) 2020 Xavier Fischer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the right
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace DEM.Net.Core
{
public class SexagesimalAngle
{
public bool IsNegative { get; set; }
public int Degrees { get; set; }
public int Minutes { get; set; }
public int Seconds { get; set; }
public int Milliseconds { get; set; }



public static SexagesimalAngle FromDouble(double angleInDegrees)
{
//ensure the value will fall within the primary range [-180.0..+180.0]
while (angleInDegrees < -180.0)
angleInDegrees += 360.0;

while (angleInDegrees > 180.0)
angleInDegrees -= 360.0;

var result = new SexagesimalAngle();

//switch the value to positive
result.IsNegative = angleInDegrees < 0;
angleInDegrees = Math.Abs(angleInDegrees);

//gets the degree
result.Degrees = (int)Math.Floor(angleInDegrees);
var delta = angleInDegrees - result.Degrees;

//gets minutes and seconds
var seconds = (int)Math.Floor(3600.0 * delta);
result.Seconds = seconds % 60;
result.Minutes = (int)Math.Floor(seconds / 60.0);
delta = delta * 3600.0 - seconds;

//gets fractions
result.Milliseconds = (int)(1000.0 * delta);

return result;
}



public override string ToString()
{
var degrees = this.IsNegative
? -this.Degrees
: this.Degrees;

return string.Format(
"{0}° {1:00}' {2:00}\"",
degrees,
this.Minutes,
this.Seconds);
}



public string ToString(string format)
{
switch (format)
{
case "NS":
return string.Format(
"{0}° {1:00}' {2:00}\".{3:000} {4}",
this.Degrees,
this.Minutes,
this.Seconds,
this.Milliseconds,
this.IsNegative ? 'S' : 'N');

case "WE":
return string.Format(
"{0}° {1:00}' {2:00}\".{3:000} {4}",
this.Degrees,
this.Minutes,
this.Seconds,
this.Milliseconds,
this.IsNegative ? 'W' : 'E');

default:
throw new NotImplementedException();
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// IEnumerableWithCount.cs
// StopwatchLog.cs
//
// Author:
// Xavier Fischer
// Xavier Fischer
//
// Copyright (c) 2019
// Copyright (c) 2020 Xavier Fischer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// in the Software without restriction, including without limitation the right
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
Expand All @@ -22,41 +22,35 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.Extensions.Logging;

namespace DEM.Net.Core
{
public interface IEnumerableWithCount<out T> : IEnumerable<T>
public class StopwatchLog : Stopwatch
{
int Count { get; }
}
private readonly ILogger _logger;

public class EnumerableWithCount<T> : IEnumerableWithCount<T>
{
private readonly IEnumerable<T> _enumerable;
private readonly int _count;

public EnumerableWithCount(int count, IEnumerable<T> enumerable)
public static StopwatchLog StartNew(ILogger logger)
{
_enumerable = enumerable;
_count = count;
StopwatchLog sw = new StopwatchLog(logger);
sw.Start();
return sw;
}
public int Count => _count;

public IEnumerator<T> GetEnumerator()
public StopwatchLog(ILogger logger)
{
return _enumerable.GetEnumerator();
this._logger = logger;
}

IEnumerator IEnumerable.GetEnumerator()
public void LogTime(string operationName = "Operation", LogLevel level = LogLevel.Information)
{
return _enumerable.GetEnumerator();
this.Stop();
if (_logger.IsEnabled(level))
{
_logger.Log(level, $"{operationName} completed in {this.Elapsed:g}");
}
this.Start();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@ namespace DEM.Net.Core
{
public class TimeSpanBlock : IDisposable
{
private Stopwatch _sw;
private ILogger _logger;
private StopwatchLog _sw;
private readonly string _operationName;
private readonly LogLevel _logLevel;

public TimeSpanBlock(string operationName, ILogger logger)
public TimeSpanBlock(string operationName, ILogger logger, LogLevel logLevel = LogLevel.Information)
{
_sw = Stopwatch.StartNew();
_logger = logger;
_sw = StopwatchLog.StartNew(logger);
_operationName = operationName;
_logLevel = logLevel;
}

public void Dispose()
{
_logger.LogInformation($"{_operationName} completed in {_sw.ElapsedMilliseconds} ms");
_sw.Stop();
_sw.LogTime(_operationName, _logLevel);
}
}
}
File renamed without changes.
17 changes: 14 additions & 3 deletions DEM.Net.Core/Model/GeoPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace DEM.Net.Core
{
public class GeoPoint : IEquatable<GeoPoint>
{
public int? Id { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public double? Elevation { get; set; }
Expand All @@ -44,6 +45,11 @@ public class GeoPoint : IEquatable<GeoPoint>
/// </summary>
public double? DistanceFromOriginMeters { get; set; }

public GeoPoint(int? id, double latitude, double longitude, double? altitude)
: this(latitude, longitude, altitude)
{
this.Id = id;
}
public GeoPoint(double latitude, double longitude, double? altitude)
{
this.Latitude = latitude;
Expand All @@ -53,15 +59,18 @@ public GeoPoint(double latitude, double longitude, double? altitude)
}

public GeoPoint(double latitude, double longitude) : this(latitude, longitude, null) { }
public GeoPoint(int? id, double latitude, double longitude) : this(id, latitude, longitude, null) { }
public GeoPoint() : this(0, 0) { }

public GeoPoint Clone()
public GeoPoint Clone(double? newHeight = null)
{
return new GeoPoint
{
Id = this.Id
,
DistanceFromOriginMeters = this.DistanceFromOriginMeters
,
Elevation = this.Elevation
Elevation = newHeight ?? this.Elevation
,
Latitude = this.Latitude
,
Expand All @@ -83,7 +92,9 @@ public static GeoPoint Zero
}
public override string ToString()
{
return $"Lat/Lon: {Latitude} / {Longitude} "
return
(Id.HasValue ? $"Id: {Id.Value}, " : "")
+ $"Lat/Lon: {Latitude} / {Longitude} "
+ (Elevation.HasValue ? $", Elevation: {Elevation.Value:F2}" : "")
+ ((DistanceFromOriginMeters ?? 0) > 0 ? $", DistanceFromOrigin: {DistanceFromOriginMeters:F2}" : "");
}
Expand Down
7 changes: 7 additions & 0 deletions DEM.Net.Core/Model/Imagery/UrlModel.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 System;

namespace DEM.Net.Core.Imagery
{
public class UrlModel
Expand All @@ -39,5 +41,10 @@ public UrlModel(string urlFormat, string[] servers)
this.UrlFormat = urlFormat;
this.Servers = servers;
}

public static implicit operator UrlModel(string url)
{
return new UrlModel(url, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class IntervisibilityReport
public GeoPoint Origin { get; internal set; }
public GeoPoint Target { get; internal set; }
public double OriginVerticalOffset { get; internal set; }
public double TargetVerticalOffset { get; internal set; }
public bool HasObstacles => Metrics?.Intervisible == false;
public int ObstacleCount => Metrics?.Obstacles?.Count ?? 0;
public List<GeoPoint> GeoPoints { get; internal set; }
Expand All @@ -48,13 +49,15 @@ public void ClearPoints()
GeoPoints = null;
}

public IntervisibilityReport(List<GeoPoint> pointsWithElevation, IntervisibilityMetrics visibilityMetrics, bool includeAllPoints = false, double originVerticalOffset = 0d)
public IntervisibilityReport(List<GeoPoint> pointsWithElevation, IntervisibilityMetrics visibilityMetrics, bool includeAllPoints = false, double originVerticalOffset = 0d
, double targetVerticalOffset = 0d)
{
this.Origin = pointsWithElevation.First();
this.Target = pointsWithElevation.Last();
this.Metrics = visibilityMetrics;
this.GeoPoints = pointsWithElevation;
this.OriginVerticalOffset = originVerticalOffset;
this.TargetVerticalOffset = targetVerticalOffset;
}
}
}

0 comments on commit c45b8e1

Please sign in to comment.