Internal error: The raster layer does not have a spatial reference.

271
2
12-31-2022 05:40 AM
NathanMoebus
New Contributor

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

9.31098696461825
0
0
-18.587360594795538
-9166533.732955951
3235852.4356317967

0 Kudos
2 Replies
PreetiMaske
Esri Contributor

Are able to view the raster layer though?, If yes, then it's fine because the issue with rater layer reporting incorrect viewstate and error is already logged internally in our bug tracking system but hasn't been prioritized yet.

0 Kudos
NathanMoebus
New Contributor

Negative - I cannot see the raster layer.  Here is a dump of both the Error and Status props of the LayerViewState from the LayerViewStateChanged event.  As you can see, status is 'NotVisible | Error'.

? e.LayerViewState.Status
NotVisible | Error

? e.LayerViewState.Error
{"Internal error: The raster layer does not have a spatial reference."}
Data: {System.Collections.ListDictionaryInternal}
ErrorCode: 18
HResult: -2146233088
HelpLink: null
InnerException: null
Message: "Internal error: The raster layer does not have a spatial reference."
Source: null
StackTrace: null
TargetSite: null

Here is a dump of the e.Layer property as well.  As you can see, the 'IsVisible' property is indeed true which contradicts the status above.

? e.Layer
{Esri.ArcGISRuntime.Mapping.RasterLayer}
Attribution: ""
Brightness: 0
CanChangeVisibility: true
Contrast: 0
Description: ""
FullExtent: {Envelope[XMin=-0.5, YMin=-255.5, XMax=255.5, YMax=0.5, WkText=]}
FullTimeExtent: null
Gamma: 0
Id: "we/IX5k5TjS3Pdb9TuAsdQ"
IsIdentifyEnabled: true
IsPopupEnabled: true
IsTimeFilteringEnabled: true
IsVisible: true
Item: null
LoadError: null
LoadStatus: Loaded
MaxScale: 1500
MinScale: 2500
Name: "img_-15657522.123893805_-1799999.9999999995.png"
Opacity: 1
PopupDefinition: null
Raster: {Esri.ArcGISRuntime.Rasters.Raster}
Renderer: null
ShowInLegend: true
SpatialReference: null
SublayerContents: {Esri.ArcGISRuntime.Internal.SublayerContentCollection}
SupportsTimeFiltering: false
TimeInterval: null
TimeOffset: null

0 Kudos