HowTo Get Field Names From Layer?

5896
7
05-05-2010 03:55 PM
RyanCoodey
Occasional Contributor III
So I have a ArcGISDynamicMapServiceLayer, which has sub layers inside of it... how do I get the names of the fields inside that sublayer?

Thanks a lot!
0 Kudos
7 Replies
DominiqueBroux
Esri Frequent Contributor
I don't think there is a SL API giving the fields for ArcGISDynamicMapServiceLayer but you can get the info by requesting the REST point.

For example http://server.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Population_Density/MapServer/3?... gives this result:
{
  "id" : 3, 
  "name" : "Counties", 
  "type" : "Feature Layer", 
  "geometryType" : "esriGeometryPolygon", 
  "description" : "This thematic map presents the population density in the United States in 2009. Population density is the number of people per square mile. It is calculated by dividing the total population count of geographic feature by the area of the feature, in square miles. The area is calculated from the geometry of the geographic feature in projected coordinates. The geography depicts states at greater than 25m scale, counties at 1m to 25m scale, Census Tracts at 250k to 1m scale, and Census Block Groups at less than 250k scale. The map has been designed to be displayed with semi-transparency of about 50% for overlay on other base maps, which is reflected in the legend for the map.  For more information on this map, visit us online at http://goto.arcgisonline.com/maps/Demographics/USA_Population_Density", 
  "definitionExpression" : "", 
  "copyrightText" : "Copyright:© 2009 ESRI", 
  "minScale" : 25000000, 
  "maxScale" : 750001, 
  "extent" : {
    "xmin" : -19840230.3902342, 
    "ymin" : 2144435.3403614, 
    "xmax" : -7452840.46520711, 
    "ymax" : 11537127.3143578, 
    "spatialReference" : {
      "wkid" : 102100
    }
  }, 
  "displayField" : "NAME", 
  "fields" : [
    {"name" : "Shape", "type" : "esriFieldTypeGeometry", "alias" : "Shape"}, 
    {"name" : "ID", "type" : "esriFieldTypeString", "alias" : "ID"}, 
    {"name" : "NAME", "type" : "esriFieldTypeString", "alias" : "Name"}, 
    {"name" : "ST_ABBREV", "type" : "esriFieldTypeString", "alias" : "State Abbreviation"}, 
    {"name" : "TOTPOP_CY", "type" : "esriFieldTypeInteger", "alias" : "2009 Total Population"}, 
    {"name" : "POPDENS_CY", "type" : "esriFieldTypeDouble", "alias" : "2009 Population Density"}, 
    {"name" : "LANDAREA", "type" : "esriFieldTypeDouble", "alias" : "Land Area in Square Miles"}, 
    {"name" : "Shape_Length", "type" : "esriFieldTypeDouble", "alias" : "Shape_Length"}, 
    {"name" : "Shape_Area", "type" : "esriFieldTypeDouble", "alias" : "Shape_Area"}
  ], 
  "parentLayer" : {"id" : 0, "name" : "USA Population Density"}, 
  "subLayers" : []
}


But you will need a little code to deserialize this.

/Dominique
0 Kudos
RyanCoodey
Occasional Contributor III
Great, thanks a lot for that info... I guess I will have to figure out how to request data from a REST service.  Know any good examples of this?  Thank you!
0 Kudos
DominiqueBroux
Esri Frequent Contributor
If you have the version 2 of the API, another option you might consider is to create a FeatureLayer which will give you the list of fields after the initialization step.

Example: Declare a feature layer in selection only mode in order not to request any data you don't need.
   
<esri:FeatureLayer Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/0"
        Mode="SelectionOnly" Initialized="FeatureLayer_Initialized">


Get the fields by handling 'Initialized' event :
private void FeatureLayer_Initialized(object sender, EventArgs e)
{
 FeatureLayer featureLayer = sender as FeatureLayer;
 List<Field> fields = featureLayer.LayerInfo.Fields;

 fields.ForEach(field => Debug.WriteLine(String.Format("Field Name = {0}, Alias = {1}, type = {2}", field.Name, field.Alias, field.Type)));
}


/Dominique
0 Kudos
AlexanderAnkrah
New Contributor III
Hi Guys,

Is it possible to programmatically obtain the Field_Alias from the REST end point for use with the identify task?

This ties in with this post
http://forums.arcgis.com/threads/7793-Identify-How-to-show-Alias-filed-instead-of-Field-Name?p=23968...

Happy if someone could shed some light on this for me

Cheers
0 Kudos
AriRaimundo
New Contributor
Hi guys,

I've created two posts in my technical blog that demonstrates how to do that. I've created an extension method for the ArcGISDynamicMapServiceLayer class. Unfortunally, my blog is in brazilian portuguese but you guys can easily translated it using Google (I guess).

See links below:

Estendendo a ESRI ArcGIS API For Microsoft Silverlight/WPF �?? Parte 1
http://araimundo.blogspot.com/2010/05/estendendo-esri-arcgis-api-for_29.html

Estendendo a ESRI ArcGIS API For Microsoft Silverlight/WPF �?? Parte 2
http://araimundo.blogspot.com/2010/05/estendendo-esri-arcgis-api-for_6136.html

Best regards.

Ari C. Raimundo
Application Developer
Curitiba-PR-Brazil
0 Kudos
vipulsoni
Occasional Contributor
Hi guys,

I've created two posts in my technical blog that demonstrates how to do that. I've created an extension method for the ArcGISDynamicMapServiceLayer class. Unfortunally, my blog is in brazilian portuguese but you guys can easily translated it using Google (I guess).

See links below:

Estendendo a ESRI ArcGIS API For Microsoft Silverlight/WPF �?? Parte 1
http://araimundo.blogspot.com/2010/05/estendendo-esri-arcgis-api-for_29.html

Estendendo a ESRI ArcGIS API For Microsoft Silverlight/WPF �?? Parte 2
http://araimundo.blogspot.com/2010/05/estendendo-esri-arcgis-api-for_6136.html

Best regards.

Ari C. Raimundo
Application Developer
Curitiba-PR-Brazil


Hi Ari,

Thanks a lot for your code it helped me a lot... saved my day, it gives a exact approach for fetching the fields of a DynamicMapServer layer I have been searching for a while for a guide for similar approach and you have done a awesome job and moreover shared your work -- not just giving pointers like in other posts. Thats really cool. Thanks a lot all points to you.
Also by the way Curitiba is a nice cool town.
0 Kudos
SangamLama
New Contributor
Impressive work Ari!! Thanks to you and Google Translate, a combobox in my application isnt empty anymore 😉


Hi Ari,

Thanks a lot for your code it helped me a lot... saved my day, it gives a exact approach for fetching the fields of a DynamicMapServer layer I have been searching for a while for a guide for similar approach and you have done a awesome job and moreover shared your work -- not just giving pointers like in other posts. Thats really cool. Thanks a lot all points to you.
Also by the way Curitiba is a nice cool town.
0 Kudos