Select to view content in your preferred language

FeatureLayer in CodeBehind (C#)

2306
4
02-15-2011 04:22 AM
UlfGrimhardt
Deactivated User
Hi

Can anyone tell me how to create a FeatureLayer in CodeBehind?
I also need to implement a Where-Clause in my FeatureLayer and dont no how to do that either.
Additionally i would like to know if it is possible to dynamically add Values to the Where Clause.

For Examaple:
FeatureLayer.Where = Number = XY OR Number = XYZ

Somehow like this i think the normal way would be. But i have a List with lots of Numbers and i would like to add a Graphic to every Feature with an entry in that List.

Thanks in Advance!
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
The following XAML-code
            <esri:FeatureLayer ID="MyFeatureLayer"
                    Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0" 
                    Where="POP1990 > 100000" />

is equivalent to:
 double number = 100000;
 FeatureLayer l = new FeatureLayer()
 {
  ID = "MyFeatureLayer",
  Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0",
  Where = string.Format("POP1990 > {0}", number)
 };
 MyMap.Layers.Add(l);

You can use string.Format() with a number argument.
0 Kudos
UlfGrimhardt
Deactivated User
Ok thanks for your answer!

I tried the following code but always get error. Whats wrong with the "Where" part?

        private void btn_phoehe_Click(object sender, RoutedEventArgs e)
        {
            FeatureLayer l = new FeatureLayer()
            {
                ID = "MyFeatureLayer",
                Url = "http://XXXX/ArcGIS/rest/services/Test/MapServer/0",
                Where = "Name=Peter"            };
            map.Layers.Add(l);
        }
0 Kudos
UlfGrimhardt
Deactivated User
Ok i got it.

But is it possible to Filter for all Features that are part of a Array?
I have an Array with 20 Numbers. Now i would like to Filter for only those Features, whose Name is equal to the Numbers in my Array.
0 Kudos
JenniferNery
Esri Regular Contributor
Your Where clause would be something like

fcode in (10201, 11201)

where fcode is field name and 10201 and 11201 are elements of your number array.

You can use the following conversion from array to comma-delimited string.
int[] numbers = new int[] { 10201, 11201 };
string where = string.Format("fcode in ({0})", string.Join(",", Array.ConvertAll(numbers, i => i.ToString())));
0 Kudos