views:

53

answers:

1

Where can i learn how to query the layers of an ESRI Map? Can anybody please help me. It is urgent. I need to query the layer of esri maps and store the data in dictionary. Pls help

A: 

The ESRI Silverlight SDK provides a QueryTask object for this. Your map must be published with ArcGIS Server providing a REST endpoint (URL) to query against. Check out the ESRI sample page. They include several examples of different styles of queries.

In its simplest form, a query will look like...

void DoQuery()
{
    QueryTask queryTask = new QueryTask("[AGS Service Endpoint]"); // Service url typically in format of http://[servername]/ArcGIS/rest/services/[ServiceName]/MapServer/[LayerId]
    queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;

    ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
    query.Where = "1=1"; // Return all features
    query.OutFields.Add("*"); // Return all fields
    queryTask.ExecuteAsync(query);
}

void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
    FeatureSet featureSet = args.FeatureSet;

    if (featureSet == null || featureSet.Features.Count == 0) return;

    foreach (Graphic feature in featureSet.Features)
    {
        // feature.Attributes is a type Dictionary<string, object> containing all attributes. Do something with it.
    }
}
Brandon Copeland
Thanks a lot Brandon :)
MBG