Uploaded image for project: 'Spatial Information Systems'
  1. Spatial Information Systems
  2. SIS-49

ArrayIndexOutOfBoundsException caused by method getCircularRegionApproximation(int numberOfPoints) in LatLonPointRadius class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 0.3
    • Geometry

    Description

      The method public LatLon[] getCircularRegionApproximation(int numberOfPoints) throws an ArrayIndexOutOfBoundsException under certain conditions. This is because of an error in the following loop:

      LatLon[] points = new LatLon[numberOfPoints + 1];
      for (int i = 0; i < 360; i += (360 / numberOfPoints)) 
      {
        points[i] = DistanceUtils.getPointOnGreatCircle(this.center.getLat(),
            this.center.getLon(), radius, i);
      }
      

      The exception arises because integer i is used as the array index for the points array, but the value of i jumps up by (360/numberOfPoints) on every iteration of the loop. For example, if numberOfPoints is 10, then i will increase by 36 each time, resulting in the exception. The points array size is set before the loop to 'numberOfPoints + 1'.

      As an experiment, I changed the loop as shown below and this appeared to fix the problem. There may be a more elegant solution:

      LatLon[] points = new LatLon[numberOfPoints + 1];
      for (int i = 0, j = 0; i < 360; i += (360 / numberOfPoints), j++) 
      {
        points[j] = DistanceUtils.getPointOnGreatCircle(this.center.getLat(),
            this.center.getLon(), radius, i);
      }
      

      Attachments

        Activity

          People

            rlaidlaw Ross Laidlaw
            rlaidlaw Ross Laidlaw
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: