Hot answers tagged

24

Any time you have a selection on a layer a cursor object will only return the selected rows. for row in arcpy.SearchCursor("name_of_layer_with_selection"): print row.field1, row.field2


19

In the Table of Contents window, there is a button across top titled "List By Selection". Clicking this button toggles the Table of Contents into a mode that lets you change the selectablity of each layer in your dataframe.


15

One thing that makes writing WHERE clauses a lot easier is to use the AddFieldDelimiters function, which automatically adds the correct, DBMS-specific delimiters for field identifiers, such as double-quotes for FGDB and brackets for PGDB. The other thing you have to consider is whether the value is a number, string, or other data type. Specifically, strings ...


14

Or you can run the ArcToolBox tool Frequency (Analysis Tools>>Statistics>>Frequency) which will output a table with unique values and a count of how many time they appear. Or you could write python script that gets a SearchCursor on a field then build a list of all values of the form if value not in myList: myList.append(value)


12

You can use the Feature Class To Feature Class python snippet. Here is the general syntax. FeatureClassToFeatureClass_conversion (in_features, out_path, out_name, {where_clause}, {field_mapping}, {config_keyword}) To output to a shapefile, make sure that your out_path is a folder (and not pointing within a file geodatabase), and that out_name has a ...


11

Without knowing what your data looks like, the general syntax you need to insert into the select by attributes window is: [FIELD_1] IS NULL OR [FIELD_2] IS NULL OR [FIELD_3] IS NULL and so on for as many fields as you have to work with. For reference the full query would be: SELECT * FROM [TABLE_NAME] WHERE [FIELD_1] IS NULL OR [FIELD_2] IS NULL OR ...


10

Another, maybe simpler, way is: where = '"StudyID" = ' + "'%s'" %Name


10

Use a Python list comprehension. import arcpy fldName = 'val_fld' fcName = 'feature_class.shp' #set creates a unique value iterator from the value field myList = set([row.getValue(fldName) for row in arcpy.SearchCursor(fcName)]) For large datasets a memory efficient method would be to use a generator expression. myList = set((row.getValue(fldName) for ...


10

You can unselect features with unselect and unselectAll methods of SelectFeature control: selectControl = new OpenLayers.Control.SelectFeature(vectorLayer); ... map.addControls([selectControl]); selectControl.activate(); // unselect any specific feature... selectControl.unselect(vectorLayer.features[0]); // ...or all features selectControl.unselectAll(); ...


10

Kadeem's modified 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 ...


9

In arcpy, When you implement the Search Cursor or Update Cursor you have the option of using the where_clause parameter, which will allow you to select a specific row based on a field value (e.g. row ID). This help file will show you how to build an appropriate SQL query for selecting a specific row.


8

Another approach to this would be to use the Spatial Join tool. Use the point as your input feature layer as above and the polygon layer as your identity features.Unlike SelectLayerByLocation, SpatialJoin does honor the extent environment. targetlayer = layername joinlayer=arcpy.PointGeometry(arcpy.Point(x, y)) fieldmappings = arcpy.FieldMappings() ...


8

There doesn't seem to be a way to directly find a feature object's parent layer or whether it's selected from a method in the QgsFeature class. A similar approach to vlayer.selectedFeatures() is to test whether the feat.id() is in vlayer.selectedFeaturesIds(). QgsFeatureIds are not unique values compared with other vector layers, only within their own ...


7

the Describe function will also return a list. I am not sure if this is faster than the cursor method but I have fond this to be a useful tool. The resulting list is the object id's for the selection set. import arcpy aa = arcpy.Describe("someFC") ss = aa.FIDset tt = ss.split("; ") Print tt [u'1363', u'1364', u'1365', u'1367', u'1369', u'1370']


7

Instead of: "'ZIP' = '10004'" try this: '"ZIP" = ' + "'10004'" The reason that your original expression gives an empty output is because the string 'ZIP' is not the same as (equal to) the string '10004'.


7

create a new polygon layer, draw a single polygon that covers all your current polygons, then cut the newly drawn polygon based on all your existing polygons, then select all polygons from you current set that share a line segment with the newly drawn polygon using select by location and you're done ---Edited version much more efficient, based on ...


7

Edit: The first method I posted wouldn't work. This one should though. One straightforward way to do this would be to select everything you want to keep via Make Feature Layer with a where clause of X <> c. Then, use Copy Features to save the result.


7

You can use the floor function in your expression, like this: floor($id /24) IN (1,3,5,7,9,11,13,15,17,19,21) On a sample grid I've obtained this result with my own numbers (my grid has 13 columns per row): I've used: floor($id/13) IN (1,3,5,7,9) So, in general: floor($id / number_of_columns) IN (1, 3, 5, ..., 2*number_of_rows_to_be_selected - 1) ...


6

The select tool has a "Select by Rectangle" option. (There are also freehand/polygon options if that would be more appropriate.) The node tool is for digitizing. I don't think that's what you want to do here. Then, right-click on the layer in layer list and use "Save selection as ...". This will create a new file with the features you selected. (You can ...


6

Right click on layer name: Selection -> Make This The Only Selectable Layer Fine control of selectable layers: In table of Contents switch to List by Selection view and then choose which layer are selectable:


6

Use the looping and variable value as shown in Aragon's answer with the FID field (this is the zero-based object ID field for shapefiles) as the select field as shown in L_Holcombe's answer to generate the where clause, and all should be good. To program in the total number of features use the Get Count tool and divide by 10 assigned to the variable. Will ...


6

Some time ago I had a similar problem (How to change the symbology of selected features in QGIS). It seems that this features isn't available in QGIS 2.12 yet (https://hub.qgis.org/issues/12879), so you can achieve this effect using isselected function, available in Nathan's plugin qgsexpressionplus (https://github.com/NathanW2/qgsexpressionsplus). For ...


5

This example should show you exactly what you need. http://openlayers.org/dev/examples/select-feature-multilayer.html


5

Toolbars are located outside your screen area. You can use Python console to move them on screen. Here is example of moving Navigation Toolbar: qgis.utils.iface.mapNavToolToolBar().move(10,10) Names of other toolbars can be found by this link.


5

Sounds like you want to select features and not clear the selection graphics layer each time you click a feature. If you're using a FeatureLayer, you would use SELECTION_ADD instead of SELECTION_NEW to add the selected features as you click on them.


5

I ended up making the function suggested below. In part inspired by inputs from other contributors on this question. The object handling is coarse and it creates a lot of temporary files. I am sure this function could be made a lot better. If properly polished it could be a decent preliminary fix for the dissolve bug by ESRI. I am making it a community ...


5

You could try the Identity tool, using your line features as the input, and polygons as the identity features: "When the Input Features are lines and the Identity Features are polygons, and the Keep relationships parameter is checked (relationship set to KEEP_RELATIONSHIPS), the output line feature class will have two additional fields, LEFT_poly and ...


5

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 ...


5

Follow these steps: Get the layer reference: cLayer = iface.mapCanvas().currentLayer() Get a featureIterator from an expression: expr = QgsExpression( "\"ogc_fid\"=482" ) it = cLayer.getFeatures( QgsFeatureRequest( expr ) ) Build a list of feature Ids from the result obtained in 2.: ids = [i.id() for i in it] Select features with the ids obtained in ...


5

I don't think you can remove features from a selection layer once it's been created, but the workaround that I usually use is to create a new selection layer from your existing one: Select the features in your selection layer that you want to remove. Open the selection layer's attribute table and click Switch Selection, which will make all the features ...



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