6.6.4 MathOperations

MathOperations performs mathematical calculations based on a source location and a target location.

The following is an example for using MathOperations:

Distance_measured = location_handle.call('MathOperations', {'MathRequest': u'FindDistance', 'DistanceParamSource': {'Longitude': u'10', 'Latitude': u'15', 'Altitude': u'20'}, 'DistanceParamDestination': {'Longitude': u'40', 'Latitude': u'55', 'Altitude': u'20'}})

The following table summarizes the specification of MathOperations:

Interface ILocation
Description Performs mathematical calculations based on a source location and a target location.
Response Model Synchronous
Pre-condition Device must be Location aware (that is, it must have some location service provider in form of GPS, AGPS, or Bluetooth).

ILocation interface loaded.

Post-condition Nil

Input Parameters

Input parameter specifies the mathematical operation such as FindDistance, FindBearingTo and so on, and position co-ordinates for performing the mathematical operation.

Table 6.136: Input parameters for MathOperations
Name Type Range Description
MathRequest string FindDistance
FindBearingTo
MoveCoordinates
Specifies the mathematical operation.
DistanceParamSource map. For more information, refer table map- Distance Param Source 6.137 NA This specifies the position co-ordinates.
Note that expected datum here is WGS-84 with decimal degree representation.
Also note that altitude supplied does not effect the result of calculation. It is used to maintain a uniform input argument, which makes it easy to use.
DistanceParamDestination map. For more information, refer table map- Distance Param Destination 6.138 NA Specifies co-ordinates of another position. It is not required when value specified in the first parameter is MoveCoordinates.
Note that expected datum here is WGS-84 with decimal degree representation.
MoveByThisDistance
(only if MathRequestType is MoveCoordinates)
double NA Move source position by the specified the distance.
(Only if MathRequestType is MoveCoordinates) double NA Move the source position by the specified bearing.



Table 6.137: map- DistanceParamSource
Key Type Description
Longitude double Longitude data
Latitude double Latitude data
Altitude double Altitude data



Table 6.138: map- DistanceParamDestination
Key Type Description
Longitude double Longitude data
Latitude double Latitude data
Altitude double Altitude data


Output Parameters

Output parameter contains ReturnValue. It also contains ErrorCode, and ErrorMessage if the operation fails.

Table 6.139: Output parameters for MathOperations
Name Type Range (Type: string) Description
ReturnValue The table 6.140 describes output obtained for various input combination NA Resultant calculation.
In case you request to Move coordinates, map described in column 2 will be returned.
Note that if distance between two coordinate is requested, it is returned in meters while FindBearingTo returned is in degrees counting clockwise relative to true north.
ErrorCode int NA Service specific error code on failure of the operation.
ErrorMessage string NA Error description in Engineering English.



Table 6.140: map- Resultant output
MathRequest type in input Obtained output type Description
FindDistance double Contains the calculated distance in meters.
FindBearingTo double Bearing between two points.
MoveCoordinates map Map described in the table 6.141 is returned, which represents the translated coordinate.  



Table 6.141: map- MoveCoordinates
Key Type Description
Longitude double Longitude data
Latitude double Latitude data
Altitude double Altitude data


Errors

The following table lists the error codes and their values:

Table 6.142: Error codes
Error code value Description
1002 Bad argument type


Error Messages

The following table lists the error messages and their description:


Table 6.143: Error messages
Error messages Description
Location:MathOperations:Missing argument- MathRequest Indicates missing Mathrequest argument.
Location:MathOperations:Wrong argument- MathRequest Indicates supplied MathRequest argument is wrong.
Location:MathOperations:Missing argument- locationcoordinate Indicates missing locationCoordinate in input.
Location:MathOperations:Missing argument- MoveByThisDistance Indicates missing MoveByThisDistance in input.
Location:MathOperations:Missing argument- MoveByThisBearing Indicates missing MoveByThisBearing in input.
Location:MathOperations:TypeMismatch- MoveByThisDistance Indicates type for Movebydistance is wrong.
Location:MathOperations:TypeMismatch- MoveByThisBearing Indicates type for Movebythisbearing is wrong.


Example

The following sample code illustrates how to perform specific calculations on user provided data:

import scriptext
location_handle = scriptext.load('Service.location', 'ILocation')

try:
    Distance_measured = location_handle.call('MathOperations', {'MathRequest': u'FindDistance', 'DistanceParamSource': {'Longitude': u'10', 'Latitude': u'15', 'Altitude': u'20'}, 'DistanceParamDestination': {'Longitude': u'40', 'Latitude': u'55', 'Altitude': u'20'}})
    errorcode = Distance_measured["ErrorCode"]
    if errorcode != 0:
        print "Error in retrieving the Distance covered"
    else:
        ret_val = Distance_measured["ReturnValue"]
        if ret_val["distance covered"]["Value"] == '50':
            print "The distance covered is  retrieved"

except scriptext.ScriptextError, err:
    print "Error performing the operation : ", err

See About this document... for information on suggesting changes.