ThinkGeo.com    |     Documentation    |     Premium Support

Combining QueryTools

Hi,

I was wondering what would be the best way to combine querytool operations? For example I would like to use GetFeaturesByColumnValue() and GetFeaturesInsideBoundingBox() to get all features inside a bounding box with a specific column value?

Thanks,
Jonathan

Thanks Jonathan,
If you are using shape file feature source. You need call GetFeaturesInsideBoundingBox() to get feature collection. Then loop the collection to filter the records by column value. Because for the shape file we use R-Tree index(ids file) to do the spatial query. it not support the SQL statement.
If you are using the database which already support the Sql spatial query. You could build your statement to do the querying.

Something like this.

   var connectionString = @"Data Source=\\192.168.0.3\Internal Test Data\Sqlite\Mapping.sqlite";
            var ne_road10m_linestring = new SqliteFeatureLayer(connectionString, "Segments", "geomID", "geom");
            ne_road10m_linestring.Name = ne_road10m_linestring.TableName;
            ne_road10m_linestring.WhereClause = $"WHERE ReplicationState = 1 and [Contain statement]";

Thanks

Frank

Hi Frank,

Thanks, we are using our own SQLite database custom layer type, and that does support spatial queries. It is looking like I would need to do do the within bounding box to get the features in the area, then process from there myself. I was thinking of possibly using LINQ on the returned collection of features to get all distinct values for a column and then I would know which value styles are used. This is for generating a legend for a printed map cut from a bigger map.

Regards,
Jonathan

Thanks Jonathan,
If you could use the LINQ. we don’t need limit to the SQLite layer. You can do it for any layer.

 var restaurantsLayer = any layer;
            var features = restaurantsLayer.FeatureSource.GetFeaturesInsideBoundingBox(mapView.CurrentExtent, ReturningColumnsType.AllColumns);
            var result = features.GroupBy(d => d.ColumnValues["xxx"].ToString())
                       .Select(grp => grp.First())
                       .ToList();

You need put using System.Linq; to the top of the class file.

More detail about the LINQ you can check here.

Thanks

Frank

Hi Frank,

Thanks, that’s very useful. It turns out that using LINQ’s own distinct was effective. Like:
var usedValues = features.Select(x => x.ColumnValues[style.ColumnName]).Distinct();

I also did something similar for range values, not quite so straightforward but still OK.

Regards,
Jonathan

Thanks Jonathan,
Good to know it works. go ahead let us know if you have any more questions.

Thanks

Frank