Hoppa till huvudinnehållet

How to capture field names

Kommentarer

12 kommentarer

  • Permanently deleted user

    I have been looking for the same thing. I believe there is a new action where you can query the service to get information but I am not sure how you go about parsing data out of it. 

    0
  • Chris Dunlop

    Approaching it through the featureset returned by a query, I can get a count of the fields through <featureset>.Features.Item(0).Attributes.Count()   I'm just not sure how to do the final step of looping through the fields to get their names.

     

    0
  • Permanently deleted user

    You could use a ForEach loop to say "ForEach item in query_result.features(index).attributes" 

    and then use item.key and item.value to get the field name and value of the field for that feature. If you are only expecting one result in your featureset you can replace index with 0 as Chris showed above.

    -Victoria

    0
  • Chris Dunlop

    Victoria, can you elaborate on exactly how to do this?  In the ForEach activity, what is the TypeArgument that I need to use?  Do I have to import anything?

    Thanks

    Chris

    0
  • Permanently deleted user

    The TypeArgument would be 'System.Collections.Generic.KeyValuePair<System.String, System.Object>'. You shouldn't have to import anything to do this.

    -Victoria

    0
  • Chris Dunlop

    Hmmm, still not working.  In my ForEach activity, I've set my TypeArgument to System.Collections.Generic.KeyValuePair<System.String, System.Object>  My Values are set to queryREsults.features(0).attributes.  When I run it, I get an error:

     

    <Event Timestamp="2012-02-06T11:52:28.3261195-08:00" Level="ERROR" Identity="Guest"><Message>Exception has been thrown by the target of an invocation.

     

    Workflow 'test' failed

     

    Aborted exception: 'Type 'System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.String,System.Object]]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types.'.

     

    Type 'System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.String,System.Object]]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types.</Message></Event>

     

    I was able to loop through the field names by first creating a variable <flds> of type ICollection(String) and assigning it to queryResults.Features(0).Attributes.Keys.  Then I looped through each item in flds.ToString()

     

    Ultimately, I want to be able to capture both the field names and their aliases.  Wouldn't it make more sense to approach this using the Featureset Fields property?  I can't make any headway on this. The ArcGIS Silverlight API reference ways that the Featureset Fields property is a List(Of Field).  Shouldn't I be able to loop through this list and grab the fields' names and aliases?  I can't seem to access the list however - If I try even a count, it just reports "Object reference not set to an instance of an object".  Am I missing something obvious?  (I apologize for my complete blundering about and lack of understanding when it comes to interpreting API References).

     

    Chris

    0
  • Ryan Cooney

    Try this: (http://data.latitudegeo.com/community/getfieldnames.zip) getfieldnames.zip . You'll need to add your own error checking but it extracts the field names from the attributes of the first feature in a FeatureSet.

    --Ryan

    0
  • Chris Dunlop

    Thanks Ryan.  That works for getting the field names.

    Any thoughts on my question about accessing field names and aliases through the featureset Fields property?  

    I created a variable fieldList, of type System.Collections.Generic.List<ESRI.ArcGIS.Client.Field>.  I set its default value to New List(Of ESRI.ArcGIS.Client.Field).  I the assigned fieldList to queryResults.Fields.  However when I try to access anything in that list, it reports "Object reference not set to an instance of an object"  

    Any ideas what might be wrong?

    Thanks!

    Chris

    0
  • Ryan Cooney

    Hi Chris,

    When the QueryTask runs it makes a request to ArcGIS Server. The response does not contain any field information so the Fields property of the FeatureSet is null. You might want to try the FieldAliases property (this seems to be populated).

    --Ryan

    0
  • Chris Dunlop

    Perfect, thanks Ryan.  The Featureset FieldAliases property contains both the (field name,field alias) in the dictionary (key,value).  Exactly what I was looking for.

     

    Chris

    0
  • Permanently deleted user

    Hi Ryan,

     

    I hope you are still listening.  Where is that link gone?

    " /Data/Sites/1/userfiles/1725/getfieldnames.xaml. "

    This is exactly what I am looking for!

    Please reinstate,

    0
  • Permanently deleted user
    (http://data.latitudegeo.com/community/getfieldnames.zip) Ryan's workflow can now be found here.
    0

Du måste logga in om du vill lämna en kommentar.