Select to view content in your preferred language

can not find feature

632
2
01-27-2012 01:31 PM
ForamParikh
Regular Contributor
Hello everyone,

I am trying to get graphic from feature layer in point layer i am getting graphic but in polygon layer i am not able to find that graphic.below is code.
<esri:Map x:Name="MyMap"  WrapAround="True"  Extent="-13249239.0000,3982263.0000,-13087512.0000,4087355.0000">
            <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
                />
            <esri:FeatureLayer ID="DynamicLayer" Opacity="0.01"
                Url="http://pipelineforthefuture.org/ArcGIS/rest/services/GIC4/Point/MapServer/0"
                />
            <esri:FeatureLayer ID="polygonlayer" Opacity="0.01"
                Url="http://pipelineforthefuture.org/ArcGIS/rest/services/GIC4/Poly/MapServer/0"
                />
            <esri:GraphicsLayer ID="glayer"></esri:GraphicsLayer>
        </esri:Map>

and on button click it is like
  private void button2_Click(object sender, RoutedEventArgs e)
        {
            FeatureLayer featureLayer = MyMap.Layers["polygonlayer"] as FeatureLayer;
            Graphic gpoly = new Graphic();
            gpoly = featureLayer.Graphics.FirstOrDefault(gtt => (int)gtt.Attributes["LOCATION_ID"] == 395);
        }

the polygon with 395 is available in map layer but here i am getting error object reference not set to an instance of object.

the above code is working fine for point layer as well it is working if i create feature service.but here i want to use map service.you can see from url my services are on and also if you query on 395 location_id that feature is

Please help,

Thanks
Foram
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
Change it to:
gpoly = featureLayer.Graphics.FirstOrDefault(gtt =>gtt.Attributes["LOCATION_ID"] != null && (int)gtt.Attributes["LOCATION_ID"] == 395);

or
gpoly = featureLayer.Graphics.FirstOrDefault(gtt =>(int?)gtt.Attributes["LOCATION_ID"] == 395);

since Attribute["LOCATION_ID"] can be null, it cannot cast to int. Also if the Key is not DisplayField, you need to include it in your FeatureLayer.OutFields.
0 Kudos
ForamParikh
Regular Contributor
Thanks it worked!!you saved my lot of time.

Thanks once again!!
0 Kudos