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 5, 2021
2 parents cebd2da + d4dab24 commit 0df845f
Show file tree
Hide file tree
Showing 28 changed files with 233 additions and 208 deletions.
7 changes: 2 additions & 5 deletions DEM.Net.Core/DEM.Net.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,22 @@
<ItemGroup>
<PackageReference Include="BitMiracle.LibTiff.NET" Version="2.4.639" />
<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.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NetTopologySuite" Version="1.15.3" />
<PackageReference Include="NetTopologySuite" Version="2.1.0" />
<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.3" />
<PackageReference Include="SDSCore" Version="1.2.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta0007" />
<PackageReference Include="SixLabors.Shapes" Version="1.0.0-beta0009" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions DEM.Net.Core/Model/Datasets/DEMDataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override string ToString()
Description = "Shuttle Radar Topography Mission (SRTM GL3) Global 90m",
PublicUrl = "http://opentopo.sdsc.edu/raster?opentopoID=OTSRTM.042013.4326.1",
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),
FileFormat = new DEMFileDefinition("Nasa SRTM HGT", DEMFileType.GEOTIFF, ".tif", DEMFileRegistrationMode.Grid),
ResolutionMeters = 90,
ResolutionArcSeconds = 3,
PointsPerDegree = 1200,
Expand All @@ -88,7 +88,7 @@ public override string ToString()
Description = "Shuttle Radar Topography Mission (SRTM GL1) Global 30m",
PublicUrl = "http://opentopo.sdsc.edu/raster?opentopoID=OTSRTM.082015.4326.1",
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),
FileFormat = new DEMFileDefinition("Nasa SRTM HGT", DEMFileType.GEOTIFF, ".tif", DEMFileRegistrationMode.Grid),
ResolutionMeters = 30,
ResolutionArcSeconds = 1,
PointsPerDegree = 3600,
Expand Down
1 change: 0 additions & 1 deletion DEM.Net.Core/Model/Imagery/TileRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using GeoAPI.Operation.Buffer;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down
27 changes: 27 additions & 0 deletions DEM.Net.Core/Model/Imagery/Tools/TileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,33 @@ public static string[] GetQuadkeysInBoundingBox(BoundingBox bounds, int zoom, in
return keys.ToArray();
}

/// <summary>
/// Calculates the tile quadkey strings that are within a bounding box at a specific zoom level.
/// </summary>
/// <param name="bounds">A bounding box defined as an array of numbers in the format of [west, south, east, north].</param>
/// <param name="zoom">Zoom level to calculate tiles for.</param>
/// <param name="tileSize">The size of the tiles in the tile pyramid.</param>
/// <returns>A list of quadkey strings.</returns>
public static IEnumerable<MapTileInfo> GetTilesInBoundingBox(BoundingBox bounds, int zoom, int tileSize)
{
var keys = new System.Collections.Generic.List<string>();

if (bounds != null)
{
PositionToTileXY(new LatLong(bounds.yMax, bounds.xMin), zoom, tileSize, out int tlX, out int tlY);
PositionToTileXY(new LatLong(bounds.yMin, bounds.xMax), zoom, tileSize, out int brX, out int brY);

for (int x = tlX; x <= brX; x++)
{
for (int y = tlY; y <= brY; y++)
{
yield return new MapTileInfo(x, y, zoom, tileSize);
}
}
}

}

/// <summary>
/// Calculates the bounding box of a tile.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions DEM.Net.Core/Model/Raster/FileMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ public BoundingBox BoundingBox
{
if (_boundingBox == null)
{
double xmin = Math.Min(DataStartLon, DataEndLon);
double xmax = Math.Max(DataStartLon, DataEndLon);
double ymin = Math.Min(DataStartLat, DataEndLat);
double ymax = Math.Max(DataStartLat, DataEndLat);
_boundingBox = new BoundingBox(xmin, xmax, ymin, ymax);
_boundingBox = new BoundingBox(
Math.Min(DataStartLon, DataEndLon),
Math.Max(DataStartLon, DataEndLon),
Math.Min(DataStartLat, DataEndLat),
Math.Max(DataStartLat, DataEndLat));
}
return _boundingBox;
}
Expand Down
2 changes: 1 addition & 1 deletion DEM.Net.Core/Services/CourbesNiveau/BeanFractionCourbe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BeanFractionCourbe
public string p00_codeFractionCourbe { get; set; }
public BeanPointDecoup_internal p01_point_1 { get; set; }
public BeanPointDecoup_internal p02_point_2 { get; set; }
//public IGeometry p10_geom { get; set; }
//public Geometry p10_geom { get; set; }
public string p20_valeurCourbe { get; set; }
public bool p11_estLigneSinonPoint_vf { get; set; }
}
Expand Down
23 changes: 12 additions & 11 deletions DEM.Net.Core/Services/Elevation/ElevationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
using System.Text;
using System.Threading.Tasks;
using DEM.Net.Core.Interpolation;
using GeoAPI.Geometries;
using Microsoft.Extensions.Logging;
using NetTopologySuite.Geometries;

