Tag Info

Hot answers tagged

5

There are a few issues: one has been pointed by recurvata, but there is also an indentation problem (this could be due to formatting only, not to your code, but it needs to be checked) and your code does not return anything. The argument of your function ReClass() should be MIN_YEAR_B as this is what you use. def ReClass(MIN_YEAR_B): x = -1 if ...


4

Try using the word "Length" (i.e. length of polylines, perimeter of polygons) instead of "Perimeter": arcpy.CalculateField_management("Iceberg","Area","!shape.geodesicLength@KILOMETERS!","PYTHON_9.3","#") I found the geodesicLength property documented in the Calculate Fields examples page: Geodesic area and length can also be calculated using ...


4

Your syntax is correct. However, yes, your data type for the field you are calculating to is incorrect. The function returns a Boolean string, TRUE or FALSE. You need to have a text field you are calculating on/into. This is explained in the specific error message you are getting. View it by going to Geoprocessing > Results, and expanding Current Session, ...


4

def slope_correct(slope, avg): if avg > 25: return "holly crap" elif 0 < avg <= 25: return "easy peasy" else: return "unknown"


3

I assume that you are using ArcGIS field calculator def CalcD(level): if 1.5 <= level <= 4.5 : return level * 9 else: return level CalcD(!Level_water!)


3

there is no such thing as the "sum" operator for difference (which is not permutable), so you should test the validity of each item to decide how you run the substraction. def stack(item1,item2): if item1 != None and item2 != None: return item1-item2 elif item1 != None: return item1 elif item2 != None: return -item2 ...


3

I would not assume it is a date. I would make sure the date and time is captured as a string and create a python expression using the strptime function and use a PYTHON_9.3 calculation to have the entire date and time calculated. VB Date expressions should be in the format of #date#, but they are not reliable, since they only preserve the date, not the ...


3

You need to pass MIN_YEAR_B in the function as well. Date_Class=ReClass(!Date_Class!, !MIN_YEAR_B!)


2

Use the substr function under String list for example: substr( 'L3NAM1988K', 6, 4 )


2

perhaps something like dim x if InStr([ExternalRe],"ASP")>0 then x = 1 end if if InStr([ExternalRe],"Q")>0 then x = 1 else x = 0 end if Letting = x vbscript seems to be picky about quotes around strings too - single quotes can give an error. EDIT: depending on how you actually want to calculate the Letting field, you may want your ...


2

You cannot assign an output directly to a field in the calculation text, only by selecting the field as the output field of the calculation. [Intact] needs to be changed to Intact (a variable) and the output needs to be to Intact in the field output portion. Parser: VB Script Use Codeblock: Checked Pre-Logic Codeblock: If IsNull([Condition]) Then ...


2

You need to cast your denominator to a float (decimal) value. See this thread: Why is this field calculator expression evaluated incorrectly when using Python syntax? Your output field also must accept decimal values (i.e. cannot be an integer field).


2

If I'm reading your logic correctly, if either Test1 or Test2 = FAIL, you want to return 0, but if both = PASS you want to return 1. I'd do something like this: def Final(t1, t2): if t1 == 'FAIL' or t2 == 'FAIL': val = 0 elif t1 == 'PASS' and t2 == 'PASS': val = 1 else: val = 2 # this allows you to check if t1 or t2 had ...


2

In general your condition statement should go as: if TEST1 == 'FAIL': return 0 Single or double quotes for checking fields with string values, and when returning to a numeric field no quotes needed.


1

We can adjust the Field Calculator Code Block to achieve the effect you are looking for. The following assumes that your target field is a Text Field, and has enough length to hold the value produced by the Field Calculation. For example, if we want to prefix our incremental count with the word "Object": Expression: autoIncrement("Object") Expression Type: ...


1

I calced !Shape.isMultipart! to a Text field and it filled it with 'TRUE' and 'FALSE'. The output type is string, not numeric, so only a Text field will work.


1

By default QGIS expressions do int / int = int which is why you see the result you do. So you need to do float(ElectionYes) / ElectionTotal which will do float/int=float However in QGIS 2.8 this has now change to do int/int = float so it will do what you are expecting.


1

fYou do not have to resave the table with the Join in place if you used a standard join and have edit rights in the directory where the shapefile is stored. I assume you added a field to the shapefile and want to fill it in. Select the table field from the Field Calculator field list box to get the fully qualified name of the joined table field (i.e., ...


1

I am assuming you are running this as a field calculate from a table? You don't reference the field you want to change in the pre-logic script section, you apply a variable to it which you compute a value for (in your case a 1 or a 0). Add Dim x to the beginning of the code in the pre-logic script code box then replace all "[Intact] = " with "x = " As you ...


1

That's a two step process rasterize the building layer to create a raster with the building height information use field calculator to sum up the DEM and building height Note that the two rasters have to be in the same CRS before you can add them up in the field calculator.


1

According to this tutorial the map function returns a list: >>> items = [1, 2, 3, 4, 5] >>> >>> def sqr(x): return x ** 2 >>> list(map(sqr, items)) [1, 4, 9, 16, 25] >>> So your code should be something like this: def Distance(Latitude, Latitude2, Longitude, Longitude2) pList = map(math.radians, ...


1

If your new fields have a pattern in their naming (e.g., [table_name]_y as in your snapshots), you can use inline variable substitution. More specifically, if you change Field Name parameter to %Name%_y, this will transfer all GRID_CODE values to this field in your individual DBFs.


1

In QGIS, the function "format_number" under the string menu in field calculator reformats numbers to locale specific separators and decimal places.



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