/*
VisAD system for interactive analysis and visualization of numerical
data.  Copyright (C) 1996 - 2017 Bill Hibbard, Curtis Rueden, Tom
Rink, Dave Glowacki, Steve Emmerson, Tom Whittaker, Don Murray, and
Tommy Jasmin.
 
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/

package visad.georef;

import visad.CoordinateSystem;
import visad.GridCoordinateSystem;
import visad.VisADException;
import visad.SetType;
import visad.RealTupleType;
import visad.Linear2DSet;
import visad.Gridded2DSet;
import visad.Linear1DSet;
import visad.Unit;
import visad.Set;
import visad.georef.MapProjection;
import java.awt.geom.Rectangle2D;

/**
 * For 2D arrays of earth observations when the navigation is not provided analytically,
 * but a set of navigated points is given to interpolate.  Particularly useful for
 * polar swath observations with point-by-point navigation. 
 */
public class LongitudeLatitudeInterpCS extends MapProjection {

   Linear2DSet domainSet;   // The CoordinateSystem
   Linear2DSet transSet;    // Set to transform between domainSet and lonlatSet
   Gridded2DSet lonlatSet;  // Set of earth locations (the Reference, to be interpolated)

   //- assumes incoming GriddedSet is (longitude,latitude) with range (-180,+180)
   boolean neg180pos180 = true;  //false: longitude range (0,+360)
   
   boolean extNeg180pos180 = false; 

   int lonIdx = 0;

   /**
    *
    * @param domainSet  The CoordinateSystem, eg. (line, element), (Track, XTrack) 
    *
    * @param lonlatSet  The set of earth locations to interpolate for (x,y) to/from (lon,lat).
    *                   May be sampled w/respect to domainSet, eg. every fifth point. 
    *                   SetType must be SpatialEarth2DTuple or LatitudeLongitudeTuple.
    *
    * @param neg180pos180  The range of longitude values in the lonlatSet. Default is true,
    *                      false is (0,+360).
    *                   
    * @exception VisADException  Couldn't create necessary VisAD object or reference type
    *                            (the lonlatSet type) is not SpatialEarth2DTuple or LatitudeLongitudeTuple
    *
    */
   public LongitudeLatitudeInterpCS(Linear2DSet domainSet, Gridded2DSet lonlatSet, boolean neg180pos180) throws VisADException {
     super(((SetType)domainSet.getType()).getDomain(), null);
     this.lonlatSet = lonlatSet;
     this.domainSet = domainSet;
     this.neg180pos180 = neg180pos180;
     int[] lengths = domainSet.getLengths();
     int[] gsetLens = lonlatSet.getLengths();
     transSet = new Linear2DSet(0.0, gsetLens[0]-1, lengths[0],
                                0.0, gsetLens[1]-1, lengths[1]);
     lonIdx = getLongitudeIndex();
   }

   public LongitudeLatitudeInterpCS(Linear2DSet domainSet, Gridded2DSet lonlatSet) throws VisADException {
     this(domainSet, lonlatSet, true);
   }

   public float[][] toReference(float[][] values) throws VisADException {
     float[][] coords = domainSet.valueToGrid(values);
     coords = transSet.gridToValue(coords);
     float[][] lonlat = lonlatSet.gridToValue(coords);

     if (!(neg180pos180 && extNeg180pos180)) { // if true lonRanges are same so don't do anything
       if (neg180pos180) {
         for (int t=0; t 180f) {
             lonlat[lonIdx][t] -= 360f;
           }
         }
       }
       else {
         for (int t=0; t 180f) {
             lonlat[lonIdx][t] -= 360f;
           }
         }
       } 
       else {
         for (int t=0; t 

Ads help maintain this website.