You can change the styles of the shape file in the layer properties. Double click the layer and select style.
Select Categorized style and choose a field you want to visualize. Remember to classify your values before leaving the dialog.
You miss a minus sign before where and the select is not necessary, so it should be:
ogr2ogr -where ID="1" outfile.shp infile.shp
or if you have to do more complex query on your input data:
ogr2ogr -sql "SELECT * FROM infile WHERE ID='1'" outfile.shp infile.shp
If ID is a field of Integer type, substitute ID='1' with ID=1.
-f "ESRI Shapefile" is ...
The simple trick to select only Integer values, is to use the following syntax:
Mod(Round("ELEVATION", 0)*10, 10)=0
This Multiplication by 10, makes all the values Integer, and then we select only those which are multiples of 10.
In case you wish to select Multiples of some other number, just multiply 10 by the interval.
To get contours at 5 m intervals, ...
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 3.:
You can achieve this with a very simple model if you have ArcGIS 10.0 or higher.
Create a model with Feature Iterator where the group by field is the attribute you wish to select by then send the output to the copy features tool using inline substitution to ensure a unique file name. The model is shown below:
This is a common error that I have run across, and I am pretty sure it is related to attempting to run the selection against a raw featureclass/shapefile output, as opposed to the "layer" representation of the featureclass/shapefile.
For example: You cannot select features from a shapefile without using ArcMap, but once you load the shapefile into ArcMap (...
You can loop over the iterator and get the .id() for every feature in it:
# build a request to filter the features based on an attribute
request = QgsFeatureRequest().setFilterExpression('"DN" != 3')
# we don't need attributes or geometry, skip them to minimize overhead.
# these lines are not strictly required but improve ...
To calculate the length in characters of a string expression use CHAR_LENGTH(string_exp)
Field name delimiters for file geodatabase is double quotes (not square brackets).
So this should work:
CHAR_LENGTH(“ColumnName“) > 5
Here is a SQL reference for query expressions used in ArcGIS.
I do not have access to ArcMap 10, only 9.3, but I expect that it won't be very different from this.
You can create a simple script in Python, that checks your attribute field for different values, and then, for each of them runs a SELECT operation to your original Shapefile.
If you are not familiar with python scripting, all you need to do is open you ...
Your original query could have been modified for a list of integers:
'"OBJECTID_1" IN ' + str(tuple(oid_list))
so if oid_list = [7, 9, 4, 8], then the result is:
"OBJECTID_1" IN (7, 9, 4, 8)
Be aware that this "trick" works if oid_list always has two or more items, since other valid tuples, such as () or (7,), will result with a SQL syntax error.
A more ...
This type of operation almost always involves writing a WHERE Clause so I think using at least a little bit of Python is in order.
Also while this is possible to do with ModelBuilder, IMO, creating a Python script tool with custom validation and more control over parameter settings could provide a better user experience -- for example, by making the Field ...
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 [...
You would select the rows which are NULL (sounds like you have done that) then simply run the calculate field tool.
Right Click the field you want to modify (while objects are selected)
Then input your value "newvalue"
NOTE: 1. if you don't have a selection this will work on "ALL" rows in your table!
2. Double quotes in this area on your text/date ...
You would need to break up your selection statement into two separate parts:
"Classes" = '14' OR "Classes" = '07'
Edit: Changed from AND to OR, since as noted in the comments, AND cannot work in this situation.
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-clicking the field heading and clicking Properties.
If the type is String, you'll need to create a new House Number field of the Integer type. Use the Field ...
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 "Parametro" = 'delta-Hexaclorociclohexano' OR "Parametro" = 'gamma-Hexaclorociclohexano'
You need to repeat the field name each time (this also work if you want ...
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 to add an action.
Fill the dialog inputs as indicated in the following picture.
You can Copy & Paste this couple of lines of code into the 'Action Text' ...
Your queries should follow the SQL format discussed here. For what you're looking for, you can use something like this:
"Some_Field" LIKE 'A%'
The % is a wild card, so this would return records that have values in "Some_Field" that start with 'A'.
Use a Feature Selection iterator in ModelBuilder. You can specify the field you want the selection to be grouped by (your field containing the unique values). It will iterate over your entire feature class, creating a selection layer from each unique value. You can then add more tools for the rest of your workflow.
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 one specific
# Example for a Inputfile called "my_shapefile" and a field called "my_attribute"
#Set Input Output variables
Here is a slightly modified version of the function in this answer, to accept a Python list instead of a semicolon-delimited string:
def buildWhereClauseFromList(table, field, valueList):
"""Takes a list of values and constructs a SQL WHERE
clause to select those values within a given field and table."""
# Add DBMS-specific field delimiters
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 10
To display any contour divisible by 50
To display half metre contours
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 2....
You can use Substring("fieldname", start, length) to mimick, left(), right() and mid() functions when querying a fgdb.
Left and Mid are obvious.
To extract the right 2 characters would be Substring("fieldname", char_length("fieldname") - 1), 2).
Column numbers are 1-based.