Select to view content in your preferred language

Time extent from querytask featureset

812
7
01-05-2012 07:53 AM
gabrielvazquez
Deactivated User
Running a simple query task, which displays through a graphic layer. The querytask is using a time enabled server layer. I am able to map the layer to a timeslider when I pull the layer in as a featurelayer on the XAML, however not when displayed through a querytask. 

I am trying to bind the querytask time extent results to a timeslider. However, i'm not sure exactly how to extract a startdate and enddate from the featureSet results.

Below is some of the code after the querytask is completed. Creating DateTimes to hold the start and end dates, and define the extent and timespan intervals for the slider. Not sure if there is any easier way to do this, or if im missing something other than mapping the featureSet result date extent.

/*was thinking I could easily point these to the featureset start and end dates to these variables and use them to for timeslider time extent. Not sure how to do so though*/

DateTime timeSliderStart;
DateTime timeSliderEnd;

ESRI.ArcGIS.Client.TimeExtent myTimeExtent = new ESRI. ArcGIS.Client.TimeExtent (timeSliderStart, timeSliderEnd);

Timespan myTimespan = new TimeSpan (1, 0, 0, 0);

System.Collections.Generic.IENumerable<DateTime> myIEnumerableDates = null;
my IEnumerableDates = ESRI.ArcGIS.Client.Toolkit.TimeSlider.CreateTimeStopsByInterval (myTimeExtent, myTimeSpan);

IncidentTimeSlider.Intervals = myIEnumerables;
0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
In this SDK sample (using FeatureLayer) http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#TimeFeatureLayer
<esri:TimeSlider x:Name="MyTimeSlider" 
      Height="20" TimeMode="TimeExtent"
                        MinimumValue="{Binding ElementName=MyMap, Path=Layers[EarthquakesLayer].TimeExtent.Start, Mode=OneWay}" 
         MaximumValue="{Binding ElementName=MyMap, Path=Layers[EarthquakesLayer].TimeExtent.End, Mode=OneWay}"
                        Value="{Binding ElementName=MyMap, Path=Layers[EarthquakesLayer].TimeExtent, Mode=OneWay}" >
                    </esri:TimeSlider>


Since you are using GraphicsLayer, there is no TimeExtent property that you can use. You would have to look at Time Info to know the TimeExtent where there would be data. For example: http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer/0. And then use the static helper methods TimeSlider.CreateTimeStopsByTimeInterval or CreateTimeStopsByCount. In the Time Info, you will also find which field to use (i.e. "Date_"), so you might be able to use Linq query to get the oldest feature and use that as MinimumValue.
0 Kudos
gabrielvazquez
Deactivated User
Jennifer,
Thanks, I will try to use linq to get the start/end dates from the date field of the queried layer. I used linq previously to obtaine distinct and ordered values.
0 Kudos
gabrielvazquez
Deactivated User
I was able to use LINQ to obtain the minimum and maximum dates from the Incidentdate field. I am then able to get the appropiate timeextent and timespan applied to the timeslider using CreateTimeStopsByTimeInterval. The slider seems to be recieving the correct result dates, however it doesnt seem to be communicating with the graphic layer.

Do I define the sliders relationship to the layer within the XAML similar to the linking a slider to feature layer,
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#TimeFeatureLayer

or should this be defined within the cs.
0 Kudos
DarinaTchountcheva
Frequent Contributor
Gabriel,

You will have to bind the Value of the TimeSlider to the Map.TimeExtent property. And also each one of the graphics in the feature set returned by the query task will need its TimeExtent property set to the IncidentDate.

[HTML]<esri:Map TimeExtent="{Binding ElementName=timeSliderName,Path=Value}" />[/HTML]

//loop through all graphics and set the time extent
graphic.TimeExtent = new TimeExtent(incidentDateOfTheGraphic);


I did the binding of the Map TimeExtent property in code behind, but I hope the xaml above is correct, and will work also.

Good Luck!
0 Kudos
gabrielvazquez
Deactivated User
Thanks for the help. I did have my timeslider value linked to the map

<esri:Map TimeExtent="{Binding ElementName=timeSliderName,Path=Value}" />

But i'm a little confused with where you say each one of the graphics in the feature set returned by the query task will need its TimeExtent property set to the IncidentDate. Graphic.TimeExtent = new TimeExtent(incidentDateOfTheGraphic);

Below is my code that i'm using, perhaps you can look at it and make some recommendations.

var TimeTemp = (from g in args.FeatureSet.Features
                                       select g.Attributres["IncidentDate"]);
DateTime TimeSliderStart = Convert.ToDateTime(TimeTemp.Min().ToString());
DateTime TimeSliderEnd = Convert.ToDateTime(TimeTemp.Max().ToString());

IncidentTimeSlider.MinimumValue = TimeSliderStart;
IncidentTimeSider.MaximumValue = TimeSliderEnd;

ESRI.ArcGIS.Client.TimeExtent myTimeExtent = new ESRI.ArcGIS.Client.TimeExtent(TimeSliderStart, TimeSliderEnd);

TimeSpan myTimeSpan = new TimeSpan(1, 0, 0, 0);

System.Collection.Generic.IEnumerable<DateTime> myIEnumerableDates = null;

myIEnumerableDates = ESRI.ArcGIS.Client.Toolkit.TimeSlider.CreateTimeStopsByTimeInterval (myTimeExtent, myTimeSpan);

IncidentTimeSlider.Intervals = myIEnumerableDates;
0 Kudos
DarinaTchountcheva
Frequent Contributor
Gabriel,

In QueryTask_ExecuteCompleted you can do something like this:

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

            if ((args.UserState as string) == "incidentQuery")
            {
                DateTime incidentDate;
                foreach (Graphic graphic in args.FeatureSet.Features)
                {
                    if (DateTime.TryParse(graphic.Attributes["IndidentDate"].ToString(), out incidentDate))
                          graphic.TimeExtent = new TimeExtent(incidentDate);
                }

                //...... more code (if you have any) 

            }
}



Good Luck!
0 Kudos
gabrielvazquez
Deactivated User
Got it to work. Used your code below, had to change it a little, but understand now.

foreach (Graphic graphic in args.FeatureSet.Features)
                {
                    if (DateTime.TryParse(graphic.Attributes["IndidentDate"].ToString(), out incidentDate))
                          graphic.TimeExtent = new TimeExtent(incidentDate);
                }

Awesome and thanks for all the help AGAIN.
0 Kudos