Select to view content in your preferred language

Select and assign graphics ......

2882
5
Jump to solution
11-05-2013 08:49 AM
YurongTan
Regular Contributor
I have a query that returns a list of records that are related to various States (polygons) and I want to link those records to the individual States.  I am having problems to extract the individual States from the State boundary GraphicsLayer. here a set of the codes:

private Graphic getStateBoundaryGraphic(string ST)
{
    GraphicsLayer usaGraphics = MyMap.Layers["StatesUSA"] as GraphicsLayer;
    Graphic state = new Graphic();
    foreach (Graphic g in usaGraphics)
    {
        if (g.Attributes["STATE"] == ST) state = g;
    }
    return state;
}

[ERROR MESSAGE:]  "foreach (Graphic g in usaGraphics)" Object reference is not set which is null which is NOT true.

What am I missing?  Thanks
0 Kudos
1 Solution

Accepted Solutions
YurongTan
Regular Contributor
Thanks for all who responded. 

The key is that (1) the Shape column must be included (or existing) in the Map Service Layer and (2) the query's parameter xxx.ReturnedGeometry must be set to true.  Then you can do whatever you want to do (clone, capture attributes, geometry, etc.) with the returned graphic.  Cheers

Thanks

View solution in original post

0 Kudos
5 Replies
PietaSwanepoel2
Frequent Contributor
Is MyMap.Layers["StatesUSA"] a graphics layer

Is STATE an attribute in MyMap.Layers["StatesUSA"]?

Is g.Attributes["STATE"] as string? Try g.Attribute["STATE"].ToString()

Did you define the variable "state" as Graphic?
0 Kudos
YurongTan
Regular Contributor
XAML file: <esri:ArcGISDynamicMapServiceLayer ID="StatesUSA" Opacity="0.8" Visible="True"
                        Url="http://oigcodevgis:6080/ArcGIS/rest/services/StateBoundary/MapServer" />

Attributes:
OBJECTID ( type: esriFieldTypeOID , alias: OBJECTID )
SFIP ( type: esriFieldTypeString , alias: SFIP , length: 4 )
SNAME ( type: esriFieldTypeString , alias: SNAME , length: 24 )
ST ( type: esriFieldTypeString , alias: ST , length: 4 )
GlobalID ( type: esriFieldTypeGlobalID , alias: GlobalID , length: 38 )
Shape ( type: esriFieldTypeGeometry , alias: Shape )
Shape.STArea() ( type: esriFieldTypeDouble , alias: Shape.STArea() )
Shape.STLength() ( type: esriFieldTypeDouble , alias: Shape.STLength() )


C# file: 
myPolyGraphics = MyMap.Layers["StatesUSA"] as GraphicsLayer;

It says myPolyGraphics is NOT defined or nonreferenced.  Any clue?  Thanks
0 Kudos
brettangel
Frequent Contributor
Have you tried referencing it using the GraphicsLayer.ID or GraphicsLayer.GetValue(MapApplication.LayerNameProperty, "MyGraphicsLayer") might work.
0 Kudos
KarenEllett
Regular Contributor
It looks like the issue is that STATE is not actually an attribute in your feature class.  Should you be referencing SNAME instead?
0 Kudos
YurongTan
Regular Contributor
Thanks for all who responded. 

The key is that (1) the Shape column must be included (or existing) in the Map Service Layer and (2) the query's parameter xxx.ReturnedGeometry must be set to true.  Then you can do whatever you want to do (clone, capture attributes, geometry, etc.) with the returned graphic.  Cheers

Thanks
0 Kudos