namespace DEM.Net.Core
{
Expand Down Expand Up @@ -169,7 +169,7 @@ private void DownloadMissingFiles_FromReport(IEnumerable<DemFileReport> report,
/// <returns></returns>
public List<GeoPoint> GetLineGeometryElevation(string lineWKT, DEMDataSet dataSet, InterpolationMode interpolationMode = InterpolationMode.Bilinear, NoDataBehavior behavior = NoDataBehavior.SetToZero)
{
IGeometry geom = GeometryService.ParseWKTAsGeometry(lineWKT);
Geometry geom = GeometryService.ParseWKTAsGeometry(lineWKT);

if (geom.OgcGeometryType == OgcGeometryType.MultiLineString)
{
Expand All @@ -188,7 +188,7 @@ public List<GeoPoint> GetLineGeometryElevation(string lineWKT, DEMDataSet dataSe
/// <param name="behavior">Action to use when no data is found in dataset</param>
/// <remarks>Output can be BIG, as all elevations will be returned.</remarks>
/// <returns></returns>
public List<GeoPoint> GetLineGeometryElevation(IGeometry lineStringGeometry, DEMDataSet dataSet, List<FileMetadata> segTiles, List<GeoSegment> nsLines, List<GeoSegment> weLines, InterpolationMode interpolationMode = InterpolationMode.Bilinear, NoDataBehavior behavior = NoDataBehavior.SetToZero)
public List<GeoPoint> GetLineGeometryElevation(Geometry lineStringGeometry, DEMDataSet dataSet, List<FileMetadata> segTiles, List<GeoSegment> nsLines, List<GeoSegment> weLines, InterpolationMode interpolationMode = InterpolationMode.Bilinear, NoDataBehavior behavior = NoDataBehavior.SetToZero)
{
if (lineStringGeometry == null || lineStringGeometry.IsEmpty)
return null;
Expand Down Expand Up @@ -257,7 +257,7 @@ public List<GeoPoint> GetLineGeometryElevation(IGeometry lineStringGeometry, DEM
/// <param name="behavior">Action to use when no data is found in dataset</param>
/// <remarks>Output can be BIG, as all elevations will be returned.</remarks>
/// <returns></returns>
public List<GeoPoint> GetLineGeometryElevation(IGeometry lineStringGeometry, DEMDataSet dataSet, InterpolationMode interpolationMode = InterpolationMode.Bilinear, NoDataBehavior behavior = NoDataBehavior.SetToZero)
public List<GeoPoint> GetLineGeometryElevation(Geometry lineStringGeometry, DEMDataSet dataSet, InterpolationMode interpolationMode = InterpolationMode.Bilinear, NoDataBehavior behavior = NoDataBehavior.SetToZero)
{
if (lineStringGeometry == null || lineStringGeometry.IsEmpty)
return null;
Expand Down Expand Up @@ -330,7 +330,7 @@ public List<GeoPoint> GetLineGeometryElevation(IEnumerable<GeoPoint> lineGeoPoin
if (lineGeoPoints == null)
throw new ArgumentNullException(nameof(lineGeoPoints), "Point list is null");

IGeometry geometry = GeometryService.ParseGeoPointAsGeometryLine(lineGeoPoints);
Geometry geometry = GeometryService.ParseGeoPointAsGeometryLine(lineGeoPoints);

return GetLineGeometryElevation(geometry, dataSet, interpolationMode, behavior);
}
Expand All @@ -346,7 +346,7 @@ public List<GeoPoint> GetLineGeometryElevation(IEnumerable<GeoPoint> lineGeoPoin
/// <returns></returns>
public Dictionary<TKey, List<GeoPoint>> GetLinesGeometryElevation<TKey>(Dictionary<TKey, List<GeoPoint>> lineGeoPoints, DEMDataSet dataSet, InterpolationMode interpolationMode = InterpolationMode.Bilinear, NoDataBehavior behavior = NoDataBehavior.SetToZero)
{
List<IGeometry> geoLines = lineGeoPoints.Select(l => GeometryService.ParseGeoPointAsGeometryLine(l.Value)).ToList();
List<Geometry> geoLines = lineGeoPoints.Select(l => GeometryService.ParseGeoPointAsGeometryLine(l.Value)).ToList();
var bbox = GeometryService.GetBoundingBox(geoLines.First());
foreach (var linePts in geoLines.Skip(1))
{
Expand All @@ -362,14 +362,14 @@ public List<GeoPoint> GetLineGeometryElevation(IEnumerable<GeoPoint> lineGeoPoin
//Dictionary<TKey, List<GeoPoint>> outLines = new Dictionary<TKey, List<GeoPoint>>(lineGeoPoints.Count);
//foreach (var linePts in lineGeoPoints)
//{
// IGeometry geometry = GeometryService.ParseGeoPointAsGeometryLine(linePts.Value);
// Geometry geometry = GeometryService.ParseGeoPointAsGeometryLine(linePts.Value);

// outLines.Add(linePts.Key, GetLineGeometryElevation(geometry, dataSet, tiles, nsLines, weLines, interpolationMode, behavior));
//}
ConcurrentDictionary<TKey, List<GeoPoint>> outLines = new ConcurrentDictionary<TKey, List<GeoPoint>>();
Parallel.ForEach(lineGeoPoints, linePts =>
{
IGeometry geometry = GeometryService.ParseGeoPointAsGeometryLine(linePts.Value);
Geometry geometry = GeometryService.ParseGeoPointAsGeometryLine(linePts.Value);
if (!outLines.TryAdd(linePts.Key, GetLineGeometryElevation(geometry, dataSet, tiles, nsLines, weLines, interpolationMode, behavior)))
{
Expand Down Expand Up @@ -1237,9 +1237,10 @@ public bool IsPointInTile(FileMetadata tileMetadata, double lat, double lon)
{
BoundingBox tileBbox = tileMetadata.BoundingBox;

bool isInsideX = (tileBbox.xMax >= lon && tileBbox.xMin <= lon);
bool isInsideY = (tileBbox.yMax >= lat && tileBbox.yMin <= lat);
return isInsideX && isInsideY;
return
(tileBbox.xMax >= lon && tileBbox.xMin <= lon) // isInsideX
&& (tileBbox.yMax >= lat && tileBbox.yMin <= lat); // isInsideY

}
// is the tile a tile just next to the tile the point is in ?
private bool IsPointInAdjacentTile(FileMetadata tile, GeoPoint point)
Expand Down
33 changes: 16 additions & 17 deletions DEM.Net.Core/Services/Geometry/GeometryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
using NetTopologySuite.Operation.Union;
Expand All @@ -45,7 +44,7 @@ public static class GeometryService
private const double RADIAN = Math.PI / 180;

private static WKTReader _wktReader;
private static IGeometryFactory _factory;
private static GeometryFactory _factory;

static GeometryService()
{
Expand All @@ -58,10 +57,10 @@ static GeometryService()
/// </summary>
/// <param name="geomWKT">Geometry Well Known Text</param>
/// <param name="srid">SRID of geomtery (defaults to 4326)</param>
/// <returns>NetTopology IGeometry instance</returns>
public static IGeometry ParseWKTAsGeometry(string geomWKT, int srid = WGS84_SRID)
/// <returns>NetTopology Geometry instance</returns>
public static Geometry ParseWKTAsGeometry(string geomWKT, int srid = WGS84_SRID)
{
IGeometry geometry = _wktReader.Read(geomWKT);
Geometry geometry = _wktReader.Read(geomWKT);
geometry.SRID = srid;
return geometry;
}
Expand All @@ -72,15 +71,15 @@ public static IGeometry ParseWKTAsGeometry(string geomWKT, int srid = WGS84_SRID
/// <returns><see cref="BoundingBox"/></returns>
public static BoundingBox GetBoundingBox(string geomWKT)
{
IGeometry geom = ParseWKTAsGeometry(geomWKT);
Geometry geom = ParseWKTAsGeometry(geomWKT);
return geom.GetBoundingBox();
}
/// <summary>
/// Extension method. Returns the bounding box for a geometry instance
/// </summary>
/// <param name="geom">NetTopology IGeometry instance</param>
/// <param name="geom">NetTopology Geometry instance</param>
/// <returns></returns>
public static BoundingBox GetBoundingBox(this IGeometry geom)
public static BoundingBox GetBoundingBox(this Geometry geom)
{
Envelope envelope = geom.EnvelopeInternal;

Expand Down Expand Up @@ -137,11 +136,11 @@ public static BoundingBox GetBoundingBox(this GeoSegment segment)
/// </summary>
/// <param name="points"></param>
/// <returns></returns>
public static IGeometry ParseGeoPointAsGeometryLine(IEnumerable<GeoPoint> points)
public static Geometry ParseGeoPointAsGeometryLine(IEnumerable<GeoPoint> points)
{
return new LineString(points.Select(pt => new Coordinate(pt.Longitude, pt.Latitude)).ToArray()) { SRID = WGS84_SRID };
}
public static IGeometry ParseGeoPointAsGeometryLine(params GeoPoint[] points)
public static Geometry ParseGeoPointAsGeometryLine(params GeoPoint[] points)
{
return new LineString(points.Select(pt => new Coordinate(pt.Longitude, pt.Latitude)).ToArray()) { SRID = WGS84_SRID };
}
Expand Down Expand Up @@ -410,7 +409,7 @@ public static double GetLineLength_Meters(List<GeoPoint> points)
/// </summary>
/// <param name="geom"></param>
/// <returns></returns>
public static IEnumerable<IGeometry> Geometries(this IGeometry geom)
public static IEnumerable<Geometry> Geometries(this Geometry geom)
{
for (int i = 0; i < geom.NumGeometries; i++)
{
Expand All @@ -424,7 +423,7 @@ public static IEnumerable<IGeometry> Geometries(this IGeometry geom)
/// <param name="lineGeom"></param>
/// <returns></returns>
/// <remarks>Only iterates if geometry is a line string</remarks>
public static IEnumerable<GeoSegment> Segments(this IGeometry lineGeom)
public static IEnumerable<GeoSegment> Segments(this Geometry lineGeom)
{

if (lineGeom == null || lineGeom.IsEmpty)
Expand Down Expand Up @@ -468,11 +467,11 @@ public static GeoPoint ToGeoPoint(this Coordinate coord)
return new GeoPoint(coord.Y, coord.X);
}

public static IGeometry ToPolygon(this BoundingBox boundingBox)
public static Geometry ToPolygon(this BoundingBox boundingBox)
{
return new Polygon(boundingBox.ToRing(), _factory);
}
public static ILinearRing ToRing(this BoundingBox boundingBox)
public static LinearRing ToRing(this BoundingBox boundingBox)
{
if (boundingBox == null)
throw new ArgumentNullException(nameof(boundingBox));
Expand All @@ -491,16 +490,16 @@ public static bool IsCovered(this BoundingBox bbox, IEnumerable<BoundingBox> bbo
if (bboxTiles == null || !bboxTiles.Any())
return false;

IGeometry bboxPoly = bbox.ToPolygon();
IGeometry tilesPolygon = UnaryUnionOp.Union(bboxTiles.Select(t => t.ToPolygon()).ToList());
Geometry bboxPoly = bbox.ToPolygon();
Geometry tilesPolygon = UnaryUnionOp.Union(bboxTiles.Select(t => t.ToPolygon()).ToList());

var inside = tilesPolygon.Contains(bboxPoly);

if (inside)
return inside;
else
{
tilesPolygon = UnaryUnionOp.Union(bboxTiles.Select(t => (IGeometry)(new LineString(t.ToRing().Coordinates))).ToList());
tilesPolygon = UnaryUnionOp.Union(bboxTiles.Select(t => (Geometry)(new LineString(t.ToRing().Coordinates))).ToList());

var dbgString = @"declare @b geometry = geometry::STGeomFromText('{bbox.WKT}',2154)
select @b,'Bbox'";
Expand Down
4 changes: 2 additions & 2 deletions DEM.Net.Core/Services/Lab/BeanFacette_internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -41,7 +41,7 @@ public class BeanFacette_internal
public List<BeanPoint_internal> p01_pointsDeFacette { get; set; }
public List<BeanArc_internal> p02_arcs { get; set; }
public bool p03_estVerticale_vf { get; set; }
public IGeometry p04_geomFacette { get; set; }
public Geometry p04_geomFacette { get; set; }
//
public List<BeanPoint_internal> p10_pointsInclus { get; set; }
//
Expand Down
2 changes: 1 addition & 1 deletion DEM.Net.Core/Services/Lab/CalculServicesVoronoi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
using System.Linq;
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using DEM.Net.Core.Voronoi;
using NetTopologySuite.Geometries;
using Point = NetTopologySuite.Geometries.Point;
Expand Down
6 changes: 3 additions & 3 deletions DEM.Net.Core/Services/Lab/CalculServices_Medium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// THE SOFTWARE.

using DEM.Net.Core.Services.VisualisationServices;
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -2028,9 +2028,9 @@ public void RecalculFacettes(ref BeanTopologieFacettes p_topol)
}
}

public IGeometry GetGeometryPolygoneFacetteEtOrdonnePointsFacette(ref BeanFacette_internal p_facette, ref BeanTopologieFacettes p_topologieFacette)
public Geometry GetGeometryPolygoneFacetteEtOrdonnePointsFacette(ref BeanFacette_internal p_facette, ref BeanTopologieFacettes p_topologieFacette)
{
IGeometry v_geom = null;
Geometry v_geom = null;
try
{
if(p_facette.p02_arcs==null || p_facette.p02_arcs.Count<3)
Expand Down

0 comments on commit 0df845f

Please sign in to comment.