Subversion Repositories eFlore/Applications.moissonnage

Compare Revisions

Ignore whitespace Rev 30 → Rev 31

/trunk/services/bibliotheque/Maillage.php
10,7 → 10,7
private $indexLatitude;
private $mailles;
private $bdd = null;
private $bdd = null;
66,6 → 66,7
") ORDER BY axe, position";
$indexMailles = $this->getBdd()->recupererTous($requete);
foreach ($indexMailles as $index) {
if ($index['axe'] == 'lng') {
$this->indexLongitude[$index['position']] = array($index['debut'], $index['fin']);
89,7 → 90,7
public function ajouterPoints(& $points) {
foreach ($points as $index => $point) {
foreach ($points as $point) {
list($longitude, $latitude) = $this->obtenirCoordonneesPoint($point);
list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude);
$this->mailles[$indexLatitude][$indexLongitude]->ajouterPoint($point);
96,6 → 97,15
}
}
public function ajouterMailles(& $mailles) {
foreach ($mailles as $maille) {
$longitude = ($maille->longitudeOuest + $maille->longitudeEst) / 2;
$latitude = ($maille->latitudeSud + $maille->latitudeNord) / 2;
list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude);
$this->mailles[$indexLatitude][$indexLongitude]->combinerMailles($maille);
}
}
private function obtenirCoordonneesPoint($point) {
$longitude = 0;
$latitude = 0;
123,107 → 133,31
return array($indexLongitude, $indexLatitude);
}
 
public function formaterSortie() {
public function formaterSortie($toutesLesMailles = false) {
$mailles_resume = array();
foreach ($this->mailles as $ligne) {
foreach ($ligne as $maille) {
$nombrePoints = $maille->getNombrePoints();
if ($nombrePoints == 0)
continue;
$mailles_resume[] = array(
'zoom' => $this->zoom,
'sud' => $maille->getLatitudeSud(),
'ouest' => $maille->getLongitudeOuest(),
'nord' => $maille->getLatitudeNord(),
'est' => $maille->getLongitudeEst(),
'points' => $nombrePoints,
'type_site' => 'MAILLE'
);
}
}
if (count($mailles_resume) == 0 || count($mailles_resume[0]) == 0)
return array();
return $mailles_resume;
}
public function formaterPourInsertionBdd() {
$mailles_resume = array();
foreach ($this->mailles as $ligne) {
foreach ($ligne as $maille) {
if ($maille->getNombrePoints() > 0) {
if ($nombrePoints > 0 || $toutesLesMailles) {
$mailles_resume[] = array(
'zoom' => $this->zoom,
'sud' => $maille->getLatitudeSud(),
'ouest' => $maille->getLongitudeOuest(),
'nord' => $maille->getLatitudeNord(),
'est' => $maille->getLongitudeEst(),
'indexLat' => $maille->getIndexLatitude(),
'indexLng' => $maille->getIndexLongitude(),
'points' => $maille->getNombrePoints()
'zoom' => $this->zoom,
'sud' => $maille->getLatitudeSud(),
'ouest' => $maille->getLongitudeOuest(),
'nord' => $maille->getLatitudeNord(),
'est' => $maille->getLongitudeEst(),
'points' => $nombrePoints,
'observations' => $maille->getNombreObservations(),
'type_site' => 'MAILLE'
);
}
}
}
if (count($mailles_resume[0]) == 0)
if (count($mailles_resume) == 0 || count($mailles_resume[0]) == 0)
return array();
return $mailles_resume;
}
 
public function zoomer() {
$this->zoom += 1;
}
// redecoupage des mailles en 4 (fonction quadtree)
// TODO : revoir le fonctionnement de cette methode (pour utilisation par les scripts uniquement)
public function redecouperMailles() {
$bdd = new Bdd();
while (count($this->indexLatitude) > 0) {
array_pop($this->indexLatitude);
}
while (count($this->indexLongitude) > 0) {
array_pop($this->indexLongitude);
}
$mailles = $this->resumePourInsertionBdd();
while (count($this->mailles) > 0) {
array_pop($this->mailles);
}
foreach ($mailles as $maille) {
$indexLat = 2 * $maille['indexLat'];
$indexLng = 2 * $maille['indexLng'];
// rechercher les nouvelles coordonnees des mailles au niveau de zoom inferieur
$requete = "SELECT axe,position,debut,fin FROM mailles_index WHERE zoom=". $this->zoom ." AND ((axe='lat'"
. " AND (position={$indexLat} OR position=" . ($indexLat+1) . ")) OR (axe='lng' AND"
. " (position={$indexLng} OR position=" . ($indexLng+1) . "))) ORDER BY If(axe='lat',0,1)";
$resultats = $bdd->recupererTous($requete);
$this->indexLatitude[$indexLat] = array($resultats[0]['debut'], $resultats[0]['fin']);
$this->indexLatitude[$indexLat+1] = array($resultats[1]['debut'], $resultats[1]['fin']);
$this->indexLongitude[$indexLng] = array($resultats[2]['debut'], $resultats[2]['fin']);
$this->indexLongitude[$indexLng+1] = array($resultats[3]['debut'], $resultats[3]['fin']);
}
ksort($this->indexLatitude);
ksort($this->indexLongitude);
// creer et ajouter les nouvelles mailles a partir des nouveaux index
foreach ($this->indexLatitude as $indexLat => $intervalleLat) {
$ligne = array();
foreach ($this->indexLongitude as $indexLng => $intervalleLng) {
$ligne[] = new Maille($intervalleLat[0], $intervalleLng[0], $intervalleLat[1],
$intervalleLng[1], $indexLat, $indexLng);
}
$this->mailles[] = $ligne;
}
 
}
public function getNombreMailles() {
return count($this->mailles);
}
}
 
?>