New answers tagged select-by-attribute
I came across the same issue last week. Follow this work flow and you'll be able to see selected points, even if they share position with non-selected points: Load your point layer in QGIS and make sure it is in the first position of the ToC. Open the Python Console from Menu Plugins. Copy the next Python code in the Python console and press Enter (you ...
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() Get a featureIterator from an expression: expr = QgsExpression( "\"EXCHANGE_1141_CODE\"='IH'" ) it = l.getFeatures( QgsFeatureRequest( expr ) ) Build a list of feature Ids from the result obtained in ...
As per @FelixIP's answer, use an IN operator in your where clause. The multivalue parameter is passed as a single semicolon delimted string, i.e. "value1;value2;value3". To convert this to the required format for the IN operator use python split/list comprehension/join or replacement. split/list comprehension/join: fields = arcpy.GetParameterAsText(0) ...
Use DPD IN ('Gas','Oil','') instead of multiple OR
If you are in ArcMap, you should just be able to run your SelectLayerByAttribute() by referencing the layer as it is in the TOC, and your selection should show up. See picture below My python window: >>> arcpy.SelectLayerByAttribute_management("Parcels", "NEW_SELECTION", """OWNER_NAME like '%SMITH%'""") <Result 'Parcels'> >>> ...
If the model is outside of ArcMap you will first have to use Make Feature Layer tool, then you may use Select Layer by Attribute tool followed by the Delete Features tool.
You can do this in a single step using the Select (Analysis) tool that works on a feature class. If you were planning to Select By Attribute where Field = 'X' and then delete the selected records simply use Select (Analysis) to select records where Field <> 'X' instead.
With booleans, you need to repeat the query with the name of the field : ("Pop_CL"=8) or ("Pop_CL"=9) or ("Pop_CL"=10) but in your case you could use "Pop_CL" in (8,9,10)
Here is a bare-bones example (borrowing from both Jim and Richard's answers): import arcpy fc = r'C:\junk\FILE_GDB.gdb\Export_output_gdb' # input feature class field1, field2 = 'Distance', 'Type' # fields to sort, and group fcOut = r'in_memory\blah' # output feature class # set up counters bankcount = 0 churchcount = 0 ...
modulo is quite convenient for this. you can go to the properties of your layer, definition queries, and set MOD("FID"+4,8)=0 if you want to create a subset, you can also use this to select by attribute and export the layer in a new layer, but it is not necessary. As a remark, your display should go faster with a file geodatabase. Also, shapefile ...
The SearchCursor syntax in the previous comments and posts is outdated and 10 times slower than a data access cursor if you have Desktop 10.1 or later. Only use DA cursors. Here is my script, assuming your categories of banks and churches are in the same field in the feature class, this script will get the top ten items for all categories or only specified ...
I think we can handle this using an arcpy.SearchCursor (I still use the Old School SearchCursor) and usage of the arcpy.Select_analysis() tool. The following is probably inefficient but I hope it helps. This assumes the Banks and Churches layer is held in a File Geodatbase (.gdb): import arcpy BanksAndChurches = r'Path\To\BanksAndChurches\FeatureClass' ...
The where clause is currently evaluating stepos literally as the value stepos, not the variable value 22. Move the stepos variable outside the where clause string, casting the numeric value to a string, like: arcpy.UpdateCursor(stefile, ' "POSITION" = ' + str(stepos))
Top 50 recent answers are included