ThinkGeo.com    |     Documentation    |     Premium Support

CustomColumn data not visible when using QueryTools

Greetings. I came across what appears to be a bug in the QueryTools.GetFeaturesWithin method (and possibly others)...


I have a layer that has 23 columns, and ~100 custom columns. When I draw a shape on the map and try to get the points that were selected, I do the following:


private void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)

{

    ShapeFileFeatureLayer layer = this.StaticOverlay.Layers["TPE"] as ShapeFileFeatureLayer;



    var items = layer.QueryTools.GetFeaturesWithin(e.TrackShape, ReturningColumnsType.AllColumns);

}


When I run that, item[0].ColumnValues.Count returns 23, not 123, as expected.  So it seems that "ReturningColumnsType.AllColumns" doesn't, in fact, return all columns.


Oddly enough, if I change the method to below, it pulls the custom columns that I manually request:

 


private void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)

{

    ShapeFileFeatureLayer layer = this.StaticOverlay.Layers["TPE"] as ShapeFileFeatureLayer;



    List<string> columns = new List<string>();

    columns.Add("Foo");

    columns.Add("Bar");


    var items = layer.QueryTools.GetFeaturesWithin(e.TrackShape, columns);

}

 


In this case, items[0].ColumnValues.Count returns 2.  Neither "Foo" nor "Bar" exist in the original 23 columns.



Am I doing something wrong, or is this a bug?


Thanks.

Charley.


 



Charley,


I think the AllColumns enumeration passed in the QueryTools SpatialQuery will only include the columns exists in feature source. If you want to include all the columns including the customized columns, try following way:

worldLayer.FeatureSource.CustomColumnFetch += new EventHandler<CustomColumnFetchEventArgs>(FeatureSource_CustomColumnFetch);
 
void FeatureSource_CustomColumnFetch(object sender, CustomColumnFetchEventArgs e)
{
  if (e.ColumnName == "CustomField1")
  {
     e.ColumnValue = "CustomField1ColumnValue";
  }
 
  //if (e.ColumnName == "CustomField2")
  //{
  //    e.ColumnValue = "CustomField2ColumnValue";
  //}
}
 
Collection<string> allColumns = new Collection<string>();
 
Collection<FeatureSourceColumn> columnsInFeatureSource = worldLayer.QueryTools.GetColumns();
foreach (FeatureSourceColumn columnInFeatureSource in columnsInFeatureSource)

    allColumns.Add(columnInFeatureSource.ColumnName);
}
 
allColumns.Add("CustomField1");
allColumns.Add("CustomField2");
 
spatialQueryResults = worldLayer.QueryTools.GetFeaturesWithin(rectangleFeature, allColumns);

 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Yale. 
  
 Thanks for replying. 
  
 Is there a way to iterate through the customColumns on the feature source?  I will not always know what columns have been added to the custom columns collection. 
  
 If I could iterate through those, it would exactly what I need. 
  
 Thanks. 
 Charley. 


Charley, 
  
   Let me help explain what is going on and maybe we can come up with some solutions.   
  
   The way custom columns work in our system is that anywhere we ask for a column name in something such as on a style or anyplace else we accept any column name even if it is not in the FeatureSource.  When we go to resolve the values of the columns we first go to see if the columns are in the FeatureSource and if not then we raise an event and we allow you to fill in the value with whatever you want.  Note that there is no ‘list’ of custom columns as we allow you to dynamically request fields anytime.  For example you could have a style that makes up random number columns names inside the style.  Those column values only get requested when that style goes to draw as it is dynamical adding the column. 
  
 The situation above make it very difficult for us to ‘know’ about custom column values ahead of time.  In thinking about this I am not sure how many options you have.  The one that pop to mind is for you to query the feature source for its columns then in that list add the custom columns.  Whenever you call the query methods always pass the collection you created.  It is similar to what you did above but just adding the FeatureSource’s columns.  This is pretty easy and will make sure you get all the columns you want.  There may be some other ways but that are much more complex. 
  
 David