Transcription of Function Calculations Simple Calculations - …
1 2012 TeachMeGIS All rights reserved. Revised 05/12 1 1 Editing Tables with theField 2 Presentation OverviewGetting to Know the Field CalculatorSimple CalculationsFunction CalculationsAdvanced Calculations 2012 TeachMeGIS All rights reserved. Revised 05/12 2 3 What is it and why do we love it?Getting to Know the Field Calculator 4 Field CalculatorUse the Field Calculator to modify records in a table 2012 TeachMeGIS All rights reserved. Revised 05/12 3 5 Field Calculator ExpressionCalculate values for a columnBuild an expression to calculate the value Same value Combination of valuesChoose parser (language) VB Script Python!RoyaltyRate! * !GasProduct! 6 Some Things to KnowModifying Data Need write access to data Existing field In or out of edit session Undo-able insideSelection Only modifies selected records Modifies all records if none selected No checkbox option in Geoprocessing Results Error messages Re-run 2012 TeachMeGIS All rights reserved.
2 Revised 05/12 4 7 Field order Layer Properties order by default Or sort from within Field CalculatorFields 8 Simple Calculations 2012 TeachMeGIS All rights reserved. Revised 05/12 5 9 Static ValuesValue type must match destination column type String Quotes Follow parser rules Number No quotes Inner Corridor Technologies 10 Copy ValuesSource type must match destination column typeFields !<fieldname>! in Python [<fieldname>] in VB Script!field_code! 2012 TeachMeGIS All rights reserved. Revised 05/12 6 11 Combine ValuesMerge multiple columnsCombine attribute values and static valuesData types matterSyntax depends on parser + for Python & for VB Script!Township! + "N-" + !Range! + "W" 12 Combination TricksE X P R E S S I O NR E S U LT!
3 PointX!+ , + !PointY! , !County_Name!+ County, + !State!Harris County,TX!Company! + \n + !Address! TeachMeGIS3000 W ilcrest[Company]& vbNewLine& ![Address] TeachMeGIS3000 W ilcrest 2012 TeachMeGIS All rights reserved. Revised 05/12 7 13 Number & StringFunction Calculations 14 Number FunctionsBasic math + -/ *Built-in functions round() abs() max() min()round( !PROD!, 1 ) 2012 TeachMeGIS All rights reserved. Revised 05/12 8 15 Math FunctionsMath module () () () () () ( !PROD!, 2 ) 16 Number TricksE X P R E S S I O NR E S U LT!Elevation_ft! * Meters!Elevation_m! * Feet!Area_km2! * Acres!Area_acres! * km2round(!PROD!* !Royalty!, 2)$!Part1! / !Total!% 2012 TeachMeGIS All rights reserved.
4 Revised 05/12 9 17 String FunctionsBuilt-in functions .upper() .lower() .title()The field name goes beforethe . Function ()!Company!.upper() 18 String SlicingSlice returns a substring: 2 inputs (start, end)All inputs are 0-basedNegative inputs count backwards from endNon-inclusive!API![0:7] 2012 TeachMeGIS All rights reserved. Revised 05/12 10 19 Find and ReplaceReplaces the first string with the second stringREMEMBER: The field name goes beforethe . Function ()!CO_NAME!.replace("Inter", "Inner") 20 Type ConversionConvert values to correct data type str() int() float()float( !GasSales! ) 2012 TeachMeGIS All rights reserved. Revised 05/12 11 21 Now Put it All TogetherFunctionsField ValuesStatic Values 22 SCENARIO: Have a string formatted like: nnnn ssss ttt vvvv xxx yyyyTASK: Format in new field as: ttt vvvv xxx yyyyExample: String FunctionsWELL_NAME: 1200 RAAA SUA HOLY BEA CALI NEW WELL_NAME FIELD: SUA HOLY BEA CALI 2012 TeachMeGIS All rights reserved.
5 Revised 05/12 12 23 Example: String FunctionsSOLUTION: " ".join(!WELL_NAME!.split()[2:])WELL_NAME C olumn with original data 1200 RAAA SUA HOLY BEA CALI !WELL_NAME!.split() Splits the string at the spaces and puts thepiecesin a list 1200 , RAAA , SUA , HOLY , BEA , CALI !WELL_NAME!.split()[2:] Removes the first 2 values from the list SUA , HOLY , BEA , CALI .join(<list>)Creates a string fromthe values in <list> separated by a space SUA HOLY BEA CALI 24 Show CodeblockAdvanced Calculations 2012 TeachMeGIS All rights reserved. Revised 05/12 13 25 Show Codeblock CalculationsWrite Function in Pre-Logic Script Code sectionCall Function (with inputs) in Expression sectionReturned value is written to the tableExpressionFunction 26 Sequential NumbersTASK: Populate a column with sequential numbersSequentialNums(1000)numVal= 0defSequentialNums(numStart):global numValif (numVal< numStart): numVal= numStartelse: numVal= numVal+ 1 return numVal 2012 TeachMeGIS All rights reserved.
6 Revised 05/12 14 27 Pick Non-Null ValueTASK: Populate a column with either API or UWI (whichever exists)PickNonNullString(str(!API!), str(!UWI!))def PickNonNullString(val1, val2):valOut = val2if val1:valOut = val1return valOut 28 Any questions?Thanks for