-
Notifications
You must be signed in to change notification settings - Fork 2
Add access to well known databases #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,39 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Net.Http; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using System.Threading.Tasks; | ||
| using Pmad.Cartography.Databases; | ||
|
|
||
| namespace Pmad.Cartography.Test.Databases | ||
| { | ||
| public class WellKnownDatabasesTest | ||
| { | ||
| private const string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"; | ||
|
|
||
| [Fact] | ||
| public async Task AW3D30_ContainsLondon() | ||
| { | ||
| var baseAddress = "https://cdn.dem.pmad.net/AW3D30/"; | ||
| var database = WellKnownDatabases.GetAW3D30(); | ||
|
|
||
| var storage = await CreateDatabaseAndLoadIndex(baseAddress); | ||
| await database.LoadIndexAsync(); | ||
|
|
||
| Assert.NotNull(await storage.GetDataCellsAsync(new Coordinates(51, 0), new Coordinates(52, 1))); | ||
| Assert.NotNull(await database.GetDataCellsAsync(new Coordinates(51, 0), new Coordinates(52, 1))); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SRTM1_ContainsLondon() | ||
| { | ||
| var baseAddress = "https://cdn.dem.pmad.net/SRTM1/"; | ||
| var database = WellKnownDatabases.GetSRTM1(); | ||
|
|
||
| var storage = await CreateDatabaseAndLoadIndex(baseAddress); | ||
| await database.LoadIndexAsync(); | ||
|
|
||
| Assert.NotNull(await storage.GetDataCellsAsync(new Coordinates(51, 0), new Coordinates(52, 1))); | ||
| Assert.NotNull(await database.GetDataCellsAsync(new Coordinates(51, 0), new Coordinates(52, 1))); | ||
| } | ||
|
|
||
|
|
||
| [Fact] | ||
| public async Task SRTM15Plus_ContainsLondon() | ||
| { | ||
| var baseAddress = "https://cdn.dem.pmad.net/SRTM15Plus/"; | ||
|
|
||
| var storage = await CreateDatabaseAndLoadIndex(baseAddress); | ||
| var database = WellKnownDatabases.GetSRTM15Plus(); | ||
|
|
||
| Assert.NotNull(await storage.GetDataCellsAsync(new Coordinates(51, 0), new Coordinates(52, 1))); | ||
| } | ||
| await database.LoadIndexAsync(); | ||
|
|
||
| private static async Task<DemDatabase> CreateDatabaseAndLoadIndex(string baseAddress) | ||
| { | ||
| var localCache = Path.Combine(Path.GetTempPath(), "dem_test_wellknown"); | ||
| var httpClient = new HttpClient { BaseAddress = new Uri(baseAddress) }; | ||
| httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent); | ||
| var storage = new DemDatabase(new DemHttpStorage(localCache, httpClient)); | ||
| await storage.LoadIndexAsync(); | ||
| return storage; | ||
| Assert.NotNull(await database.GetDataCellsAsync(new Coordinates(51, 0), new Coordinates(52, 1))); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| using System; | ||
| using System.Data; | ||
| using System.Net.Http; | ||
| using static System.Runtime.InteropServices.JavaScript.JSType; | ||
|
|
||
| namespace Pmad.Cartography.Databases | ||
| { | ||
| public static class WellKnownDatabases | ||
| { | ||
| private const string DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"; | ||
|
|
||
| internal static HttpClient CreateClient(string baseAddress) | ||
| { | ||
| var httpClient = new HttpClient { BaseAddress = new Uri(baseAddress) }; | ||
| // OVH CDN Requires a user agent | ||
| httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(DefaultUserAgent); | ||
| return httpClient; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get the AW3D 30 data hosted on cdn.dem.pmad.net: | ||
| /// Japan Aerospace Exploration Agency (2021). ALOS World 3D 30 meter DEM. V3.2, Jan 2021. | ||
| /// </summary> | ||
| /// <param name="localCache">Cache location. If null, will use <see cref="DemHttpStorage.DefaultCacheLocation"/>.</param> | ||
| /// <returns></returns> | ||
| /// <remarks> | ||
| /// This dataset is available to use with no charge under the following conditions. | ||
| /// When the user provide or publish the products and services to a third party using this dataset, it is necessary to display that the original data is provided by JAXA. | ||
| /// You are kindly requested to show the copyright (© JAXA) and the source of data When you publish the fruits using this dataset. | ||
| /// JAXA does not guarantee the quality and reliability of this dataset and JAXA assume no responsibility whatsoever for any direct or indirect damage and loss caused by use of this dataset.Also, JAXA will not be responsible for any damages of users due to changing, deleting or terminating the provision of this dataset. | ||
| /// </remarks> | ||
| public static DemHttpStorage GetAW3D30Storage(string? localCache = null) | ||
| { | ||
| return new DemHttpStorage(localCache, CreateClient("https://cdn.dem.pmad.net/AW3D30/")); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get the SRTM 1 data hosted on cdn.dem.pmad.net: | ||
| /// NASA Shuttle Radar Topography Mission (SRTM)(2013). Shuttle Radar Topography Mission (SRTM) Global. | ||
| /// </summary> | ||
| /// <param name="localCache">Cache location. If null, will use <see cref="DemHttpStorage.DefaultCacheLocation"/>.</param> | ||
| /// <returns></returns> | ||
| /// <remarks> | ||
| /// Public domain. | ||
| /// </remarks> | ||
| public static DemHttpStorage GetSRTM1Storage(string? localCache = null) | ||
| { | ||
| return new DemHttpStorage(localCache, CreateClient("https://cdn.dem.pmad.net/SRTM1/")); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get the SRTM 15+ data hosted on cdn.dem.pmad.net: | ||
| /// GLOBAL BATHYMETRY AND TOPOGRAPHY AT 15 ARCSECONDS. SRTM15+V2.5.5 - March 20, 2023 | ||
| /// </summary> | ||
| /// <param name="localCache">Cache location. If null, will use <see cref="DemHttpStorage.DefaultCacheLocation"/>.</param> | ||
| /// <returns></returns> | ||
| /// <remarks> | ||
| /// Reference: Tozer, B. , D. T. Sandwell, W. H. F. Smith, C. Olson, J. R. Beale, and P. Wessel, Global bathymetry and topography at 15 arc seconds: SRTM15+, Accepted Earth and Space Science, August 3, 2019. | ||
| /// Public domain. | ||
| /// </remarks> | ||
| public static DemHttpStorage GetSRTM15PlusStorage(string? localCache = null) | ||
| { | ||
| return new DemHttpStorage(localCache, CreateClient("https://cdn.dem.pmad.net/SRTM15Plus/")); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get the AW3D 30 database hosted on cdn.dem.pmad.net: | ||
| /// Japan Aerospace Exploration Agency (2021). ALOS World 3D 30 meter DEM. V3.2, Jan 2021. | ||
| /// </summary> | ||
| /// <param name="localCache">Cache location. If null, will use <see cref="DemHttpStorage.DefaultCacheLocation"/>.</param> | ||
| /// <returns></returns> | ||
| /// <remarks> | ||
| /// This dataset is available to use with no charge under the following conditions. | ||
| /// When the user provide or publish the products and services to a third party using this dataset, it is necessary to display that the original data is provided by JAXA. | ||
| /// You are kindly requested to show the copyright (© JAXA) and the source of data When you publish the fruits using this dataset. | ||
jetelain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// JAXA does not guarantee the quality and reliability of this dataset and JAXA assume no responsibility whatsoever for any direct or indirect damage and loss caused by use of this dataset.Also, JAXA will not be responsible for any damages of users due to changing, deleting or terminating the provision of this dataset. | ||
| /// </remarks> | ||
| public static DemDatabase GetAW3D30(string? localCache = null) | ||
| { | ||
| return new DemDatabase(GetAW3D30Storage(localCache)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get the SRTM 1 database hosted on cdn.dem.pmad.net: | ||
| /// NASA Shuttle Radar Topography Mission (SRTM)(2013). Shuttle Radar Topography Mission (SRTM) Global. | ||
| /// </summary> | ||
| /// <param name="localCache">Cache location. If null, will use <see cref="DemHttpStorage.DefaultCacheLocation"/>.</param> | ||
| /// <returns></returns> | ||
| /// <remarks> | ||
| /// Public domain. | ||
| /// </remarks> | ||
| public static DemDatabase GetSRTM1(string? localCache = null) | ||
| { | ||
| return new DemDatabase(GetSRTM1Storage(localCache)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get the SRTM 15+ database hosted on cdn.dem.pmad.net: | ||
| /// GLOBAL BATHYMETRY AND TOPOGRAPHY AT 15 ARCSECONDS. SRTM15+V2.5.5 - March 20, 2023 | ||
| /// </summary> | ||
| /// <param name="localCache">Cache location. If null, will use <see cref="DemHttpStorage.DefaultCacheLocation"/>.</param> | ||
| /// <returns></returns> | ||
| /// <remarks> | ||
| /// Reference: Tozer, B. , D. T. Sandwell, W. H. F. Smith, C. Olson, J. R. Beale, and P. Wessel, Global bathymetry and topography at 15 arc seconds: SRTM15+, Accepted Earth and Space Science, August 3, 2019. | ||
| /// Public domain. | ||
| /// </remarks> | ||
| public static DemDatabase GetSRTM15Plus(string? localCache = null) | ||
| { | ||
| return new DemDatabase(GetSRTM15PlusStorage(localCache)); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.