- * Scale the given latitude value
- * @param inLatitude latitude in degrees
- * @return scaled latitude
- */
- private double getScaledLatitude(double inLatitude)
- {
- return inLatitude - _latMedian;
- }
- /**
- * Scale the given longitude value
- * @param inLongitude longitude in degrees
- * @return scaled longitude
- */
- private double getScaledLongitude(double inLongitude)
- {
- return (inLongitude - _lonMedian) * _longFactor;
- }
- /**
- * Scale the given altitude value
- * @param inAltitude Altitude object
- * @return scaled altitude
- */
- private double getScaledAltitude(Altitude inAltitude)
- {
- if (inAltitude == null) return -1;
- return (inAltitude.getValue(Altitude.Format.METRES) - _minAltitude) * _altFactor;
- }
-
- /**
- * Unscale the given latitude value
- * @param inScaledLatitude scaled latitude
- * @return latitude in degrees
- */
- private double getUnscaledLatitude(double inScaledLatitude)
- {
- return inScaledLatitude + _latMedian;
- }
- /**
- * Unscale the given longitude value
- * @param inScaledLongitude scaled longitude
- * @return longitude in degrees
- */
- private double getUnscaledLongitude(double inScaledLongitude)
- {
- return inScaledLongitude / _longFactor + _lonMedian;
- }
-
- /**
- * Calculate the latitude and longitude lines
- */
- public void calculateLatLongLines()
- {
- double maxValue = getMaximumHoriz() > getMaximumVert() ?
- getMaximumHoriz():getMaximumVert();
- // calculate boundaries in degrees
- double minLong = getUnscaledLongitude(-maxValue);
- double maxLong = getUnscaledLongitude(maxValue);
- double minLat = getUnscaledLatitude(-maxValue);
- double maxLat = getUnscaledLatitude(maxValue);
- // work out what line separation to use to give at least two lines
- int sepIndex = -1;
- double separation;
- int numLatLines = 0, numLonLines = 0;
- do
- {
- sepIndex++;
- separation = COORD_SEPARATIONS[sepIndex];
- numLatLines = getNumLinesBetween(minLat, maxLat, separation);
- numLonLines = getNumLinesBetween(minLong, maxLong, separation);
- }
- while ((numLonLines <= 1 || numLatLines <= 1) && sepIndex < MAX_COORD_SEPARATION_INDEX);
- // create lines based on this separation
- _latLinesDegs = getLines(minLat, maxLat, separation, numLatLines);
- _lonLinesDegs = getLines(minLong, maxLong, separation, numLonLines);
- // scale lines also
- _latLinesScaled = new double[numLatLines];
- for (int i=0; i<numLatLines; i++) _latLinesScaled[i] = getScaledLatitude(_latLinesDegs[i]);
- _lonLinesScaled = new double[numLonLines];
- for (int i=0; i<numLonLines; i++) _lonLinesScaled[i] = getScaledLongitude(_lonLinesDegs[i]);
- }
-
-
- /**
- * Calculate the number of lines in the given range using the specified separation
- * @param inMin minimum value
- * @param inMax maximum value
- * @param inSeparation line separation
- * @return number of lines
- */
- private static int getNumLinesBetween(double inMin, double inMax, double inSeparation)
- {
- // Start looking from round number of degrees below minimum
- double value = (int) inMin;
- if (inMin < 0.0) value = value - 1.0;
- // Loop until bigger than maximum
- int numLines = 0;
- while (value < inMax)
- {
- if (value >= inMin) numLines++;
- value += inSeparation;
- }
- return numLines;
- }
-
-
- /**
- * Get the line values in the given range using the specified separation
- * @param inMin minimum value
- * @param inMax maximum value
- * @param inSeparation line separation
- * @param inCount number of lines already counted
- * @return array of line values
- */
- private static double[] getLines(double inMin, double inMax, double inSeparation, int inCount)
- {
- double[] values = new double[inCount];
- // Start looking from round number of degrees below minimum
- double value = (int) inMin;
- if (inMin < 0.0) value = value - 1.0;
- // Loop until bigger than maximum
- int numLines = 0;
- while (value < inMax)
- {
- if (value >= inMin)
- {
- values[numLines] = value;
- numLines++;
- }
- value += inSeparation;
- }
- return values;
- }
-
- /**
- * @return array of latitude lines in degrees
- */
- public double[] getLatitudeLines()
- {
- return _latLinesDegs;
- }
- /**
- * @return array of longitude lines in degrees
- */
- public double[] getLongitudeLines()
- {
- return _lonLinesDegs;
- }
- /**
- * @return array of latitude lines in scaled units
- */
- public double[] getScaledLatitudeLines()
- {
- return _latLinesScaled;
- }
- /**
- * @return array of longitude lines in scaled units