ThinkGeo.com    |     Documentation    |     Premium Support

QueryTools is Null

I have been using the QueryTools property of my shape files layers without a problem for the last week. Then suddenly, it is always null.


This is how I add my point layers:


        private Layer CreatePointLayer(string layerName, string fileName, PointStyle pointStyle, string displayColumnName, GeoColor displayColumnColour, GeoFont displayColumnFont)

        {

            Logger.Log("Loading Point Layer: " + fileName, Adapt.Utilities.Common.Logger.MessageType.Information, this.GetType().FullName);

            ShapeFileFeatureLayer.BuildIndexFile(MapPath(fileName), BuildIndexMode.DoNotRebuild);

            var myLayer = new ShapeFileFeatureLayer(MapPath(fileName));

            myLayer.RequireIndex = true;

            myLayer.Name = layerName;


            myLayer.ZoomLevelSet.ZoomLevel19.DefaultPointStyle = pointStyle;

            myLayer.ZoomLevelSet.ZoomLevel19.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            myLayer.ZoomLevelSet.ZoomLevel19.DefaultTextStyle = new TextStyle(displayColumnName, displayColumnFont, new GeoSolidBrush(displayColumnColour));

            myLayer.DrawingMarginPercentage = 50;


            return myLayer;

        }


 


This is in the Map1_Click event where I need QueryTools but it's null. The code inside the first if statement is never hit because QueryTools is always null.


            foreach (ShapeFileFeatureLayer layer in Map1.StaticOverlay.Layers)

            {

                layer.FeatureSource.Open();


                if (layer.QueryTools != null)

                {

                    //Get columns in layer

                    var columns = layer.QueryTools.GetColumns();


                    //Add column names to a list

                    var columnNames = new List<string></string>();

                    foreach (var column in columns)

                    {

                        columnNames.Add(column.ColumnName);

                    }


                    //Query the layer for features within one meter of point clicked

                    var features = layer.QueryTools.GetFeaturesWithinDistanceOf(e.Position, GeographyUnit.Meter, DistanceUnit.Meter, 2, columnNames);

                    layer.FeatureSource.Close();


                    //Add features to dictionary

                    layerDictionary.Add(layer.Name, features);

                }

            }


 



Christian 
  
 You need to open the layer before using QueryTools. Here attached is the correct code.  
  
 
      foreach (ShapeFileFeatureLayer layer in Map1.StaticOverlay.Layers)
      {
            layer.Open();
            if (layer.QueryTools != null)
            {
                //Get columns in layer
                var columns = layer.QueryTools.GetColumns();

                //Add column names to a list
                var columnNames = new List();
                foreach (var column in columns)
                {
                    columnNames.Add(column.ColumnName);
                }

                //Query the layer for features within one meter of point clicked
              var features = layer.QueryTools.GetFeaturesWithinDistanceOf(e.Position, GeographyUnit.Meter, DistanceUnit.Meter, 2, columnNames);

                //Add features to dictionary
                layerDictionary.Add(layer.Name, features);
            }
layer.Close();
      }
 
  
 As QueryTools is a mirror of the query methods of FeatureSource, another option is opening the FeatureSource and using the method layer.FeatureSource.GetFeaturesWithinDistanceOf() directly. Have a try if you are interested. 
  
 Ben.

I'm having problems with this.


i'm using a shape file, when i GetFeaturesWithinDistanceOf(...), the map stop working. 


Could it be somehow locked?


 



I think that we would have to look at how the GetFeaturesWithinDistanceOf method is behaving with the shapefile you are using. Can you you attach the shapefile? If it is too big or if you feel unconfortable sending your shapefile in the Discussion Forum. Please, contact Support for that at support@thinkgeo.com. Thank you.

Please see: 
 gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/12/aft/7410/afv/topic/Default.aspx 
 There is a link to sample code and to shapefiles, and a small video showing the problem i’m having. 


Rui, 
  
 Please refer to the response at gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/12/aft/7410/afv/topic/afpgj/1/Default.aspx#16495
  
 Thanks, 
  
 Johnny