Beispiel #1
0
 /**
  * Compares the histogram object against another histogram object.
  * The lower the returned value is, the closer a match they are.
  *
  * @param Histogram $histogram The histogram object to compare against.
  * @return int The comparison value. Lower means a closer match.
  */
 private function compare_against($histogram)
 {
     $value = 0;
     // If there is no histogram (image couldn't be analyzed), never match anything
     if ($this->histogram == '' || $histogram == '') {
         return self::$match_threshold;
     }
     foreach ($this->histogram as $channel_key => $color_channel) {
         foreach ($color_channel as $bucket_key => $color_bucket) {
             $value += abs($color_bucket - $histogram->get($channel_key, $bucket_key));
             // Stop computing early if the value will never be a match
             if ($value >= self::$match_threshold) {
                 return self::$match_threshold;
             }
         }
     }
     return $value;
 }
            $flt = array("tipo" => Filtro::$FILTRO_ESTADO, "valores" => $valores);
            break;
        case "regiao":
            $valores = PublicMethods::getRegionID(explode(",", $value["valores"]), $ocon);
            $flt = array("tipo" => Filtro::$FILTRO_REGIAO, "valores" => $valores);
            break;
    }
    array_push($filtros, $flt);
}
/* obtendo indicador */
$ano = 2010;
if (sizeof($lindicador) > 1) {
    $ano = $lindicador[1];
}
$indicador = PublicMethods::getIndicator($lindicador[0], $ano, $ocon);
$h = new Histogram($indicador['indc'], $indicador['ano'], $espacialidade, $ocon);
//explodindo os filtros
foreach ($filtros as $filtro) {
    if ($filtro['tipo'] == Filtro::$FILTRO_REGIAO) {
        $h->selectByRegions($filtro['valores'], $indicador['indc'], $indicador['ano']);
    } else {
        if ($filtro['tipo'] == Filtro::$FILTRO_ESTADO) {
            $h->selectByStates($filtro['valores'], $indicador['indc'], $indicador['ano']);
        } else {
            if ($filtro['tipo'] == Filtro::$FILTRO_MUNICIPIO) {
                $h->selectByCities($filtro['valores'], $indicador['indc'], $indicador['ano']);
            }
        }
    }
}
$h->getFunctions($ocon);
Beispiel #3
0
 /**
  * Moves the uploaded file from its temporary location to the server.
  *
  * This method will also create web and thumbnail sizes of the media.
  *
  * @param array $file The uploaded file from the $_FILES array.
  * @param string $filename The filename to be moved to.
  * @param string $extension The extension of the moved file.
  * @param string &$histograms Will be given a serialized histogram object.
  * @param bool $allow_dupes Whether duplicates should be allowed.
  * @return array A status array, where the 'status' index is the status code of the operation, and the 'response' index is a string describing the status.
  */
 private static function move_to_server($file, $filename, $extension, &$histograms, $allow_dupes)
 {
     $move_to = UPLOADS_DIR . "/{$filename}.{$extension}";
     // If the upload fails, return an error message
     if (!move_uploaded_file($file['tmp_name'], $move_to)) {
         return array('status' => STATUS_UPLOAD_ERROR, 'response' => "Couldn't move the file to the server.");
     }
     self::create_image_sizes($filename, $extension);
     // Create a serialized histogram for the database
     // Using the web source because it's smaller than the full size
     $web_src = UPLOADS_DIR . "/{$filename}" . WEB_SRC_SUFFIX . ".{$extension}";
     $thumb_src = UPLOADS_DIR . "/{$filename}" . THUMB_SRC_SUFFIX . ".{$extension}";
     $histograms = Histogram::create_from($web_src);
     // Compare histogram against exisiting images to prevent duplicates
     $histogram = new Histogram($histograms);
     $similar_id = $histogram->compare_against_database();
     // If a similar image was found, return a status
     if ($similar_id !== null && !$allow_dupes) {
         // Delete the uploaded files from the server
         unlink(UPLOADS_DIR . "/{$filename}.{$extension}");
         unlink($web_src);
         unlink($thumb_src);
         return array('status' => STATUS_SIMILAR_EXISTS, 'response' => $similar_id);
     }
     return array('status' => STATUS_OK, 'response' => 'File successfully moved to server.');
 }
//Espacialidade Selecionada
//    var_dump($lugares);
//    print_r($lugares);
//    Pega o array com os valores da espacialidade selecionada
$lugares2 = array();
//    foreach ($lugares as $key => $val){
//        if($key == 'id'){
//            $lugares2 = explode(',', $val);
//            echo $lugares2['ids'].'  ';
//        }
//        echo 'Key: '.$key.'  ';
//        echo 'Val: '.$val.'  ';
//        if ($val['e'] == $espacialidadeSelecionada){
//            $lugares2 = $val;
//        }
//    }
//    var_dump($lugares2);
//print_r($lugares);
//    $lugares2['ids'] = explode(',', $lugares['est']);
//Pega indicador e ano
$indicador = $_POST['indicador'];
//    echo $indicador;
$ano = $_POST['ano'];
//    echo $ano;
$arrayConsulta = array();
$arrayConsulta[] = $espacialidadeSelecionada;
$arrayConsulta[] = $lugares;
$arrayConsulta[] = $indicador;
$arrayConsulta[] = $ano;
$histograma = new Histogram($arrayConsulta);
echo json_encode($histograma->DrawHistograma());