New answers tagged

1

As mentioned in the comment, you could create a model from the Processing Toolbox but if you want to create a script, you could use the following which creates the start_lat field and updates it for each layer (comments are included which hopefully will help): # Import required module to create field from PyQt4.QtCore import QVariant # For each layer in ...


3

It looks like you're mixing up data access update cursors and calculate field. Use the data access update cursor (it's faster): with arcpy.da.UpdateCursor (StreetCenterlines, ["Latitude", "Longitude", "SHAPE@X", "SHAPE@Y"]) as cursor: for lat, long, x, y in cursor: row = (x, y, x, y) cursor.updateRow (row)


3

Your if statements are wrong for this case. You can visualize how VB is evaluating your statement like this: if [LWS50yrp] >= (136.5 < 154) so that line will catch all values over 136.5 because 136.5 is less than 154 make your statements read this way: ElseIf ([LWS50yrp] >= 136.5) And ([LWS50yrp] < 154) Then parenthesis were added for ...


1

I had a similar problem but this seems to be a usable workaround: Instead of using the table calculator, use "Vector -> Geometry Tools -> Export/Add Geometry Columns...". In this dialog box, use the option to Calculate using "Layer CRS" or "Project CRS", and you will get the correct area. If you use "Ellipsoid" you will get errors similar to the column ...


2

I believe the issue is that you are giving two integers in the CalculateField expression, so an integer is returned. You need to force one to a float or decimal to get a proportional value back. Try: exp = str(float(count)) + "/!Total_Properties!"


3

You could create a Custom function in the Function Editor to use the python ORD() function to get the ASCII value of a character (A being 65): http://www.qgistutorials.com/en/docs/custom_python_functions.html The function might look like this: from qgis.core import * from qgis.gui import * @qgsfunction(args=0, group='Custom') def ord_place(value1, ...


1

