Skip to content

Commit d9d5efb

Browse files
committed
Clarify raster terrain texture diagnostics
1 parent e805f9d commit d9d5efb

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

src/PlateauResoniteLink/Targets/Resonite/ResoniteQueuedTexturePreparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private static string DescribeTerrainTextureSource(TerrainTextureSource source)
167167
{
168168
TerrainTextureGeoReferencedRasterSource rasterSource => string.Create(
169169
CultureInfo.InvariantCulture,
170-
$"GeoTIFF(source='{rasterSource.ContentSource.Description}', crs='{rasterSource.Metadata.CoordinateSystemIdentifier}')"),
170+
$"Geo-referenced raster(source='{rasterSource.ContentSource.Description}', crs='{rasterSource.Metadata.CoordinateSystemIdentifier}')"),
171171
TerrainTextureTileSource tileSource when IsGsiFallbackSource(tileSource) => string.Create(
172172
CultureInfo.InvariantCulture,
173173
$"GSI seamless photo tile(z={tileSource.ZoomLevel})"),

src/PlateauResoniteLink/Targets/Resonite/TerrainTextureAssetGenerator.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,37 @@ private static async Task<TerrainTextureSourceImage> CreateTextureFromGeoReferen
220220
TerrainTextureGeoReferencedRasterSource rasterSource,
221221
CancellationToken cancellationToken)
222222
{
223-
await using Stream sourceStream = await rasterSource.OpenReadAsync(cancellationToken);
224-
using Image<Rgba32> sourceImage = await Image.LoadAsync<Rgba32>(sourceStream, cancellationToken);
225-
Image<Rgba32>? cropped = TerrainTextureGeoReferencedRasterCropper.TryCrop(
226-
sourceImage,
227-
rasterSource.Metadata,
228-
terrainTextureOverlay.GeographicBounds);
229-
if (cropped is null)
223+
Image<Rgba32> sourceImage;
224+
try
225+
{
226+
await using Stream sourceStream = await rasterSource.OpenReadAsync(cancellationToken);
227+
sourceImage = await Image.LoadAsync<Rgba32>(sourceStream, cancellationToken);
228+
}
229+
catch (Exception exception) when (exception is not OperationCanceledException)
230230
{
231231
throw new InvalidOperationException(
232232
string.Create(
233233
CultureInfo.InvariantCulture,
234-
$"Geo-referenced raster source '{rasterSource.ContentSource.Description}' does not overlap terrain overlay bounds '{TerrainTextureDescriptorFormatting.FormatBounds(terrainTextureOverlay.GeographicBounds)}'."));
234+
$"Failed to open or decode geo-referenced raster source '{rasterSource.ContentSource.Description}' for terrain overlay bounds '{TerrainTextureDescriptorFormatting.FormatBounds(terrainTextureOverlay.GeographicBounds)}'."),
235+
exception);
235236
}
236237

237-
return new TerrainTextureSourceImage(cropped, null);
238+
using (sourceImage)
239+
{
240+
Image<Rgba32>? cropped = TerrainTextureGeoReferencedRasterCropper.TryCrop(
241+
sourceImage,
242+
rasterSource.Metadata,
243+
terrainTextureOverlay.GeographicBounds);
244+
if (cropped is null)
245+
{
246+
throw new InvalidOperationException(
247+
string.Create(
248+
CultureInfo.InvariantCulture,
249+
$"Geo-referenced raster source '{rasterSource.ContentSource.Description}' does not overlap terrain overlay bounds '{TerrainTextureDescriptorFormatting.FormatBounds(terrainTextureOverlay.GeographicBounds)}'."));
250+
}
251+
252+
return new TerrainTextureSourceImage(cropped, null);
253+
}
238254
}
239255

240256
private static GeneratedTerrainTexture CreateGeneratedTexture(

tests/PlateauResoniteLink.Tests/Targets/TerrainTextureGeoReferencedRasterSupportTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,12 @@ public async Task EnsureTextureAsyncRejectsUnavailableGeoReferencedRasterSourceW
516516
using HttpClient httpClient = new(handler);
517517
TerrainTextureAssetGenerator generator = new(httpClient, disablePersistentCache: true);
518518

519-
await Assert.ThrowsAsync<FileNotFoundException>(
519+
InvalidOperationException exception = await Assert.ThrowsAsync<InvalidOperationException>(
520520
async () => await generator.EnsureTextureAsync(overlay, CancellationToken.None));
521521

522+
Assert.Contains("missing.tif", exception.Message, StringComparison.Ordinal);
523+
Assert.Contains(TerrainTextureDescriptorFormatting.FormatBounds(bounds), exception.Message, StringComparison.Ordinal);
524+
Assert.IsType<FileNotFoundException>(exception.InnerException);
522525
Assert.Equal(0, handler.RequestCount);
523526
}
524527

0 commit comments

Comments
 (0)