Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	DEM.Net.Core/Services/Adornments/AdornmentsService.cs
  • Loading branch information
xfischer committed Jan 13, 2021
2 parents 6458208 + d5af46e commit 3230998
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
8 changes: 8 additions & 0 deletions DEM.Net.Core/IO/Raster/netCDF/NetCdfFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public HeightMap GetHeightMap(FileMetadata metadata)
{
HeightMap heightMap = new HeightMap(metadata.Width, metadata.Height);
heightMap.Count = heightMap.Width * heightMap.Height;
heightMap.Minimum = 15000;
heightMap.Maximum = -15000;
var coords = new List<GeoPoint>(heightMap.Count);

MultipleDataResponse response = _dataset.GetMultipleData(
Expand All @@ -128,6 +130,8 @@ public HeightMap GetHeightMap(FileMetadata metadata)
float heightValue = (float)Convert.ChangeType(elevationsEnumerator.Current, typeof(float));

coords.Add(new GeoPoint(latitude, longitude, heightValue));
heightMap.Minimum = Math.Min(heightMap.Minimum, heightValue);
heightMap.Maximum = Math.Max(heightMap.Maximum, heightValue);

index++;
}
Expand Down Expand Up @@ -159,6 +163,8 @@ public HeightMap GetHeightMapInBBox(BoundingBox bbox, FileMetadata metadata, flo

heightMap = new HeightMap(xEast - xWest + 1, yNorth - ySouth + 1);
heightMap.Count = heightMap.Width * heightMap.Height;
heightMap.Minimum = 15000;
heightMap.Maximum = -15000;

// The netCDF storage is arranged as contiguous latitudinal bands.
MultipleDataResponse response = _dataset.GetMultipleData(
Expand Down Expand Up @@ -186,6 +192,8 @@ public HeightMap GetHeightMapInBBox(BoundingBox bbox, FileMetadata metadata, flo
float heightValue = (float)Convert.ChangeType(elevationsEnumerator.Current, typeof(float));

curRow.Add(new GeoPoint(latitude, longitude, heightValue));
heightMap.Minimum = Math.Min(heightMap.Minimum, heightValue);
heightMap.Maximum = Math.Max(heightMap.Maximum, heightValue);

index++;
}
Expand Down
5 changes: 3 additions & 2 deletions DEM.Net.Core/Services/Adornments/AdornmentsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ public TriangulationList<Vector3> CreateModelAdornments(DEMDataSet dataset, Imag
.Translate(new Vector3(projWidth / 2, -projHeight / 2 - projHeight * 0.05f, zCenter));

var text = this.CreateText($"{dataset.Attribution.Subject}: {dataset.Attribution.Text}{Environment.NewLine}{imageryProvider.Attribution.Subject}: {imageryProvider.Attribution.Text}", VectorsExtensions.CreateColor(255, 255, 255)).ToGlTFSpace();
var scale = ((projWidth - scaleBarSize) * 0.9f) / text.GetBoundingBox().Width;
var textWidth = (float)text.GetBoundingBox().Width;
var scale = (float)(((projWidth - scaleBarSize) * 0.9f) / textWidth);

text = text.Scale((float)scale)
.RotateX(-PI / 2)
.Translate(new Vector3(-projWidth * 0.25f, -projHeight * 0.55f, zCenter));
.Translate(new Vector3((-projWidth + textWidth * scale) / 2f, -projHeight * 0.55f, zCenter));
adornments += text;

return adornments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void IDEMDataSetIndex.Setup(DEMDataSet dataSet, string dataSetLocalDir)
{
_logger?.LogInformation($"Downloading index file from {dataSet.DataSource.IndexFilePath}... This file will be downloaded once and stored locally.");

HttpClient client = _httpClientFactory.CreateClient();
HttpClient client = _httpClientFactory == null ? new HttpClient() : _httpClientFactory.CreateClient();

using (HttpResponseMessage response = client.GetAsync(dataSet.DataSource.IndexFilePath).Result)
using (FileStream fs = new FileStream(vrtFileName, FileMode.Create, FileAccess.Write))
Expand Down Expand Up @@ -209,7 +209,7 @@ public void DownloadRasterFile(DemFileReport report, DEMDataSet dataset)
// Create directories if not existing
new FileInfo(report.LocalName).Directory.Create();

HttpClient client = _httpClientFactory.CreateClient();
HttpClient client = _httpClientFactory == null ? new HttpClient() : _httpClientFactory.CreateClient();

var contentbytes = client.GetByteArrayAsync(report.URL).Result;
using (FileStream fs = new FileStream(report.LocalName, FileMode.Create, FileAccess.Write))
Expand Down
19 changes: 15 additions & 4 deletions DEM.Net.Core/Services/Imagery/ImageryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class ImageryService
// calculate the size of the full bbox at increasing zoom levels
// until the full image would be greater than a tile
int zoom = 0;
int maxSize = 256 * minTilesPerImage; /* fixed to 256px to limit number of tiles */
int maxSize = 256 * minTilesPerImage; /* fixed to 256px to limit number of tiles */
do
{
zoom++;
Expand All @@ -106,7 +106,7 @@ public class ImageryService
bottomRight = TileUtils.PositionToGlobalPixel(new LatLong(bbox.yMin, bbox.xMax), zoom, provider.TileSize);
mapBbox = new BoundingBox(topLeft.X, bottomRight.X, topLeft.Y, bottomRight.Y);
} while (zoom < provider.MaxZoom
&& Math.Min(mapBbox.Width, mapBbox.Height) < maxSize );
&& Math.Min(mapBbox.Width, mapBbox.Height) < maxSize);

// now we have the minimum zoom without image
// we can know which tiles are needed
Expand Down Expand Up @@ -147,16 +147,27 @@ public TileRange DownloadTiles(TileRange tiles, ImageryProvider provider)
var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = provider.MaxDegreeOfParallelism };
var range = tiles.TilesInfo.ToList();
_logger?.LogInformation($"Downloading {range.Count} tiles...");
Parallel.ForEach(range, parallelOptions, tile =>
try
{
Parallel.ForEach(range, parallelOptions, (tile, state) =>
{
Uri tileUri = BuildUri(provider, tile.X, tile.Y, tile.Zoom);
var contentBytes = cache.GetTile(tileUri, provider, tile);
tiles.Add(new MapTile(contentBytes, provider.TileSize, tileUri, tile));
}
);
}
catch (AggregateException ex)
{
throw ex.GetInnerMostException();
}
catch (Exception)
{
throw;
}


swDownload.Stop();
_logger?.LogInformation($"DownloadImages done in : {swDownload.Elapsed:g}");
Expand Down
4 changes: 2 additions & 2 deletions DEM.Net.TestWinForm/DEM.Net.TestWinForm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotSpatial.Projections">
<Version>1.9.0</Version>
<PackageReference Include="DotSpatial.Projections.NetStandard">
<Version>1.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.Platforms">
<Version>2.2.0</Version>
Expand Down
14 changes: 13 additions & 1 deletion DEM.Net.TestWinForm/EchantillonsTestsServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using DEM.Net.Core;
using DEM.Net.Core.Datasets;

namespace DEM.Net.TestWinForm
{
Expand All @@ -15,7 +16,18 @@ public List<BeanPoint_internal> GetPointsTestsByBBox(string p_bbox, DEMDataSet d
List<BeanPoint_internal> v_pointsToTest = new List<BeanPoint_internal>();
try
{
RasterService v_rasterService = new RasterService(null);
// fix issue #86 to work with opentopography files without proper DI injection
RasterIndexServiceResolver rasterIndexServiceResolver = dataSourceType =>
{
switch (dataSourceType)
{
case DEMDataSourceType.GDALVrt:
return new GDALVRTFileService(null, null);
default:
throw new KeyNotFoundException(); // or maybe return null, up to you
}
};
RasterService v_rasterService = new RasterService(rasterIndexServiceResolver);
ElevationService v_elevationService = new ElevationService(v_rasterService, null);
BoundingBox v_bbox = GeometryService.GetBoundingBox(p_bbox);
v_elevationService.DownloadMissingFiles(dataset, v_bbox);
Expand Down

0 comments on commit 3230998

Please sign in to comment.