In your Field Calculator interface, go to the Function Editor tab, create a new file and input the following code: from qgis.utils import qgsfunction from qgis.core import QgsExpression, QgsMapLayerRegistry @qgsfunction(args="auto", group='Custom') def stringtoNum(field, feature, parent): val = dict(zip(string.letters,[ord(c)%32 for c in string.letters]...


3

Right-click on your layer in the Layers Panel and then click on Open the Attribute table. Click on Open field calculator (CTRL+I). There, create a new (virtual) field with the following expression: CASE WHEN col1 = 'A' THEN 1 WHEN col1 = 'B' THEN 2 WHEN col1 = 'C' THEN 3 ELSE 0 END Edit: you can also use strpos to return the position of ...


0

you are right that you can use the field calculator, but you could also do this with a cursor. With the field calculator, you can define a function that take all your fields as input and gives the position of the field as an output. argmax(!field1!,!field2!,!field3!,...,!field15!) def argmax(a,b,c,...o): mylist = [a,b,c,...o] return mylist.index(...


0

Use the "not equal" operator for the field calculator. def getClass(Text1,Text2,Text3): if Text1 != None: return Text1 elif Text2 != None: return Text2 elif Text3 != None: return Text3 else: return None; You may also want to account for the possibility that none of the input fields have a value, as seen in the code snippet ...


0

You need to make sure you're passing the other fields in the function call at the bottom. getClass(!Field1!, !Field2, !Field3!)


2

Hmm not sure how to do it all at once but you can do it in a couple of steps. I made an example using the values you specified: First we need to replace all forward slashes with an underscore _, the reason for this will be explained in the next step. You can use the expression: replace( "name", '/', '_') Now we can extract the strings after ...


6

This will need you to modify values based on your GRIDCODE as I can only see 4 and 16 in your table, but to do this in the Field Calculator is fairly straightforward. In the Field Calculator window, select Python parser, and select Show Codeblock. Enter the following into the Pre-Logic Script Code textbox: def updateName(gCode): if gCode == 4: ...


6

ArcGIS Method In field calculator switch the parser to Python and check the "Show Codeblock" box. In the Pre-Logic Script Code box enter import re def splitField(inField): return re.split('[-|#|~|\*]', inField)[1] In the TEXT box enter splitField(!nameofField!) QGIS Method Open Field Calculator and go to the Function Editor tab. In the code ...


6

In your table, right-click on the column name StreetNames and select Field Calculator... In the Field Calculator window, double-click on the field you want to copy (in your case TEMP, in my example I've used Sub_Unit_Type) and click OK Your StreeNames will now be overwritten by the values in your other field.


2

With VB script you just make the expression [temp] and in Python the expression is !temp! The Field Calculator has a field list to pick from on the left, so you can just double click the field name and it will add the delimiters around the field name.


0

You are currently using the python math.acos external to the field calculator to calculate the acos. So Python sees this as a string rather than a float (hence the error). Try instead to place the full expression in quotation marks. arcpy.CalculateField_management(fc_Arcs, "Angle", "math.acos(!X!/!Radius!)", "PYTHON_9.3"


2

The field calculator works always for the selection of rows, or if there are none selected for all rows. Just select the rows you want to be calculated by clicking the grey squares left of the first column (use shift or strg for multiple selection) or with "select by attributes".


1

I would somehow get a list of all the unique values. There are a few ways to do this. You can do it with Excel or Access or in ArcGis you can use the Find Identical tool to isolate the duplicates. arcpy.FindIdentical_management('your_layer', r"C:\OUTPUT.gdb\dupe_table", "FLDWITHDUPES", output_record_option="ONLY_DUPLICATES") You don't need to use the ...


1

In the code block window of the field calculator, try using: def new(DB_Low): if DB_Low == 0: return 0 else: return DB_Low + 2.25 And then in the expression window: new(!DB_Low!)


1

You defined your variables as POINT_X and POINT_Y, but you use in the function X and Y. Then i also would go for an easier approach and not the old string formatting method, that is harder to read. In the code block you can put the following that is more logical (in my opinion): def Output(POINT_X,POINT_Y): return '{'+str(round(float(POINT_X),4))+'}'+'{'+...


1

Depending on if you have a reasonably small amount of communities, you could use something like the following by going to the Field Calculator and selecting to either create a new field or update "Flurstueck": CASE WHEN "Gemarkung" = '[08, 8030]' THEN "Flurstueck" + '_1' WHEN "Gemarkung" = '[08, 8015]' THEN "Flurstueck" + '_2' ELSE "Flurstueck" END If you ...


15

Yes, this functionality is called virtual fields. Open the field calculator and check the "virtual field" checkbox. The value will then be updated (or rather it is recalculated every time it is requested) based on changing attribute values or geometry.


2

I'm guessing you mean the CalculateField tool when you refer to 'field editor with Python,' and you are in a locale that uses comas as a decimal mark (ie 0,1*dB1 = 0.1*dB1). You can do this with a single expression: !dB1! + !dB2! if 0 in (!dB1!,!dB2!) else 10*math.log(10**(0.1*!dB1!)+10*(0.1*!dB2!)) This uses a shorthand form of if/else: <condition ...


5

You can also use coalesce to replace NULL values from column_1 by column_5. coalesce("column_1", "column_5")


2

Open the attribute table and make it editable. Select by expression "column_1" isnull Along the top of the attribute table you an select in a drop down a column of your choice. Select "column_1" In the text box available write "column_5" Click "Update Selected"


11

The field calculator always calculates on a row-by-row basis. So you can use: CASE WHEN "column_1" IS NULL THEN "column_5" ELSE "column_1" END


0

I might expect the results for area calculated in the projected space to be different from those using geographic coordinates. It just depends what areas the tool claim to compute. Consider the "square" whose corners are at the UTM coordinates 18n 528007 4467447 18n 528008 4467447 18n 528008 4467448 18n 528007 4467448 It might be plausible to ...



Top 50 recent answers are included