Subversion Repositories eFlore/Applications.moissonnage

Compare Revisions

Ignore whitespace Rev 31 → Rev 34

/trunk/services/bibliotheque/Maillage.php
3,40 → 3,47
 
class Maillage {
private $bbox;
private $zoom;
private $bbox = array();
private $zoom = '';
private $source = '';
private $indexLongitude;
private $indexLatitude;
private $mailles;
private $indexLongitude = array();
private $indexLatitude = array();
private $mailles = array();
private $bdd = null;
public function __construct($bbox, $zoom) {
$this->bbox = $bbox;
$this->zoom = $zoom;
public function __construct($bbox, $zoom, $source) {
$this->bbox = $this->calculerLimiteBboxGlobale($bbox);
$this->zoom = $zoom;
$this->source = $source;
$this->indexLongitude = array();
$this->indexLatitude = array();
$this->indexLatitude = array();
$this->mailles = array();
}
public function __destruct() {
while (count($this->indexLatitude) > 0) {
array_pop($this->indexLatitude);
private function calculerLimiteBboxGlobale($bbox) {
$bboxGlobale = $bbox[0];
for ($index = 1; $index < count($bbox); $index ++) {
if ($bbox[$index]['ouest'] < $bboxGlobale['ouest']) {
$bboxGlobale['ouest'] = $bbox[$index]['ouest'];
}
if ($bbox[$index]['sud'] < $bboxGlobale['sud']) {
$bboxGlobale['sud'] = $bbox[$index]['sud'];
}
if ($bbox[$index]['est'] > $bboxGlobale['est']) {
$bboxGlobale['est'] = $bbox[$index]['est'];
}
if ($bbox[$index]['nord'] > $bboxGlobale['nord']) {
$bboxGlobale['nord'] = $bbox[$index]['nord'];
}
}
while (count($this->indexLongitude) > 0) {
array_pop($this->indexLongitude);
}
return $bboxGlobale;
}
while (count($this->mailles) > 0) {
array_pop($this->mailles);
}
unset($this);
}
public function genererMaillesVides() {
$this->recupererIndexMaillesDansBbox();
foreach ($this->indexLatitude as $indexLat => $intervalleLat) {
51,7 → 58,6
private function recupererIndexMaillesDansBbox() {
// recuperer toutes les mailles qui couvrent l'espace a requeter
$conditionsLongitude = "";
if ($this->bbox['ouest'] > $this->bbox['est']) {
$conditionsLongitude = "NOT(debut>=".$this->bbox['ouest']." AND fin<=".$this->bbox['est'].")";
66,7 → 72,6
") 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']);
74,51 → 79,36
$this->indexLatitude[$index['position']] = array($index['debut'], $index['fin']);
}
}
}
}
private function getBdd() {
if (is_null($this->bdd)) {
$this->bdd = new Bdd();
}
$nomBdd = Config::get('bdd_eflore');
if (is_null($nomBdd)) {
$nomBdd = Config::get('bdd_nom');
}
$nomBdd = Config::get('bdd_nom_eflore');
$this->bdd->requeter("USE ".$nomBdd);
return $this->bdd;
}
public function ajouterPoints(& $points) {
foreach ($points as $point) {
list($longitude, $latitude) = $this->obtenirCoordonneesPoint($point);
public function ajouterStations(& $stations) {
foreach ($stations as $station) {
$longitude = $station['longitude'];
$latitude = $station['latitude'];
list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude);
$this->mailles[$indexLatitude][$indexLongitude]->ajouterPoint($point);
$this->mailles[$indexLatitude][$indexLongitude]->ajouterStation($station, $this->source);
}
}
public function ajouterMailles(& $mailles) {
foreach ($mailles as $maille) {
$longitude = ($maille->longitudeOuest + $maille->longitudeEst) / 2;
$latitude = ($maille->latitudeSud + $maille->latitudeNord) / 2;
$longitude = ($maille['ouest'] + $maille['est']) / 2;
$latitude = ($maille['sud'] + $maille['nord']) / 2;
list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude);
$this->mailles[$indexLatitude][$indexLongitude]->combinerMailles($maille);
$this->mailles[$indexLatitude][$indexLongitude]->combinerMailles($maille, $this->source);
}
}
private function obtenirCoordonneesPoint($point) {
$longitude = 0;
$latitude = 0;
if (!isset($point['type_site']) || $point['type_site'] == 'STATION') {
$longitude = $point['longitude'];
$latitude = $point['latitude'];
} else {
$longitude = $point['lng_commune'];
$latitude = $point['lat_commune'];
}
return array($longitude, $latitude);
}
private function rechercherIndexMaille($longitude, $latitude) {
$indexLatitude = 0;
$indexLongitude = 0;
128,26 → 118,25
}
while ($indexLongitude < count($this->indexLongitude) - 1
&& $this->mailles[$indexLatitude][$indexLongitude]->getLongitudeEst() < $longitude) {
$indexLongitude ++;
$indexLongitude ++;
}
return array($indexLongitude, $indexLatitude);
}
 
public function formaterSortie($toutesLesMailles = false) {
public function formaterSortie() {
$mailles_resume = array();
foreach ($this->mailles as $ligne) {
foreach ($ligne as $maille) {
$nombrePoints = $maille->getNombrePoints();
if ($nombrePoints > 0 || $toutesLesMailles) {
$nombreStations = $maille->getNombrestations();
if ($nombreStations > 0) {
$mailles_resume[] = array(
'zoom' => $this->zoom,
'type_site' => 'MAILLE',
'sud' => $maille->getLatitudeSud(),
'ouest' => $maille->getLongitudeOuest(),
'nord' => $maille->getLatitudeNord(),
'est' => $maille->getLongitudeEst(),
'points' => $nombrePoints,
'observations' => $maille->getNombreObservations(),
'type_site' => 'MAILLE'
'stations' => $maille->getStations(),
'observations' => $maille->getObservations()
);
}
}
157,7 → 146,6
return $mailles_resume;
}
 
}
 
?>