Hot answers tagged

6

Just use the field calculator, goto attribute table and right click on the table header, and choose field calculator [ONEWAY] = "B" obviously our fields are a little different, just make sure you select the field you want to calcuate to


5

Here's a simple expression with no need to define a function in the codeblock: Headwater = 0 if !NextDown_Copy! else 1 This checks if each value of NextDown_Copy is truthy (i.e. not a null, 0, empty string), and returns a 0 if so, otherwise it returns a 1.


4

VBScript does not support syntax such as a=b=c to compare three values. Instead, you should write something like a=b AND a=c. The complete pre-logic block could be If [Grunntype] = [Grunntyp_1] And [Grunntype] = [Grunntyp_2] Then Lik_grtyp = 3 ElseIf [Grunntype] <> [Grunntyp_1] And [Grunntype] <> [Grunntyp_2] And [Grunntyp_1] <> ...


4

The function you are looking for is actually getFeature (at least in QGIS 2.8). It takes 3 arguments (hence your "Parsing Error") : the name of the layer, the name of the field, and the value of the field. So it would be something like getFeature( 'your_layer', 'id', 6679 ). Additionnal point : you actually have to use geometry(getFeature( ... )) in your ...


4

def des(num): aList=['Flat', 'N', 'NE', 'E','SE','S','SW','W','NW','N'] if num in range(1,11):return aList[num-1] return 'N/A' Alternatively select valid records and use: ['Flat', 'N', 'NE', 'E','SE','S','SW','W','NW','N'][ !MajAspNum! -1]


4

Try this out: def Get_Class(depth): breaks=[0.5,1,2,3,5,10,100000] n=len(breaks) for i in range(n): if breaks[i] >= depth: m=i+1; break return m '=============================================== Get_Class( !AREA_HA! ) It will look cooler with enumerate though


4

You can use the Python collections module and an Update Cursor to accomplish this. This method adds a new field and populates it with a 1 if there are any duplicates, otherwise a 0 if there are no duplicates. import arcpy, collections shp = r'C:\temp\names.shp' # Add a field called "check" to store binary data. arcpy.AddField_management(shp, field_name = ...


4

$area is the area of the current feature. It's a numeric variable. area is a function which takes a geometry, and returns its area. This geometry could be any geometry, not just the current feature. You could say that $area is the same thing as area($geometry) Some examples - you could use area (the function) to get the area of the bounding box of the ...


4

What about using re and set and setting a flag ( here 0 and 1) in python- re will extract all the names (last and first) from BENNETT MCCARL & ARNETTE BENNETT without &. For pattern matching re is of highest priority- you can use re how you want. import re def sorter(val): words = re.findall(r'\w+',val) uniques = set(words) if ...


4

With the next release QGIS 2.14 this will be fixed. If you have python knowledge, it should be straightforward to port the code linked to above to a small python snippet that copies joins and virtual fields from one layer to another. Please note that this is not a bug tracker and instead you should raise the awareness on the issue page you linked to, on ...


3

If you select your features before running the Field Calculator in the modeler, the output will contain only those selected features. A workaround would be to use a custom script in your model which allows you to update your selected features within the same layer. To do this, go to Processing Toolbox > Scripts > Tools > Create new script and copy the ...


3

!a! is not valid Python. Is this a typo? Calculate Field defaults to the VB parser, so you'll want to change that to Python. Something like the following should work: str.format() for reference. arcpy.CalculateField_management(fc, b, "!{}!".format(a), "PYTHON_9.3") To simplify things, you can combine all your for loops into one: for fc in ...


3

A switch statement is ideal for what you want to do. Since Python doesn't support switch statements, you can use dictionary mapping to accomplish the same thing. def des(num): the_dict = {1: 'Flat', 2: 'North', 3: 'Northeast', 4: 'East', 5: 'Southeast', 6: 'South', ...


2

Go to your layer properties by double-clicking the layer (or right-click > Properties) and go to the Fields tab. You will see the list of fields available including virtual fields. The expressions are stored in the Comment column as shown in the image (the red circle highlights the Expression Builder tool which you can click to edit your expression): ...


2

