Author Archives: Simon

About Simon

I am a GIS devloper working mostly with C#.Net - but am quite ambivalent about preference to programming languages - they all serve a purpose in their own little way!

Add raster layer from map service in ArcGIS Portal

Problem

User needs to add one or many raster layers into ArcGIS Pro from a map service.  Default behaviour only allows adding the complete map service and all it’s constituent rasters (of which there could be dozens).

First of all map services need to be enabled with WMS before you can even start thinking about adding discrete layers.  This is done via ArcGIS Server:

In Portal, as admin, you need to make sure both the map service and the WMS service are given the correct permissions to your end users – you must do this for both services!

The Code

Note the code below is referencing the WMS url not the standard map service.


string wmsUrl = "https://gisportal.foocompany.local/ags/services/fooservice/MapServer/WMSServer";
string rasterName = "fooRasterName";  
var serverConnection = new CIMInternetServerConnection { URL = wmsUrl };
var connection = new CIMWMSServiceConnection { ServerConnection = serverConnection };
connection.ServerConnection.User = "fooUser";
connection.ServerConnection.Password = "barPassword";
connection.LayerName = layerName;
RasterLayer rasterLayer = null;
await QueuedTask.Run(() =>
{
    var layer = LayerFactory.Instance.CreateLayer(connection, MapView.Active.Map);
});

Conclusion

This method seems clunky becuase you have the overhead of having to create a WMS service and not just being able to stick with standard map services.

After asking ESRI why when trying to add a raster layer nothing happens – they replied by saying “it’s by design” – with no further explanation. To me it makes no sense – why not have it behave the same way when adding feature based layers from a map service.