uDIG

error in cursorPosition code

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: UDIG 1.1.0, UDIG 1.1.1, UDIG 1.2.M2, UDIG 1.2.M3
  • Fix Version/s: UDIG 1.2.M4
  • Component/s: application
  • Labels:
    None
  • Environment:
    XP, jre1.6.0_07_win32_gdal, Eclipse Ganymede.

Description

There is error in cursorPosition code. Whenever the world co-ordinate is in the exponential form (say 3.3100324202343583E7), the data displayed in the text field is not correct. It is because 3.3100324202343583E7 is being treated as 3.310032420234358 and not 33100324.20234358. My suggestion is that you just need to convert the double in exponential from to decimal form.

Problem is in function:

private String getString(double value) {
            if (Double.isNaN(value) ){
                return Messages.CursorPosition_not_a_number;
            }
            
            if( Double.isInfinite(value) ){
                return Messages.CursorPosition_infinity;
            }
            
			String string = String.valueOf(value);
			string+="00"; //$NON-NLS-1$
            
//          calculate number of digits to display based on zoom level
            Coordinate coordFactor = getContext().getPixelSize();
            double inverse = (double)1 / coordFactor.x;
            String strFactor = String.valueOf(inverse);
            int factor = strFactor.lastIndexOf('.');

      int end=Math.max(1, Math.min(string.lastIndexOf('.') + factor, string.length() - 1));  //// This line generates the wrong end.
            string = string.substring(0, end); 
            
            if( string.endsWith(".") ){ //$NON-NLS-1$
                string=string.substring(0,string.length()-1);
            }
            
			return string;
		}

Activity

Hide
Jody Garnett added a comment -
The class to be updated is CursorPosition in the net.refractions.udig.tool.default plugin. Would you like to submit a patch?
Show
Jody Garnett added a comment - The class to be updated is CursorPosition in the net.refractions.udig.tool.default plugin. Would you like to submit a patch?
Hide
Jody Garnett added a comment -
Issue is marked resolved .. used:
{code}
    static NumberFormat format = NumberFormat.getNumberInstance();
    static {
        format.setMaximumFractionDigits(64);
    }
....
String string = format.format(value);
{code}
Show
Jody Garnett added a comment - Issue is marked resolved .. used: {code}     static NumberFormat format = NumberFormat.getNumberInstance();     static {         format.setMaximumFractionDigits(64);     } .... String string = format.format(value); {code}
Hide
John Hudson added a comment -
verified in Revision 31311
Show
John Hudson added a comment - verified in Revision 31311

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: