Retrieving symbols from ServiceFeatureTable (and passed to KML)

533
5
Jump to solution
09-29-2022 04:59 AM
MarcHillman
New Contributor III

I have only recently discovered ServiceFeatureTable. I had previously been using a ghastly process of http request, and then parsing the json to get features. It was all too hard, but it worked.

ServiceFeatureTable has been a revelation, and I'm converting all my ghastly code to use ServiceFeatureTable. I've got most of the functionality converted, but one area has me baffled. I have a feature which is (say) type 1. How do I get the symbol for type 1? I used to knife and fork my way though a json response, but surely there's a simple primitive to get this? I've seen ShowSymbol, but I can't see how to apply it. What I really need is a way to get all the symbols, by type, from the ServiceFeatureTable.

As to using the symbol in KML - I currently convert the symbol imageData to Base64, save it to a local file, and put a reference to this file in the KML. Is there a better way?

 

https://services.ga.gov.au/gis/rest/services/NM_Transport_Infrastructure/MapServer/4

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
PreetiMaske
Esri Contributor

First cast the renderer as UniqueValueRenderer and then get uniquevalues

```

var uvr= layer.Renderer as UniqueValueRenderer;

var uv_values= uvr.UniqueValues;

```

View solution in original post

0 Kudos
5 Replies
ViktorSafar
Occasional Contributor II

I have a WPF app and in a ViewModel I get the image like this:

 

 

		private async Task GenerateImage()
		{
			var legendInfos = (await _layer.GetLegendInfosAsync()).ToList();
			if (legendInfos.Count > 0)
			{
// This is dummed down to 1st
				var symbol = await legendInfos.First().Symbol.CreateSwatchAsync(); 				 
                var stream = await symbol.GetEncodedBufferAsync();

// LayerImageSource is a property of my VM where a View's image binds its source
				LayerImageSource = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); 
			}
		}

 

 

_layer is a Layer which you can get from the ServiceFeatureTable:

var layer = new FeatureLayer(table)
MarcHillman
New Contributor III

Very nearly there. The result of the GetLegendInfosAsync is a collection of 10 legendinfo. The Name property of this maps to "Label" when you look at the capabilities of the resource. Unfortunately, Label is not unique. I need both the Value and Label fields. The Value field is what I see in the retrieved feature. The Label field denotes which symbol to use. I've listed the 10 symbols this server provides below. Any ideas?

UniqueValueInfos:

    • Value: Operational
      Label: Operational
      Description:
      Symbol:MarcHillman_0-1664456473666.png

       

    • Value:
      Label: Operational
      Description:
      Symbol:MarcHillman_1-1664456473666.png

       

    • Value: Decommissioned On Dismantled Railway
      Label: Abandoned or Dismantled
      Description:
      Symbol:MarcHillman_2-1664456473667.png

       

    • Value: Unknown
      Label: Abandoned or Dismantled
      Description:
      Symbol:MarcHillman_3-1664456473667.png

       

    • Value: Abandoned On Abandoned Railway
      Label: Abandoned or Dismantled
      Description:
      Symbol:MarcHillman_4-1664456473667.png

       

    • Value: Abandoned On Operational Railway
      Label: Abandoned or Dismantled
      Description:
      Symbol:MarcHillman_5-1664456473667.png

       

    • Value: Dismantled
      Label: Abandoned or Dismantled
      Description:
      Symbol:MarcHillman_6-1664456473668.png

       

    • Value: Abandoned On Dismantled Railway
      Label: Abandoned or Dismantled
      Description:
      Symbol:MarcHillman_7-1664456473668.png

       

    • Value: Abandoned
      Label: Abandoned or Dismantled
      Description:
      Symbol:MarcHillman_8-1664456473668.png

       

    • Value: Under Construction
      Label: Under Construction
      Description:
      Symbol:MarcHillman_9-1664456473669.png

       

0 Kudos
MarcHillman
New Contributor III

Apparently, what I need to do is access layer.Renderer.UniqueValues and it has all I need. With the object inspector at runtime, I can see all the values I need. However, when I put layer.Renderer.UniqueValues in my code, the IDE says "Error BC30456 'uniquevalues' is not a member of 'Renderer'."

It looks to me I have a bug in the esri libraries 😞

0 Kudos
PreetiMaske
Esri Contributor

First cast the renderer as UniqueValueRenderer and then get uniquevalues

```

var uvr= layer.Renderer as UniqueValueRenderer;

var uv_values= uvr.UniqueValues;

```

0 Kudos
MarcHillman
New Contributor III

That seems to work, but why is it necessary to use this 'trick'? 

0 Kudos