Field calculation

Instructions for Use

Field calculation calculates the value of a new field through an expression composed of fields, operators, or functions. The result returns the feature dataset (FeatureRDD). Application scenarios such as when a certain business needs to comprehensively price the housing price, and the distance between the community and the subway station has a certain functional relationship with the housing price, defined by calculating the distance field. The V1 version of field calculation expressions currently supports mathematical operators, mathematical functions, conditional operators, logical operators, and mixed operations between them; The V2 version has more flexible field calculation expression function and supports more complex operations.

Change Statement

Add the 'Field Calculation Version' parameter to control the field calculation version. This article mainly introduces the V1 version of field calculation expressions. For a detailed introduction to V2, please refer to<a=“ https://blog.csdn.net/supermapsupport/article/details/123902526?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164888089116782092976100%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=164888089116782092976100&biz_id=0&utm_medium=distribute.pc_search_result.none -task-blog-2blogfirst_ rank_ ecpm_ v1~rank_ v31_ ecpm-1-123902526.nonecase&utm_ term=v2&spm=1018.2226.3001.4450" target="_ Blank ">Calculation of Fields in the SuperMap GPA Toolbox for V2 Upgraded Version.

Expression method:

  1. Mathematical operators
    Operator Description v1 Example and Result
    A+B A+B, A and B can be numerical values, functions, field names, or expressions "fieldname1+5"=15.0
    A – B A minus B, A and B can be numerical values, functions, field names, or expressions "fieldname1 fieldname2"=5.0
    A * B A multiplied by B, where A and B can be numerical values, functions, field names, or expressions "(filedname1-5) * (filedname2+5)=50.0
    A/B A divided by B, A and B can be numerical values, functions, field names, or expressions "abs (- filedname1)/filedname2=2.0
    Note: In the example, it is assumed that the value of fieldname1 is 10.0 and the value of filedname2 is 5.0    
  2. Mathematical function
    Operator Description v1 Example and Result
    Abs (a) The absolute value of a, which can be a numerical value, function, field name, or expression "abs (fieldname1) * 2"=20.0
    The trigonometric sine function of sin (a) a, which can be a numerical value, function, field name, or expression "sin (abs (fieldname1)+20)"=0.5
    Cos (a) The trigonometric cosine function of a, which can be a numerical value, function, field name, or expression "cos (filedname2 * 4+40)"=0.5
    Tan (a) The tangent value of a, which can be a numerical value, function, field name, or expression "tan (filedname2 * 9)"=1.0
    Log (a) The natural logarithm of a (based on e). A can be a value, function, field name or expression "log (1)"=0
    Sqrt (a) The square root of a, which can be a numerical value, function, field name, or expression 'sqrt (filedname1 * (filedname2+5)'=10
    Min (a, b) The minimum values of a and b, which can be numerical values, functions, field names, or expressions "min (10, filedname2)"=5.0
    Max (a, b) The maximum values of a and b, which can be numerical values, functions, field names, or expressions max (abs (filedname1), 8) "=10.0
    Note: In the example, it is assumed that the value of fieldname1 is -10.0, and the value of filedname2 is 5.0    
  3. Conditional Operators
    Operator Description v1 Example and Result
    A>B Is A greater than B? A and B can be numerical values, functions, field names, or expressions "abs (fieldname1)>filedname2"=1
    A<B Is A less than B? A and B can be numerical values, functions, field names, or expressions "fieldname1<fieldname2"=0
    A> =B Is A greater than or equal to B? A and B can be numerical values, functions, field names, or expressions "- fieldname1>=filedname2 * 2"=1
    A<=B Is A less than or equal to B? A and B can be numerical values, functions, field names, or expressions "(fieldname2+5) * 2<=10"=0
    A != Is B A not equal to B? A and B can be numerical values, functions, field names, or expressions '5!=10'=1
    A==B Is A equal to B? A and B can be numerical values, functions, field names, or expressions "fieldname2+5==max (10,5)"=1
    Note: In the example, it is assumed that the value of fieldname1 is -10.0, and the value of filedname2 is 5.0    
  4. Logical operator
    Operator Description v1 Example and Result
    A or B, where A and B are conditional operation expressions fieldname1>0 "=1  
    A&&B A and B, where A and B are conditional operation expressions "fieldname1>0&&filedname2>0"=0
    Note: In the example, it is assumed that the value of fieldname1 is -10.0, and the value of filedname2 is 5.0. The result 0 represents false, and 1 represents true    
  5. Priority Parenthesis "()", minus sign ("-"), and functions>Mathematical operators multiply ("*") divide ("/")>Mathematical operators add ("+") subtract ("-")>Conditional operators>Logical operators
  6. Precautions

*The negative sign in the field expression is only valid before the field name. *The priority of conditional and logical operators is relatively low, so expressions before and after conditional and logical operators do not need to be enclosed in parentheses. (fieldname1>0) | | (filedname2>0): Error, fieldname1>0 | | filedname2>0: Correct *You can add spaces before and after numerical values, field names, operators, or expressions in field expressions, and the calculation results are not affected. *Expressions support nesting of multiple functions and mixed operations after nesting. *A valid field name can only consist of letters, numbers, and underscores, and cannot start with a number.

Application Scenario

The V2 version of the field calculation expression function is more flexible and supports more complex operations. For example, it is necessary to rasterize vector data by analyzing the slope within the grid, whether it contains large vegetation, water systems, and residential areas, in order to create a thematic map for aircraft landing area analysis. The requirements for rasterization function are: Special map of aircraft landing area analysis: (2 modes) A. Aircraft landing: slope<10 °, no large vegetation, no water system, no residential area; B. Non aircraft landing: slope>10 °, or with vegetation, water systems, or residential areas. Using the V1 version of the field calculation cannot obtain such complex operational requirements. Using the V2 version of the field calculation, enter the expression: If (@ ["HYDA"]==null/ anhydrous system line/ &&@ ["HYDL"]==null/ anhydrous plane/ &&@ ["RESA"]==null/ No residential area/ &&@ ["VEGA"]==null/ No vegetation/ &&@ ["slope"]<10/ The slope is less than 10/ ) {return "A";}
Else if (@ ["HYDA"]!=null | | @ ["HYDL"]!=null)/
with a water system line or surface/ &&@ ["RESA"]==null/ Residential area/ &&@ ["VEGA"]==null/ No vegetation/ &&@ ["slope"]>10/ The slope is less than 10*/ ){return "B";} else{return null;} You can obtain the results of two landing area modes A and B in the new field, which can then be used to draw thematic maps.

Parameter Description

Parameter Name Default Value Parameter Definition Parameter Type
Dataset used for field calculation   Dataset used for field calculation, supporting point, line, surface, or table datasets FeatureRDD
Field name used to save calculation results   Field name used to save calculation results String
Field type used to save calculation results   Field type used to save calculation results String
Expressions used for calculations   Expressions used for calculations, supporting mathematical operations, comparison operations, mathematical functions, etc. String
Field Calculation Version v1 To ensure compatibility issues with field calculation, provide setting version parameters. V1 represents the field calculation of the old version, and v2 represents the field calculation of the new version, which is more flexible compared to the v1 version JavaFieldCalculatorVersion