44

Not sure if this option ever existed, but the new QGIS version hides a lot of things somewhere else and this seems so simple that I'm kind of convinced it was possible to do this before.

I have quite a large data set with ship tracks. I now want to analyse individual ship tracks (made from point layer with Points2One Plugin). However, it is so crowded that it is hard to look at individual tracks. I don't want to save each single track as a new layer, so I wonder if it is possible to select one track in the Attribute table and display only that one on the map/hide the others?

Taras
  • 32,823
  • 4
  • 66
  • 137
Kristina
  • 1,073
  • 2
  • 12
  • 21
  • IN QGIS 3.18 the Properties of the Layer are organised differently and there is now no General tab. Is there still a Layer Subset option that can be used to filter the display and if so where is it to be found? – Jamie Hartzell May 11 '21 at 08:45

3 Answers3

45

Kadeem's answer will prevent your features from being visible, but they will still be present, if you are trying to identify an individual ship track you may click an invisible feature by mistake. What it seems like you need to do is define your layer so that it's as if those features don't exist. In ArcGIS this would usually be done using a Definition Query, in QGIS the equivalent command is the Layer Subset. Go to the Properties of your layer, in the Source tab click on the button Query Builder (QGIS versions prior to 3.10 this used to be in the General tab, at the bottom in the Feature Subset box), to bring up the following window:

enter image description here

The Query Builder will help you create an SQL query to define what features in your layer should actually be displayed in your project. Note that the value needs to be stated between single quotes. Any features not returned by the query are made invisible, not just visually but entirely (they are not deleted from your data, of course, they're just defined out of existence until you remove the Layer Subset query).

Adrian
  • 115
  • 4
Dan C
  • 12,212
  • 11
  • 57
  • 86
  • Dan, thanks a lot!!! This is what I was looking for, a bit more complicated than I hoped but does the trick! Very helpful, thanks! – Kristina Aug 27 '14 at 16:26
  • That's idd the answer. Nice tip Dan! – kadéem Aug 28 '14 at 14:05
  • Weird. Some time ago I did this and it worked. Now I want to do it again on another layer and the Feature Subset box is grayed out, as well as the button of the QueryBuilder! Any suggestion??? – Patrick Van Den Noortgaete May 12 '15 at 06:51
  • Solved, but not clear why. I saved the changes I made and then the QueryBuilder Button became available... – Patrick Van Den Noortgaete May 12 '15 at 06:58
  • This works, but is painfully complicated for my use case where I need to browse through hundreds of features. I wish there was something like quick filters in Excel - just choose attribute and value to make only matching features shown. Sounds like a plugin to be developed? – Simo A. May 04 '16 at 04:29
  • 1
    @SimoA. If your data is in Excel, you could filter it there, add a new field where you convert VALUE to 'VALUE',, then copy and paste that field into the query box using an IN query. – Dan C Oct 11 '16 at 19:47
  • 5
    In QGIS 3.10 you'll find the Query Builder in Layer Properties > Source > section Provider Feature Filter at the bottom right corner. When your subselection is applied, a filter icon appears behind the layer item in the Layers panel – kadéem Jan 07 '20 at 08:32
  • @DanC How can this this kind of query be developed to only display features in current map extent or within a specific polygon layer. – ar-siddiqui Aug 05 '20 at 18:20
31

This is now possible using just selections and a rule-based symbology.

This requires the Expression Plus plugin (for QGIS 2.x. 3.0 has the functionality built in).

Create a rule based symbology with the filter of:

QGIS 3.0+ (from thequerist in the comments):

is_selected()

QGIS 2.12-2.18:

isselected( @layer_name )

Or QGIS 2.8:

isselected( 'ACTUAL_NAME_OF_LAYER' )

Now only the selected features that meet this rule will be shown.

You can also have an ELSE rule for all unselected features.

enter image description here

HeikkiVesanto
  • 16,433
  • 2
  • 46
  • 68
  • 1
    This is exactly what I was looking for - thanks for this answer – geobar Oct 13 '16 at 14:01
  • HeikkiVesanto, where i insert this filter? – newGIS Aug 23 '17 at 20:06
  • I have added a picture. – HeikkiVesanto Aug 24 '17 at 08:32
  • 1
    Using QGIS 2.18.14 and the expression that worked is isselected('layer_name'). Using (@layer_name) returned 0 results. – Techie_Gus Dec 18 '17 at 16:47
  • 3
    In QGIS 3 and above this feature is built in. You can find it under Record and Attributes in the Expression String Builder. Also, you do not need to put the layer name in anymore and do not forget to underscore between is and selected. Here is an example for QGIS 3 and above: is_selected(). – thequerist Oct 02 '18 at 19:54
14

Kristina, I assume there is an attribute in your table which allows you to identify a single track? For example:

  point_id  |  track_id
------------+------------
     1      |     15
     2      |     15
     5      |     24
     6      |     24
     7      |     24

If you open the attribute table, you can find an epsilon symbol (in the figure below, the 4th one).

enter image description here

This allows you to type an expression; for example:

"track_id" = 24

When you confirm, all rows that satisfy your expression (that is: all points that belong to the track with track_id X) are selected. If you then click on the magnifier button, QGIS zooms to your selection in the map canvas. The selected features (points in your case) are highlighted.


What you can do is to apply a rule-based style. As such you can show an individual ship track using a given symbol or marker, and 'not show' all other points by giving them an 'unvisible' marker. The screenshot (part from Layer Properties) below explains how it works:

  • Rule 1: apply the given marker to all points having a value of 24 for track_id
  • Rule 2: apply the given marker (a circle with white fill and white border...) to all points that do not satisfy a track_id value of 24

enter image description here

In fact all points are still there (making them white will not make the rendering taking less time) but at least your eyes can relax!

kadéem
  • 565
  • 4
  • 14
  • Thanks a lot for your answer Kadeem! I am aware of the selection function and this works well, however, I literally have 500,000 points in a small area and just highlighting the tracks I am looking for is not enough, the map is still too crowded and confusing. Do you know if there is a possibility to block all not selected points or something like it? – Kristina Aug 27 '14 at 14:05
  • 3
    I edited my answer with another option below the line. I guess this will help you. – kadéem Aug 27 '14 at 15:53
  • Kadeem, this is so simple but effective - great idea, thanks so much! – Kristina Aug 27 '14 at 15:58