Attempting to load a set of PNG raster files but seeing the following error from the LayerViewStateChanged event.
Internal error: The raster layer does not have a spatial reference.
I don't see any way to set the spatial reference on the RasterLayer as the property only has a getter. Also, I have world files that are in the same directory as the png files.
private async Task LoadMap()
{
// create map
Map myMap = new Map(SpatialReference.Create(3857));
myMap.Basemap = new Basemap(BasemapStyle.ArcGISOceansBase);
MyMapView.Map = myMap;
MyMapView.LayerViewStateChanged += MyMapView_LayerViewStateChanged;
// Get the file name
string filepath = GetFilesPath();
var files = Directory.GetFiles(filepath, "*.png");
foreach (var file in files)
{
// Load the raster file
Raster myRasterFile = new Raster(file);
// Create the layer
RasterLayer myRasterLayer = new RasterLayer(myRasterFile);
// Add the layer to the map
myMap.OperationalLayers.Add(myRasterLayer);
try
{
// Wait for the layer to load
await myRasterLayer.LoadAsync();
// Set the viewpoint
await MyMapView.SetViewpointGeometryAsync(myRasterLayer.FullExtent);
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Error");
}
}
}
Sample - World File Contents