mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-04-22 07:16:39 +00:00
api /api/satellite/tiles/latlon
This commit is contained in:
@@ -90,8 +90,8 @@ if (app.Environment.IsDevelopment())
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.MapGet("/api/satellite/tiles/latlon", GetSatelliteTilesByLatLon)
|
||||
.WithOpenApi(op => new(op) { Summary = "Get satellite tiles by latitude and longitude coordinates" });
|
||||
app.MapGet("/api/satellite/tiles/latlon", GetTileByLatLon)
|
||||
.WithOpenApi(op => new(op) { Summary = "Get satellite tile by latitude and longitude coordinates" });
|
||||
|
||||
app.MapGet("/api/satellite/tiles/mgrs", GetSatelliteTilesByMgrs)
|
||||
.WithOpenApi(op => new(op) { Summary = "Get satellite tiles by MGRS coordinates" });
|
||||
@@ -101,9 +101,6 @@ app.MapPost("/api/satellite/upload", UploadImage)
|
||||
.WithOpenApi(op => new(op) { Summary = "Upload image with metadata and save to /maps folder" })
|
||||
.DisableAntiforgery();
|
||||
|
||||
app.MapPost("/api/satellite/tiles/download", DownloadSingleTile)
|
||||
.WithOpenApi(op => new(op) { Summary = "TEMPORARY: Download single tile at specified coordinates" });
|
||||
|
||||
app.MapPost("/api/satellite/request", RequestRegion)
|
||||
.WithOpenApi(op => new(op) { Summary = "Request tiles for a region" });
|
||||
|
||||
@@ -118,32 +115,17 @@ app.MapGet("/api/satellite/route/{id:guid}", GetRoute)
|
||||
|
||||
app.Run();
|
||||
|
||||
IResult GetSatelliteTilesByLatLon(double lat, double lon, double squareSideMeters)
|
||||
{
|
||||
return Results.Ok(new GetSatelliteTilesResponse());
|
||||
}
|
||||
|
||||
IResult GetSatelliteTilesByMgrs(string mgrs, double squareSideMeters)
|
||||
{
|
||||
return Results.Ok(new GetSatelliteTilesResponse());
|
||||
}
|
||||
|
||||
IResult UploadImage([FromForm] UploadImageRequest request)
|
||||
{
|
||||
return Results.Ok(new SaveResult { Success = false });
|
||||
}
|
||||
|
||||
async Task<IResult> DownloadSingleTile([FromBody] DownloadTileRequest request, GoogleMapsDownloaderV2 downloader, ITileRepository tileRepository, ILogger<Program> logger)
|
||||
async Task<IResult> GetTileByLatLon([FromQuery] double Latitude, [FromQuery] double Longitude, [FromQuery] int ZoomLevel, GoogleMapsDownloaderV2 downloader, ITileRepository tileRepository, ILogger<Program> logger)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("Downloading single tile at ({Lat}, {Lon}) with zoom level {Zoom}",
|
||||
request.Latitude, request.Longitude, request.ZoomLevel);
|
||||
logger.LogInformation("Getting tile at ({Lat}, {Lon}) with zoom level {Zoom}",
|
||||
Latitude, Longitude, ZoomLevel);
|
||||
|
||||
var downloadedTile = await downloader.DownloadSingleTileAsync(
|
||||
request.Latitude,
|
||||
request.Longitude,
|
||||
request.ZoomLevel);
|
||||
Latitude,
|
||||
Longitude,
|
||||
ZoomLevel);
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var currentVersion = now.Year;
|
||||
@@ -186,11 +168,21 @@ async Task<IResult> DownloadSingleTile([FromBody] DownloadTileRequest request, G
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to download tile");
|
||||
logger.LogError(ex, "Failed to get tile");
|
||||
return Results.Problem(detail: ex.Message, statusCode: 500);
|
||||
}
|
||||
}
|
||||
|
||||
IResult GetSatelliteTilesByMgrs(string mgrs, double squareSideMeters)
|
||||
{
|
||||
return Results.Ok(new GetSatelliteTilesResponse());
|
||||
}
|
||||
|
||||
IResult UploadImage([FromForm] UploadImageRequest request)
|
||||
{
|
||||
return Results.Ok(new SaveResult { Success = false });
|
||||
}
|
||||
|
||||
async Task<IResult> RequestRegion([FromBody] RequestRegionRequest request, IRegionService regionService, ILogger<Program> logger)
|
||||
{
|
||||
try
|
||||
@@ -329,18 +321,6 @@ public record SaveResult
|
||||
public string? Exception { get; set; }
|
||||
}
|
||||
|
||||
public record DownloadTileRequest
|
||||
{
|
||||
[Required]
|
||||
public double Latitude { get; set; }
|
||||
|
||||
[Required]
|
||||
public double Longitude { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ZoomLevel { get; set; } = 20;
|
||||
}
|
||||
|
||||
public record DownloadTileResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
@@ -388,7 +368,10 @@ public class ParameterDescriptionFilter : IOperationFilter
|
||||
["lat"] = "Latitude coordinate where image was captured",
|
||||
["lon"] = "Longitude coordinate where image was captured",
|
||||
["mgrs"] = "MGRS coordinate string",
|
||||
["squareSideMeters"] = "Square side size in meters"
|
||||
["squareSideMeters"] = "Square side size in meters",
|
||||
["Latitude"] = "Latitude coordinate of the tile center",
|
||||
["Longitude"] = "Longitude coordinate of the tile center",
|
||||
["ZoomLevel"] = "Zoom level for the tile (higher values = more detail)"
|
||||
};
|
||||
|
||||
foreach (var parameter in operation.Parameters)
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
namespace SatelliteProvider.IntegrationTests;
|
||||
|
||||
public record DownloadTileRequest
|
||||
{
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public int ZoomLevel { get; set; }
|
||||
}
|
||||
|
||||
public record DownloadTileResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
@@ -24,7 +24,7 @@ class Program
|
||||
Console.WriteLine("✓ API is ready");
|
||||
Console.WriteLine();
|
||||
|
||||
await TileTests.RunSingleTileDownloadTest(httpClient);
|
||||
await TileTests.RunGetTileByLatLonTest(httpClient);
|
||||
|
||||
await RegionTests.RunRegionProcessingTest_200m_Zoom18(httpClient);
|
||||
|
||||
|
||||
@@ -10,25 +10,18 @@ public static class TileTests
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public static async Task RunSingleTileDownloadTest(HttpClient httpClient)
|
||||
public static async Task RunGetTileByLatLonTest(HttpClient httpClient)
|
||||
{
|
||||
Console.WriteLine("Test: Download Single Tile at Coordinates 47.461747, 37.647063");
|
||||
Console.WriteLine("Test: Get Tile by Lat/Lon at Coordinates 47.461747, 37.647063");
|
||||
Console.WriteLine("------------------------------------------------------------------");
|
||||
|
||||
const double latitude = 47.461747;
|
||||
const double longitude = 37.647063;
|
||||
const int zoomLevel = 18;
|
||||
|
||||
Console.WriteLine($"Downloading tile at coordinates ({latitude}, {longitude}) with zoom level {zoomLevel}");
|
||||
Console.WriteLine($"Getting tile at coordinates ({latitude}, {longitude}) with zoom level {zoomLevel}");
|
||||
|
||||
var request = new DownloadTileRequest
|
||||
{
|
||||
Latitude = latitude,
|
||||
Longitude = longitude,
|
||||
ZoomLevel = zoomLevel
|
||||
};
|
||||
|
||||
var response = await httpClient.PostAsJsonAsync("/api/satellite/tiles/download", request);
|
||||
var response = await httpClient.GetAsync($"/api/satellite/tiles/latlon?Latitude={latitude}&Longitude={longitude}&ZoomLevel={zoomLevel}");
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -77,30 +70,30 @@ public static class TileTests
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("✓ Tile downloaded successfully");
|
||||
Console.WriteLine("✓ Tile retrieved successfully");
|
||||
Console.WriteLine("✓ Tile metadata validated");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Testing tile reuse (downloading same tile again)...");
|
||||
Console.WriteLine("Testing tile reuse (getting same tile again)...");
|
||||
|
||||
var response2 = await httpClient.PostAsJsonAsync("/api/satellite/tiles/download", request);
|
||||
var response2 = await httpClient.GetAsync($"/api/satellite/tiles/latlon?Latitude={latitude}&Longitude={longitude}&ZoomLevel={zoomLevel}");
|
||||
|
||||
if (!response2.IsSuccessStatusCode)
|
||||
{
|
||||
var errorContent = await response2.Content.ReadAsStringAsync();
|
||||
throw new Exception($"Second download failed with status {response2.StatusCode}: {errorContent}");
|
||||
throw new Exception($"Second request failed with status {response2.StatusCode}: {errorContent}");
|
||||
}
|
||||
|
||||
var tile2 = await response2.Content.ReadFromJsonAsync<DownloadTileResponse>(JsonOptions);
|
||||
|
||||
if (tile2 == null)
|
||||
{
|
||||
throw new Exception("No tile data returned from second download");
|
||||
throw new Exception("No tile data returned from second request");
|
||||
}
|
||||
|
||||
Console.WriteLine($"✓ Second download returned tile ID: {tile2.Id}");
|
||||
Console.WriteLine($"✓ Second request returned tile ID: {tile2.Id}");
|
||||
Console.WriteLine("✓ Tile reuse functionality working");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Single Tile Download Test: PASSED");
|
||||
Console.WriteLine("Get Tile by Lat/Lon Test: PASSED");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user