public Object valueAt(double lat,double lon,Projection proj){
  int lat_index=-1;
  int lon_index=-1;
  if (renderType == RENDERTYPE_LATLON) {
    lat_index=(int)Math.round((lat - latitude) / verticalResolution);
    lon_index=(int)Math.round((lon - longitude) / horizontalResolution);
  }
 else   if (renderType == RENDERTYPE_XY || renderType == RENDERTYPE_OFFSET) {
    if (getNeedToRegenerate()) {
      if (proj == null) {
        return null;
      }
      generate(proj);
    }
    Point pt=(Point)proj.forward(lat,lon,new Point());
    lat_index=(int)Math.round((pt.y - point1.y) / verticalResolution);
    lon_index=(int)Math.round((pt.x - point1.x) / horizontalResolution);
  }
  GridData gd=getData();
  if (gd != null && (lat_index >= 0 || lat_index < rows) && (lon_index >= 0 || lon_index < columns)) {
    Object obj=null;
    if (major == COLUMN_MAJOR) {
      obj=gd.get(lon_index,lat_index);
    }
 else {
      obj=gd.get(lat_index,lon_index);
    }
    return obj;
  }
  return null;
}

public Object valueAt ( double lat , double lon , Projection proj ) { int lat_index = - 1 ; int lon_index = - 1 ; if ( renderType == RENDERTYPE_LATLON ) { lat_index = ( int ) Math . round ( ( lat - latitude ) / verticalResolution ) ; lon_index = ( int ) Math . round ( ( lon - longitude ) / horizontalResolution ) ; } else if ( renderType == RENDERTYPE_XY || renderType == RENDERTYPE_OFFSET ) { if ( getNeedToRegenerate ( ) ) { if ( proj == null ) { return null ; } generate ( proj ) ; } Point pt = ( Point ) proj . forward ( lat , lon , new Point ( ) ) ; lat_index = ( int ) Math . round ( ( pt . y - point1 . y ) / verticalResolution ) ; lon_index = ( int ) Math . round ( ( pt . x - point1 . x ) / horizontalResolution ) ; } GridData gd = getData ( ) ; if ( gd != null && ( lat_index >= 0 || lat_index < rows ) && ( lon_index >= 0 || lon_index < columns ) ) { Object obj = null ; if ( major == COLUMN_MAJOR ) { obj = gd . get ( lon_index , lat_index ) ; } else { obj = gd . get ( lat_index , lon_index ) ; } return obj ; } return null ; }
the value at the closest sw post to the given lat / lon . this is just a go - to - the - closest - post solution .
