Adding a raster layer from a map service results in null layer

1885
17
04-17-2019 06:26 AM
Vidar
by
Occasional Contributor II

Hi,

NOTE: I have updated this question from struggling to add a specific layer from a map service (as I have managed to work this out) to having a problem with adding raster layers (don't work) vs adding vector layers (which do work!).

I have a map service which has many layers of type "Raster Layer".  It is stored on Portal. I can locate the exact layer I want (it's a single layer) - but when I add it to the map - the result never shows in the map.  I just have an empty map.

However - if you change the code ever so slightly below to work against a Map Service with just vector/feature based layers - the layer loads ABSOLUTELY FINE!

So why is this not working for raster layers ?? This is beyond frustrating!!

Anyone have any ideas?

public static async void AddLayerToView()
 {
    Uri portalUri = new Uri("https://fooserver.foocompany.local/portal");

    var portal = ArcGISPortalManager.Current.GetPortal(portalUri);
    var owner = portal.GetSignOnUsername();
    var portalInfo = await portal.GetPortalInfoAsync();

    // Get all web maps and map services - include user, organization
    // and "foo" in the title
    var query2 = PortalQueryParameters.CreateForItemsOfTypes(new List<PortalItemType>() {
    PortalItemType.WebMap, PortalItemType.MapService, PortalItemType.Layer}, owner, "", "Title:Foo");
    query2.OrganizationId = portalInfo.OrganizationId;

   //retrieve in batches of up to a 100 each time
    query2.Limit = 100;

   //Loop until done
    var portalItems = new List<PortalItem>();
    while (query2 != null)
    {
       //run the search
       PortalQueryResultSet<PortalItem> results = await portal.SearchForContentAsync(query2);
       portalItems.AddRange(results.Results);
       query2 = results.NextQueryParameters;
    }

    RasterLayer rasterLayer = null;
    //Layer vectorLayer = null;  //UNCOMMENT FOR VECTOR

    //process results
    foreach (var pi in portalItems)
    {
       string itemID = pi.ID;
       Item currentItem = ItemFactory.Instance.Create(itemID, ItemFactory.ItemType.PortalItem);

       await QueuedTask.Run(() =>
       {
          var subItems = currentItem.GetItems();

          foreach (var item in subItems)
          {
             if (item.Name == "MY_LAYER_NAME_TO_MATCH_ON")
             {
                if (LayerFactory.Instance.CanCreateLayerFrom(item))
                {
                   rasterLayer = (RasterLayer)LayerFactory.Instance.CreateLayer(item, MapView.Active.Map);
                   //vectorLayer = LayerFactory.Instance.CreateLayer(item, MapView.Active.Map);
//UNCOMMENT FOR VECTOR
                }
            }
         }
    });
}




PS - Is there any way to make the above look more like code layout.
Tags (3)
0 Kudos
17 Replies
Vidar
by
Occasional Contributor II

Thanks for your reply - as you can see I have updated my code and modified the question slightly - I know how to add a single layer from a service but I still fail to add a raster based layer - it is always null and nothing appears in the map view - can you help with that?

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Simon

I am able to reproduce this behavior you are seeing. Will investigate and let you know.

Thanks

Uma

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Simon

You cannot add raster sublayers (that is, raster layers inside a map service) individually to Pro. This is by-design.

Thanks

Uma

Vidar
by
Occasional Contributor II

Hi Uma, 

That's interesting, I'm wondering if you can tell me why this is the case, what's the thinking behind designing the map service in such a way - bearing in mind you have this behaviour if you toggle WMS for the map service or if you work with a map service which has published featureclasses. 

Kind regards

Simon.

0 Kudos
Vidar
by
Occasional Contributor II

Hi, Uma

I would really appreciate a more detailed response to this as it is critical to the project I am currently on with.

Kind regards.

Simon.

0 Kudos
TanuHoque
Esri Regular Contributor
Simon,
map service was designed, back in the day, to draw features on the server side and return image in png/jpg etc. format for web clients to consume/use data that are disseminated over web. It also supports query operations for feature layer -- therefore advanced clients can download features and have them drawn on the client side. That's why it works for you when you create a feature layer with a url pointing to a feature-layer off a map service.
But map service was never designed to return raw raster/image dataset.
We have Image service for that reason, that returns raw raster data (similar to OGC - where wms for maps and wcs for raster data). Therefore raster layer can't be created in Pro pointing to a raster layer off a map service.
please refer to the following to learn more about Image Service Layer and see whether it helps in your workflow.
Otherwise, if you give us your entire workflow, we will see what best way your use case can be addressed. All I see is that you want to add them individually - not sure why? (sorry if I missed/overlooked that) -- pls let me know what do you want to do with that layer once added -  do you just want to draw or do you want to performance some identify operation/analysis etc. afterwards?
Thanks
Tanu
Vidar
by
Occasional Contributor II

Hi Tanu, sorry for the late reply (I didn't recieve a notification or didn't notice one).

The workflow is to browse several hundred map services - inside each one there may just be Feature Layers published, or rasters, all in all there are tens of thousands of individual layers. The user is not aware of all these hundreds of map services - the UI in Pro hides this all away.

All they are presented with is a nice UI in Pro - which allows them to query layers spread accross all the map services - from there they can filter down and pick some (or just one) layers of interest (I mean that in a generic sense i.e. can be either raster or feature layer type) - then they ask those layers to be added to the Map in Pro.

The code behind does things like searching and caching what it has found amongst the map services - all via REST api calls - in the end the specific layers are found and then added to the Map view inside Pro.

The user is not anything fancy with the layers - it's a means to view and inspect some of the attribute data perhaps - but certainly no advanced geoprocessing tasks or anything like that.  It's essentially a huge data repository stored in the cloud via Portal.

Thats the workflow - it's not complicated as you can see - it's just basically find me data and show it in Pro.  Data stored centrally in the cloud/ArcGIS Enterprise.

I look forward to your thoughts.

0 Kudos
TanuHoque
Esri Regular Contributor

Hi Simon

No worries.

When you see the layer type is 'raster', can you add that as a map service layer?

If you use 'dynamic layers' capability to remove all other sub-layers from the map service layer. This will allow you to see the layer on the map.

hope this helps.

0 Kudos