Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/dem-net/DEM.Net into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	DEM.Net.glTF/MeshReducer/MeshReducer.cs
#	DEM.Net.glTF/gtlfSharp/SharpGltfService.cs
  • Loading branch information
xfischer committed Aug 10, 2021
2 parents ae905f1 + c718c62 commit 8090059
Show file tree
Hide file tree
Showing 26 changed files with 242 additions and 794 deletions.
5 changes: 5 additions & 0 deletions DEM.Net.Core/Configuration/DEMNetOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ public class DEMNetOptions
public float ImageryCacheExpirationMinutes { get; set; } = 5f;

public bool PowerOfTwoImages { get; set; } = false;

public string LocalDirectory { get; set; } = null;

// Set to true for ensure tiles stitch correctly when tiling
public bool ReduceMeshPreserveEdges { get; set; } = false;
}
}
1 change: 1 addition & 0 deletions DEM.Net.Core/Configuration/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static IServiceCollection AddDemNetCore(this IServiceCollection services)
{
services.AddMemoryCache();
services.AddHttpClient();
services.AddOptions();

services.AddSingleton<GDALVRTFileService>();
services.AddSingleton<LocalFileSystemIndex>();
Expand Down
15 changes: 7 additions & 8 deletions DEM.Net.Core/DEM.Net.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>DEM.Net.Core</PackageId>
<Version>0.2.8.0</Version>
<Version>0.3.2.0</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>- OpenTopography endpoints updated
- Disabled GEBCO 2020
- New STL transforms
- Triangulation Clone()</PackageReleaseNotes>
<PackageReleaseNotes>
LocalDirectory is configuration in DEMNetOptions
</PackageReleaseNotes>
<PackageTags>DEM, Terrain, Elevation</PackageTags>
<Title>DEM.Net</Title>
<Product>DEM.Net</Product>
Expand All @@ -22,10 +21,10 @@
</PackageLicenseExpression>
<PackageIconUrl>https://raw.githubusercontent.com/dem-net/Resources/master/images/DEMnet_512.png</PackageIconUrl>
<PackageIcon>DEMnet_64.png</PackageIcon>
<AssemblyVersion>0.2.7.4</AssemblyVersion>
<FileVersion>0.2.7.4</FileVersion>
<AssemblyVersion>0.3.2.0</AssemblyVersion>
<FileVersion>0.3.2.0</FileVersion>
<UserSecretsId>a9a5d6e1-3bb8-4dfd-ac6a-861f60dada50</UserSecretsId>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand Down
4 changes: 4 additions & 0 deletions DEM.Net.Core/Helpers/VectorsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public static Vector3 AsVector3(this GeoPoint geoPoint)
{
return new Vector3((float)geoPoint.Longitude, (float)geoPoint.Latitude, (float)(geoPoint.Elevation ?? 0D));
}
public static GeoPoint AsGeoPoint(this Vector3 vector3)
{
return new GeoPoint(vector3.Y, vector3.X, vector3.Z);
}
public static Vector3 ToGlTFSpace(this Vector3 vector3)
{
return new Vector3(vector3.X, vector3.Z, -vector3.Y);
Expand Down
31 changes: 11 additions & 20 deletions DEM.Net.Core/IO/Raster/GeoTiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public FileMetadata ParseMetaData(DEMFileDefinition format)
// Add other information about the data
metadata.SampleFormat = sampleFormat[0].Value.ToString();
// TODO: Read this from tiff metadata or determine after parsing
metadata.NoDataValue = "-10000";
metadata.NoDataValue = "-32767";

metadata.WorldUnits = "meter";

Expand All @@ -356,7 +356,7 @@ public HeightMap GetHeightMapInBBox(BoundingBox bbox, FileMetadata metadata, flo
xStart = (int)Math.Floor((bbox.xMin - metadata.DataStartLon) / metadata.pixelSizeX);
xEnd = (int)Math.Ceiling((bbox.xMax - metadata.DataStartLon) / metadata.pixelSizeX);
}


// Tiled geotiffs like aster have overlapping 1px borders
int overlappingPixel = this.IsTiled ? 1 : 0;
Expand Down Expand Up @@ -422,10 +422,9 @@ public HeightMap GetHeightMapInBBox(BoundingBox bbox, FileMetadata metadata, flo
heightMap.Maximum = Math.Max(heightMap.Maximum, heightValue);
}

else
{
heightValue = (float)noDataValue;
}
if (heightValue < -15000 || heightValue > 10000)
heightValue = noDataValue;

coords.Add(new GeoPoint(latitude, longitude, heightValue));

}
Expand Down Expand Up @@ -480,21 +479,13 @@ public HeightMap GetHeightMapInBBox(BoundingBox bbox, FileMetadata metadata, flo
default:
throw new Exception("Sample format unsupported.");
}
if (heightValue <= 0)
{
heightMap.Minimum = Math.Min(heightMap.Minimum, heightValue);
heightMap.Maximum = Math.Max(heightMap.Maximum, heightValue);
}
else if (heightValue < 32768)
{
heightMap.Minimum = Math.Min(heightMap.Minimum, heightValue);
heightMap.Maximum = Math.Max(heightMap.Maximum, heightValue);
}

else
{
heightValue = (float)noDataValue;
}
if (heightValue < -15000 || heightValue > 10000)
heightValue = noDataValue;
heightMap.Minimum = Math.Min(heightMap.Minimum, heightValue);
heightMap.Maximum = Math.Max(heightMap.Maximum, heightValue);


coords.Add(new GeoPoint(latitude, longitude, heightValue));

}
Expand Down
32 changes: 16 additions & 16 deletions DEM.Net.Core/Model/Datasets/DEMDataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static Dictionary<string, DEMDataSet> GetRegisteredDatasets()
Name = nameof(AW3D30),
Description = "ALOS World 3D - 30m (nicest but contain void areas)",
PublicUrl = "http://opentopo.sdsc.edu/raster?opentopoID=OTALOS.112016.4326.2",
DataSource = new VRTDataSource("https://opentopography.s3.sdsc.edu/raster/AW3D30/AW3D30_alos.vrt"),
DataSource = new VRTDataSource("https://opentopography.s3.sdsc.edu/raster/AW3D30/AW3D30_global.vrt"),
FileFormat = new DEMFileDefinition("GeoTiff file", DEMFileType.GEOTIFF, ".tif", DEMFileRegistrationMode.Cell),
ResolutionMeters = 30,
ResolutionArcSeconds = 1,
Expand Down Expand Up @@ -197,21 +197,21 @@ private static Dictionary<string, DEMDataSet> GetRegisteredDatasets()
"https://www.gebco.net/data_and_products/gridded_bathymetry_data/gebco_2019/gebco_2019_info.html",
"GEBCO Compilation Group (2019) GEBCO 2019 Grid (doi:10.5285/836f016a-33be-6ddc-e053-6c86abc0788e)")
});
datasets.Add("GEBCO_2020", new DEMDataSet()
{
Name = nameof(GEBCO_2020),
Description = "GEBCO’s gridded bathymetric data set, a global terrain model for ocean and land at 15 arc-second intervals",
PublicUrl = "https://www.gebco.net/data_and_products/gridded_bathymetry_data/gebco_2020/",
DataSource = new LocalFileSystem(localDirectory: "GEBCO_2020"),
FileFormat = new DEMFileDefinition("GeoTiff file", DEMFileType.GEOTIFF, ".tif", DEMFileRegistrationMode.Grid),
ResolutionMeters = 464,
ResolutionArcSeconds = 15,
PointsPerDegree = 240,
NoDataValue = -9999,
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "GEBCO Compilation Group (2020) GEBCO 2020 Grid (doi:10.5285/a29c5465-b138-234d-e053-6c86abc040b9)",
"https://www.gebco.net/data_and_products/gridded_bathymetry_data/gebco_2020/",
"GEBCO Compilation Group (2020) GEBCO 2020 Grid (doi:10.5285/a29c5465-b138-234d-e053-6c86abc040b9)")
});
//datasets.Add("GEBCO_2020", new DEMDataSet()
//{
// Name = nameof(GEBCO_2020),
// Description = "GEBCO’s gridded bathymetric data set, a global terrain model for ocean and land at 15 arc-second intervals",
// PublicUrl = "https://www.gebco.net/data_and_products/gridded_bathymetry_data/gebco_2020/",
// DataSource = new LocalFileSystem(localDirectory: "GEBCO_2020"),
// FileFormat = new DEMFileDefinition("GeoTiff file", DEMFileType.GEOTIFF, ".tif", DEMFileRegistrationMode.Grid),
// ResolutionMeters = 464,
// ResolutionArcSeconds = 15,
// PointsPerDegree = 240,
// NoDataValue = -9999,
// Attribution = new Attribution(ATTRIBUTION_SUBJECT, "GEBCO Compilation Group (2020) GEBCO 2020 Grid (doi:10.5285/a29c5465-b138-234d-e053-6c86abc040b9)",
// "https://www.gebco.net/data_and_products/gridded_bathymetry_data/gebco_2020/",
// "GEBCO Compilation Group (2020) GEBCO 2020 Grid (doi:10.5285/a29c5465-b138-234d-e053-6c86abc040b9)")
//});