Try this if("laeskaerm"='1' OR "laeskaerm"='true','true','false') in 2.2 Case when "laeskaerm"='1' OR "laeskaerm"='true' then 'true' Else 'false' End


2

You could use the following expression to update your "laeskaerm" field: CASE WHEN "laeskaerm" = 1 THEN 'True' WHEN "laeskaerm" = 2 THEN 'False' ELSE "laeskaerm" END


2

As you have already noticed, if you use your same expression for a real field and increase the precision, you could see that each id value is incremented with an almost-constant number (in your case, 0.2) depending on the parameters you specified. These are then rounded to give a whole number which I assume is what your scaled_id field-type is: I did ...


2

If you switch the parser to Python, and desired Secondary values are always the same length and position (e.g., Secondary is always the last 4 characters), you could do this: def FindLabel([PRIMARY], [SECONDARY]): primType = [PRIMARY].upper() second = [SECONDARY].upper() if primType == 'PRIMARY': return second[-1] # last character of ...


2

If i follow you correctly, you can do this in vbs without using the left/right Dim Result if [TYPE] = "PRIMARY" then Result = "B" elseif [TYPE] = "SECONDARY" then Result = "D20" End If [LABEL] = Result * EDIT * with the new information (and how i understand your question) i think this will work (I am not at the office nor do I have Arc handy ...


2

Use Spatialite Database! It is a lightweight file based spatial DB supported out of the box by QGIS. First set-up a spatialite DB following theses instructions Push your two tables to this spatialite DB using QGIS DB manager Assuming that your tables are called "polygon" and "line" run the following SQL command in DB manager query interface. SELECT ...


2

So we have a definite answer to the question: The problem involves QGIS not liking the backslash try this replace ("Hotlink" , 'ABCD' , 'Maps\\ABCD\\ABCD') see esdm.co.uk/qgis-field-calculator-backslash-gotcha


2

Assuming your source data is a FeatureClass/Table in a File GeoDatabase then the following query will select the rows you require: SUBSTRING(name FROM 1 FOR 7) = 'BENNETT' AND SUBSTRING(name FROM (CHAR_LENGTH(name) - 6) FOR 7) = 'BENNETT name is the field, I just happened to call it name. The first part is testing the left hand side the second part is ...


2

Field calculator expression based on this answer def cw(sentence): words = sentence.split() counts = {} nMax=0 for word in words: if word not in counts:counts[word] = 0 counts[word] += 1 nMax=max(nMax, counts[word]) return nMax '================================================== cw( !MUID!) It will return maximum count of same words in ...


2

Python uses None to denote null values. I'd replace your Null with None (no quotes or brackets)and see what you get. Your script is essentially looking for a text string value of null. Furthermore, it's not contained in single quotes, so you're throwing a syntax error twice over.


1

Your indentation is off, you're missing an indent on the "Else" line: def reLabel(typeLabel): if typeLabel == 'BPS Easement': return 'BPS' else: return 'Other'


1

If you need MORE control over the class/label name and interval WISELY and want to use ANY type of equality check then a way is to use dictionary that keeps order (i.e. OrderedDict) and eval check as below where you have good command in interval for class and label for a class.To edit class (i.e. 1,2,3 etc.) and interval (i.e. ...


1

I found a solution Instead of editing the fields myself I found a plugin that coould do the job (quickmultiattributeedit) Thank you for your help and time


1

here it is in vbs, i can do it in python later when i have the time. dim result1 if [MajAspNum] = "1" then result1 = "flat" Elseif [MajAspNum] = "2" then result1 = "north" Elseif [MajAspNum] = "3" then result1 = "northeast" ... Else result1 = "N/A" end if ^^ codeblock Direction = result1 I found this searching the site, Writing ...


1

I was able to get this done by creating a model with many tedious steps but it worked. Basically, I selected any Feeders without a certain voltage then merged and summarized the table with the total lengths of each Feeder of that voltage. This gave me a length value for each Feeder.


1

As @PolyGeo comments you can do this with Summary Statistics with any license level. Use the Length field as statistics field with the 'SUM' statistic type the FeederId and OperatingVolt as case fields. You will get the total length of all combinations of FeederID and OperatingVolt values. This is a single step process so I don't see much added value ...



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