10-09-2020 08:41 AM
Hi all,
In GeoMedia how can I round to the nearest 0.5?
Example:
45,64 -> 45,5
45,91 -> 46,0
43,81 -> 44,0
57,01 -> 57,0
56,33 -> 56,5
51,26 -> 51,5
35,43 -> 35,5
45,64 -> 45,5
59,29 -> 59,5
Thank you
Solved! Go to Solution.
10-09-2020 08:52 AM
Does the ROUND operator help you, in Functional Attributes?
https://hexagongeospatial.fluidtopics.net/reader/rZHMZP5BYO6l8Rulw8Ns9g/CvvVo1TLMHBkR8qWB0FH6A
ROUND rounds a number to a specified number of digits.
Syntax
ROUND(number, num_digits)
Elements
number
I/O: Input R/O: Required DataType:I/O: Description: The number you want to round.
num_digits
I/O: Input R/O: Required DataType:I/O: Description: The number of digits to which you want to round number.
If num_digits is greater than 0 (zero), then number is rounded to the specified number of decimal places.
If num_digits is 0, then number is rounded to the nearest integer.
If num_digits is less than 0, then number is rounded to the left of the decimal point.
Return Type
gdbDouble
10-09-2020 09:50 AM
This is a bit tricky I would say. Using ROUND it might be something like ROUND(2.0*x, 0)/2.0, or perhaps clearer would be FLOOR(2.0*x + 1.0)/2.0.
10-09-2020 01:52 PM
Nice thing about the expression system is there's alternate ways of doing things... some methods better than others... I do NOT avocate this as being the most direct solution.
One way to think of the problem is that it's two conditional evalutions based on the value of the decimal portion of the value.
Condition 1: Decimal values >= 0.5, where the range is 0.5 to 1.0:
For these if the decimal value is closer to 0.5, then want the result to be Truc value + 0.5
if the decimal value is closer to 1.0, then want the result to be the Truc value + 1.0
Condition 2: Decimal values < 0.5, where the range is 0 to 0.5:
For these if the decimal value is closer to 0, then want the result to be Truc Value
if the decimal value is closer to 0.5, then want the result to be Truc value + 0.5
So with these conditions in mind in Functional Attributes you might try the following odd workflow..
In Functional Attributes build expressions:
FA_INT
TRUNC(Input.Source_Value)
FA_DEC
ROUND(Input.Source_Value - Output.FA_INT, 2)
The next part is bit messy so before building any further expression think out the logic from above to build two separate IF statements:
Syntax for IF:
IF ([Conditional test], [Value if True], [Vaue if False])
For Decimal values >= 0.5
IF(1.0-Output.FA_DEC >=0.25, Output.FA_INT+0.5, OUTPUT.FA_INT+1)
For Decimal values < 0.5
IF(0.5-Output.FA_DEC >=0.25, Output.FA_INT, Output.FA_INT+0.5)
You could do an attribute query divide and conquer in two different runs using the expressions above (which is probably what I would do to avoid wrapping my head around a nested IF statement) but.... if you want to put it altogether as a nested IF it might look like the following:
FA_Target_Values
IF(Output.FA_DEC >= 0.5, IF(1.0-Output.FA_DEC >=0.25, Output.FA_INT+0.5, Output.FA_INT+1), IF(0.5-Output.FA_DEC >=0.25, Output.FA_INT, Output.FA_INT+0.5))
Depth calculations for nautical charting?
10-13-2020 06:21 AM
Before seeing Pavel's answer I came to the same conclusion. It's quite simple/elegant:
ROUND((MyFieldName*2),0)/2
Hal
10-13-2020 10:37 AM
Arrggg.. sorry for the wind.. that's definitely a simple solution! I thought I had tested Pavel's suggestion and noted that it did not always work but apparently my test was wrong.. perhaps I tested using FLOOR.
10-16-2020 07:40 AM
Thank you all for your time and effort searching for an answer for my question.
Problem solved!
Regards.