return datasets;
}
Expand Down
4 changes: 3 additions & 1 deletion DEM.Net.Core/Model/Geometry/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ public bool IsValid()
{
return xMin < xMax
&& yMin < yMax
&& ((SRID == 4326
&& GpsLocation.IsValidLongitude(xMin)
&& GpsLocation.IsValidLongitude(xMax)
&& GpsLocation.IsValidLatitude(yMin)
&& GpsLocation.IsValidLatitude(yMax);
&& GpsLocation.IsValidLatitude(yMax))
|| SRID != 4326);
}
public void UnionWith(double x, double y, double z)
{
Expand Down
23 changes: 15 additions & 8 deletions DEM.Net.Core/Model/Imagery/ImageryProviders.Predefined.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public partial class ImageryProvider
public static readonly ImageryProvider DebugProvider = new TileDebugProvider(null);
#endif
//https://t0.tiles.virtualearth.net/tiles/a1202221311130.jpeg?g=990&mkt=en-us&n=z
public static readonly ImageryProvider BingMapsSatellite = new ImageryProvider
{
Name = "MapTiler-Satellite",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "Bing Maps", "https://www.microsoft.com/en-us/maps/product/terms-april-2011", "© Bing Maps"),
UrlModel = new UrlModel("https://t{s}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=990&mkt=en-us&n=z", new[] { "0", "1", "2", "3", "4", "5", "6", "7" }),
TileSize = 256,
MaxZoom = 19
};
//public static readonly ImageryProvider BingMapsSatellite = new ImageryProvider
//{
// Name = "BingMaps-Satellite",
// Attribution = new Attribution(ATTRIBUTION_SUBJECT, "Bing Maps", "https://www.microsoft.com/en-us/maps/product/terms-april-2011", "© Bing Maps"),
// UrlModel = new UrlModel("https://t{s}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=990&mkt=en-us&n=z", new[] { "0", "1", "2", "3", "4", "5", "6", "7" }),
// TileSize = 256,
// MaxZoom = 19
//};
public static readonly ImageryProvider MapTilerSatellite = new ImageryProvider
{
Name = "MapTiler-Satellite",
Expand Down Expand Up @@ -135,6 +135,13 @@ public partial class ImageryProvider
TokenUserSecretsKey = "ThunderForestApiKey",
MaxZoom = 22
};
public static readonly ImageryProvider OrtoIGNes = new ImageryProvider
{
Name = "OrtoIGNes",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "IGN.es", "https://www.ign.es", "ign.es"),
UrlModel = new UrlModel("http://www.ign.es/wmts/pnoa-ma?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=OI.OrthoimageCoverage&FORMAT=image/jpeg&TILEMATRIXSET=GoogleMapsCompatible&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}", null),
MaxZoom = 20
};

}
}
2 changes: 1 addition & 1 deletion DEM.Net.Core/Model/Raster/FileMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public override bool Equals(object obj)
}
public override int GetHashCode()
{
return Filename.GetHashCode();
return Path.GetFileName(Filename).GetHashCode();
}

