Select to view content in your preferred language

How to use a Raster image as a basemap or layer?

4291
11
08-28-2017 06:31 PM
Parh_JinChia
Emerging Contributor

Hi, I have discovered there is a Raster type and RasterLayer in Esri ArcGIS

Runtime for .Net.

However I could not get it to work.

In the github samples, I could only find RasterLayerImageServiceRaster

<https://github.com/Esri/arcgis-runtime-samples-dotnet/tree/master/src/WPF/ArcGISRuntime.WPF.Samples/...>

and RasterLayerRasterFunction

<https://github.com/Esri/arcgis-runtime-samples-dotnet/tree/master/src/WPF/ArcGISRuntime.WPF.Samples/...>

I just want to create a Raster Layer from a GeoTIFF file stored on local

disk and then display it. Nothing too fancy.

 

My code at the moment looks something like:

 

Raster myRaster = new Raster(@"C:\tiffmap.tif");

RasterLater newRasterLayer = new RasterLayer(myRaster);

 

Basemap myBasemap = _map.Basemap;

LayerCollection myLayerCollection = myBasemap.BaseLayers;

myLayerCollection.Add(newRasterLayer);

 

but the map is not showing. I get a blank map. I have tried using WMTSLayer and it works, so I am not too far off.

What should I be doing? The documentation and examples are sparse....

 

rgds

PJ

Tags (1)
0 Kudos
11 Replies
NagmaYasmin
Esri Contributor

Hi,

Below is the code to display a raster as a basemap or an operational layer

  string pathToRaster = @"C:\rasters\wsiearth.tif";

// create a raster from a path to a supported raster format
Raster myRaster = new Raster(pathToRaster);

// create a RasterLayer using the Raster
Esri.ArcGISRuntime.Mapping.RasterLayer newRasterLayer = new Esri.ArcGISRuntime.Mapping.RasterLayer(pathToRaster);
Map map = new Map();

map.Basemap.BaseLayers.Add(newRasterLayer); // as a Basemap
// map.OperationalLayers.Add(newRasterLayer); // as an operational layer
MyMapView.Map = map;

Hope that helps.

RasterLayer

0 Kudos
Parh_JinChia
Emerging Contributor

Thanks Yasmin, that's a great help. However it still does not work. The

window just shows all white.

However, I can swap in a WmtsLayer and THAT displays, so the rest of my

code should be okay.

Could you point me to a tif file for me to try? Maybe my tif file is

defective...

0 Kudos
NagmaYasmin
Esri Contributor

Hi,

Attached is the zip file of the raster I used.

Best,

Nagma

0 Kudos
Parh_JinChia
Emerging Contributor

Thanks Nagma, it still does not work. All I'm getting is a white window.

Your tiff file set consists of the files with extensions .tfw, .tif,

.aux.xml and .tif.ovr

my tiff file set consts of files with the extensions .prj, .tfw, .tif,

.README.html and .VERSION.txt

seems like slightly different formats, but both does not work.

For the pathToRaster I just point to the .tif file itself right?

do I need to do anything else like set the SpatialReferences?

I noticed that in your code, there seems to be one line that does nothing

"Raster myRaster = new Raster(pathToRaster)':

i.e. myRaster is not used.. am I missing something?

I can do either new RasterLayer(myRaster) OR new

RasterLayer(pathToRaster)

but it makes no difference either way.

any ideas?

rgds

PJ

0 Kudos
NagmaYasmin
Esri Contributor

Hi PJ,

You right, I haven't used the variable 'myRaster' anywhere in the code, sorry for the confusion. But I am not sure why you are seeing only the white screen using same raster I used.

0 Kudos
Parh_JinChia
Emerging Contributor

I suspect it is stuck at loading the raster.

I have drawn some graphics in a graphics overlay, which does come out when

I switch over to wmtslayer.

Could I trouble you to provide a shortest complete source code that works?

Rgds

PJ

0 Kudos
NagmaYasmin
Esri Contributor

Hi PJ,

Attached is the complete project.Just install the NuGet pacahage for WPFand point to the lication of the tif file, It should display the raster as the previous scree shot. 

Hope that helps.

0 Kudos
Parh_JinChia
Emerging Contributor

Hi Nagma, thank you very much, it was a great help! I could get your

project to work.

I finally discovered what in my case was preventing the raster from

loading...

it was the

ArcGISRuntimeEnvironment.SetLicense(licenseKey);

that was the culprit...

I added this to your project (together with my license string) and it

stopped working immediately.

I removed it from my project and it worked!

I'm puzzled why that would interfere with loading the raster.

The license has no effect on WmtsLayer and other kinds of basemaps..

rgds

PJ

0 Kudos
NagmaYasmin
Esri Contributor

Hi PJ,

According to the documentation, (License your app—ArcGIS Runtime SDK for .NET (WPF) | ArcGIS for Developers) to display the local raster layer, you need to have the minimum Standard license. I am guessing you might be using Basic or Lite license in your application that prevent displaying the raster image.

Best,

Nagma

0 Kudos