38 votes
Accepted

Selecting features using expression with PyQGIS

Nowadays : QGIS 3.x Get the layer reference: layer = iface.activeLayer() Select features by expression: layer.selectByExpression("\"ogc_fid\"=482") Before QGIS 2.16 Follow ...
user avatar
23 votes
Accepted

Deleting selected features using PyQGIS

You can loop over the iterator and get the id() for every feature in it: with edit(layer): # build a request to filter the features based on an attribute request = QgsFeatureRequest()....
user avatar
18 votes
Accepted

Selecting features with equal field value interactively on QGIS map

Very nice use case for yet another handy QGIS feature: Layer actions! Here the steps to configure your layer action: Open your layer Properties dialog. Click on menu Actions. Click on the green cross ...
user avatar
17 votes
Accepted

Select by Attributes - Strings with < 5 characters

Using the Select by Attributes tool, you could enter the following SQL query to select all features with less than 5 characters in the ZIP field: CHAR_LENGTH("ZIP") < 5
user avatar
  • 72.4k
15 votes
Accepted

Selecting multiple attributes, greater and less than

I think you need to use the following instead: "GRIDCODE" >= 10 AND "GRIDCODE" < 15 You need to switch the => operators and specify again the attribute field for the second term (i.e. < ...
user avatar
  • 72.4k
12 votes

Selecting all features except one using QGIS?

How about "ONScode" != '17UB' != means "not equal to".
user avatar
11 votes

Creating new layer from selection in QGIS

In QGIS 2.6.2 Brighton, you can do the following: Select features Right click on the layer Save as... Select the option "Save only selected objects" Save That should do
user avatar
  • 111
11 votes

Select By Attribute: Between Two Numbers

The number values in your example query have quotation marks around them, so it looks like the problem is that your house numbers are stored as strings and not as numbers. You can check by right-...
user avatar
  • 12k
11 votes

Select features using an expression, QGIS

There are two possibilities when you want to select several value. The first is to use the OR operator : "Parametro" = 'alfa-Hexaclorociclohexano' OR "Parametro" = 'beta-Hexaclorociclohexano' OR "...
user avatar
  • 12k
11 votes
Accepted

Selecting multiple field values using range in QGIS

Use this expression: ("ALTURA_SOB" >=500 AND "ALTURA_SOB" <= 1200) OR ("ALTURA_SOB" >=2000 AND "ALTURA_SOB" <= 2500)
user avatar
  • 3,479
10 votes

How to select and zoom in features from a QGIS Python Plugin

Follow these 5 steps in the QGIS Python console: Get the layer reference (I assume the layer is at the top of the ToC): l = iface.mapCanvas().layers()[0] Get a featureIterator from an expression: ...
user avatar
10 votes

Selecting polygon with the largest area in QGIS

You would be better off using "Select by expression" instead of "Select by attribute". Your expression should be something like: "AREA" = maximum("AREA") ...
user avatar
  • 1,966
10 votes
Accepted

Selecting latest record by date

QDateTimeobject is returned from maximum, but inspection_date is probably QDate. And to_date converts the result to QDate object. "inspection_date" = to_date(maximum("inspection_date&...
user avatar
10 votes
Accepted

QGIS Select points within ONE polygon in a different layer

If you check "Select features only" option for the polygon layer, you can select the points within the selected polygon.
user avatar
9 votes

Exporting feature class into multiple feature classes based on field values using ArcGIS Desktop?

I used @AlexandreNeto's script and updated it for ArcGIS 10.x users. Mainly you now have to import "arcpy" instead of "arcgisscripting": # Script created to separate one shapefile in multiple ones by ...
user avatar
9 votes

Selecting contours which heights are integers?

Here is another query option. It largely does the same as the answers listed above but is (in my opinion) a little bit easier to customise for different scenarios. To display any contour divisible by ...
user avatar
  • 91
9 votes
Accepted

Saving/exporting selected features in QGIS

For QGIS 2.x versions You are doing fine, but just need to go to next step. Tick on Save only selected features.
user avatar
  • 29.1k
9 votes

Showing string that contains specific number in QGIS

It is unclear to me what you want to do exactly. The expression you are using is correct. It highlights the points with the correct expression because you are using "Select By Expression" ...
user avatar
  • 36.3k
9 votes
Accepted

Processing tool to invert/switch selection in Graphical Modeler

Yes, you can use "select by expression" tool and insert if(is_selected() is false,true,false) as expression. This will allow inverting your selection in graphical modeler. Result:
user avatar
  • 25.5k
9 votes
Accepted

Exporting features when column value between specific percentiles

You can create a new function which returns a percentile value, then, compare the field value. Open Select Feature by Expression tool Create new function in the Function Editor using the script below....
user avatar
  • 3,479
9 votes

QGIS Select points within ONE polygon in a different layer

Using selection by expression: overlay_within ( LAYER:= 'POLYGON', filter:= "COD_PROV" = 88)
user avatar
  • 3,637
8 votes

Assign multiple colors to features within a single vector layer

Alternatively to categorized styling, if you want to play a bit with colour you can try to code it by yourself: CASE WHEN Field = 'Value1' THEN color_rgb(0, 176, 80) WHEN Field = 'Value2' ...
user avatar
  • 303
8 votes
Accepted

Why does the Select by expression dialog not show field values?

The information you are looking for is hidden in a panel that is collapsed/minimized on the right-hand side of the dialog. Here's how you can access it:
user avatar
  • 82k
8 votes
Accepted

Select features from the attributes table without opening it in QGIS

Sure, here some options: Use the processing toolbox and one of these tools: Select by Expression Select by Attribute Select by Location Or directly extract them via processing tools: Extract by ...
user avatar
  • 25.5k
8 votes

Selecting items in the attribute column based on items of the other layer in QGIS

I can suggest a solution with PyQGIS. Proceed with Plugins > Python Console > Show Editor and paste the script below layer1 = QgsProject.instance().mapLayersByName('Final cellsites')[0] layer2 = ...
user avatar
  • 24k
7 votes

Exporting feature class into multiple feature classes based on field values using ArcGIS Desktop?

This is an even easier way to do this... and it outputs into a GDB. http://www.umesc.usgs.gov/management/dss/split_by_attribute_tool.html download the tool from USGS, took me 3 minutes to do what i ...
user avatar
7 votes
Accepted

Selecting Layer by Attribute using SQL and variable in ArcPy

It always helps to include the error message you're getting with the script, so I'm guessing a bit, but the correct format for your SQL where clause is probably '"LCC_DRN_ID" = \'{0}\''.format(...
user avatar
  • 1,468
7 votes

Selecting features using expression with PyQGIS

This worked for me from the QGIS Python Console layer = qgis.utils.iface.activeLayer() layer.selectByExpression(" \"ogc_fid\" = '{}' ".format(482))
user avatar
7 votes

Using Select Layer by Attribute in ArcPy?

You'll make life simpler in the future by using Add Field Delimiters. This will work for shapefiles, feature classes in a file geodatabase, personal geodatabase, etc. You might find that str.format() ...
user avatar
  • 11.5k
7 votes
Accepted

Selection by attribute string with wildcard as part of name in ArcGIS Desktop?

From the page on SQL reference for query expressions used in ArcGIS To include the percent symbol or underscore in your search string, use the ESCAPE keyword to designate another character as the ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible