HeatMap from QueryTask

563
5
09-15-2011 06:10 AM
gabrielvazquez
New Contributor
I am attempting to create a heatmap layer from points in a graphic layer, which are the result of various Querytasks and Findtasks. However, I am having issues assisging the geometry from the query results.

I found a good example that got me some of the way through the problem, but this works for featurelayers. Similar to this thread http://forums.arcgis.com/threads/34724-HeatMapLayer-based-on-points-from-FeatureLayer.

Does some one have an example of code they can provide for mapping query task results to a heatmaplayer?
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
You should be able to do something like:
void QueryTask_ExecuteCompleted(object sender, QueryEventArgs e)
{
 if (e.FeatureSet == null) return;
 var heatLayer = MyMap.Layers["MyHeatMapLayer"] as HeatMapLayer;
 foreach (var g in e.FeatureSet)
 {
  if (g.Geometry is MapPoint)
  {
   var mp = Geometry.Clone(g.Geometry) as MapPoint;
   heatLayer.HeatMapPoints.Add(mp);
  }
 }
}
0 Kudos
gabrielvazquez
New Contributor
Great, thank you Jennifer.
0 Kudos
gabrielvazquez
New Contributor
Jennifer,
Thank you. I able to get it working, just need to fix the code to allow the user to turn the heat map layer off/on outside of the query.

However, on another note. I was able to get the HeatMap function to work for QueryTasks. However, I have several FindTasks that we are also using. But the FindTask and FindResult doesnt seem to support 'Geometry' as it does with a FeatureSet with a QueryTask.

Do you know if there is a work around for this?
0 Kudos
JenniferNery
Esri Regular Contributor
FindTask.FindParameters also have a ReturnGeometry property, which you can set to True.
findParameters.ReturnGeometry = true;


In the ExecuteCompleted event handler, notice that you can get geometry:
void findTask_ExecuteCompleted(object sender, FindEventArgs e)
{
 foreach (var r in e.FindResults)
 {
  var g = r.Feature.Geometry;
 }  
}
0 Kudos
gabrielvazquez
New Contributor
Jennifer,
Thanks. I did have the return Geometry set. Just had to fix the code for the geometry. Thank you.
0 Kudos