Select to view content in your preferred language

Raster layer spatial reference not being detected

161
0
Monday
Labels (3)
EmilisArc
New Contributor

Hi community, I'm working on a function, that needs to take an imported geotiff file and add it as a raster layer to my Map OperationalLayers collection. But I'm having an issue where the RasterLayer object throws an internal error and fails to get a spatial reference. The layer can still be added, but it's not visible on the MapView. I've checked the geotiff file using gdal and it seems to be valid, with the SpatialReference that matches the Map. Also the geotiff opens fine on ArcGIS Pro. Interestingly, if I transform the .tif to a geopackage (.gpkg) with gpkg_contents datatype as "tiles", than there the layer gets applied and is visible. 

public async Task AddNewLayer(string tifFile)
{
    try
    {
        var raster = new Raster(tifFile);

        SpatialReference mapSpatialReference = ActiveMap.SpatialReference;
        Debug.WriteLine($"Map Spatial Reference: {mapSpatialReference?.Wkid}");

        var rasterLayer = new RasterLayer(raster);

        await rasterLayer.LoadAsync();

        if (rasterLayer.SpatialReference is null)
        {
            Debug.WriteLine("Raster layer SpatialReference is null.");
            return;
        }

        SpatialReference rasterSpatialReference = rasterLayer.SpatialReference;
        Debug.WriteLine($"Raster Spatial Reference: {rasterSpatialReference?.Wkid}");

        ActiveMap.OperationalLayers.Add(rasterLayer);
        Layers.Add(rasterLayer);
    }
    catch (Exception e)
    {
        Debug.WriteLine($"Error adding new layer from {tifFile}: {e.Message}");
    }
}

This method would print to Debug console: "Raster layer SpatialReference is null." While debugging, I can see that the RasterLayer.SpatialReference.BaseGeographic throws an exception: 

  Name Value Type

BaseGeographic'rasterLayer.FullExtent.SpatialReference.BaseGeographic' threw an exception of type 'System.InvalidOperationException'Esri.ArcGISRuntime.Geometry.SpatialReference {System.InvalidOperationException}

 

The map's SpatialReference is the same as defined in the geotiff:

  Name Value Type

mapSpatialReference{SpatialReference[Wkid=3346]}Esri.ArcGISRuntime.Geometry.SpatialReference

 

From the output of gdal raster.tif

"coordinateSystem":{
"wkt":"PROJCRS[\"LKS94 / Lithuania TM\",\n BASEGEOGCRS[\"LKS94\",\n DATUM[\"Lithuania 1994 (ETRS89)\",\n ELLIPSOID[\"GRS 1980\",6378137,298.257222101,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n ID[\"EPSG\",4669]],\n CONVERSION[\"Lithuania 1994\",\n METHOD[\"Transverse Mercator\",\n ID[\"EPSG\",9807]],\n PARAMETER[\"Latitude of natural origin\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8801]],\n PARAMETER[\"Longitude of natural origin\",24,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8802]],\n PARAMETER[\"Scale factor at natural origin\",0.9998,\n SCALEUNIT[\"unity\",1],\n ID[\"EPSG\",8805]],\n PARAMETER[\"False easting\",500000,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8806]],\n PARAMETER[\"False northing\",0,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8807]]],\n CS[Cartesian,2],\n AXIS[\"northing (X)\",north,\n ORDER[1],\n LENGTHUNIT[\"metre\",1]],\n AXIS[\"easting (Y)\",east,\n ORDER[2],\n LENGTHUNIT[\"metre\",1]],\n USAGE[\n SCOPE[\"Engineering survey, topographic mapping.\"],\n AREA[\"Lithuania - onshore and offshore.\"],\n BBOX[53.89,19.02,56.45,26.82]],\n ID[\"EPSG\",3346]]",

 

0 Kudos
0 Replies