public bool Equals(FileMetadata other)
Expand Down
11 changes: 7 additions & 4 deletions DEM.Net.Core/Services/Adornments/AdornmentsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ public TriangulationList<Vector3> CreateModelAdornments(DEMDataSet dataset, Imag
.RotateZ(PI / 2f)
.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 textWidth = (float)text.GetBoundingBox().Width;
var text = $"{dataset.Attribution.Subject}: {dataset.Attribution.Text}";
if (imageryProvider != null)
text = string.Concat(text, $"{Environment.NewLine}{imageryProvider.Attribution.Subject}: {imageryProvider.Attribution.Text}");
var text3D = this.CreateText(text, VectorsExtensions.CreateColor(255, 255, 255)).ToGlTFSpace();
var textWidth = (float)text3D.GetBoundingBox().Width;
var scale = (float)(((projWidth - scaleBarSize) * 0.9f) / textWidth);

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

return adornments;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void IDEMDataSetIndex.Setup(DEMDataSet dataSet, string dataSetLocalDir)

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

using (HttpResponseMessage response = client.GetAsync(dataSet.DataSource.IndexFilePath).Result)
//using (HttpResponseMessage response = client.GetAsync(dataSet.DataSource.IndexFilePath).Result)
using (FileStream fs = new FileStream(vrtFileName, FileMode.Create, FileAccess.Write))
{
var contentbytes = client.GetByteArrayAsync(dataSet.DataSource.IndexFilePath).Result;
Expand Down
Loading

0 comments on commit 8090059

Please sign in to comment.