Subversion Repositories eFlore/Applications.moissonnage

Rev

Rev 31 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 31 Rev 34
Line 1... Line 1...
1
<?php
1
<?php
Line 2... Line 2...
2
 
2
 
Line 3... Line 3...
3
 
3
 
4
class Maillage {
4
class Maillage {
-
 
5
	
5
	
6
	private $bbox = array();
6
	private $bbox;
7
	private $zoom = '';
7
	private $zoom;
8
	private $source = '';
8
	
9
	
Line 9... Line 10...
9
	private $indexLongitude;
10
	private $indexLongitude = array();
Line 10... Line 11...
10
	private $indexLatitude;
11
	private $indexLatitude  = array();
-
 
12
	private $mailles = array();
11
	private $mailles;
13
	
12
	
14
	private $bdd = null;
13
	private $bdd = null;
15
	
14
	
16
	
15
	
17
	
16
	
18
	public function __construct($bbox, $zoom, $source) {
Line 17... Line 19...
17
	public function __construct($bbox, $zoom) {
19
		$this->bbox   = $this->calculerLimiteBboxGlobale($bbox);
-
 
20
		$this->zoom   = $zoom;
18
		$this->bbox = $bbox;
21
		$this->source = $source;
-
 
22
		$this->indexLongitude = array();
19
		$this->zoom = $zoom;
23
		$this->indexLatitude  = array();
20
		$this->indexLongitude = array();
24
		$this->mailles = array();
21
		$this->indexLatitude = array();
25
	}
22
		$this->mailles = array();
26
	
23
	}
27
	private function calculerLimiteBboxGlobale($bbox) {
-
 
28
		$bboxGlobale = $bbox[0];
-
 
29
		for ($index = 1; $index < count($bbox); $index ++) {
24
	
30
			if ($bbox[$index]['ouest'] < $bboxGlobale['ouest']) {
25
	public function __destruct() {
31
				$bboxGlobale['ouest'] = $bbox[$index]['ouest'];
26
		while (count($this->indexLatitude) > 0) {
32
			}
-
 
33
			if ($bbox[$index]['sud'] < $bboxGlobale['sud']) {
27
			array_pop($this->indexLatitude);
34
				$bboxGlobale['sud'] = $bbox[$index]['sud'];
28
		}
35
			}
29
		while (count($this->indexLongitude) > 0) {
36
			if ($bbox[$index]['est'] > $bboxGlobale['est']) {
30
			array_pop($this->indexLongitude);
37
				$bboxGlobale['est'] = $bbox[$index]['est'];
Line 31... Line 38...
31
		}
38
			}
32
		
39
			if ($bbox[$index]['nord'] > $bboxGlobale['nord']) {
33
		while (count($this->mailles) > 0) {
40
				$bboxGlobale['nord'] = $bbox[$index]['nord'];
34
			array_pop($this->mailles);
41
			}
Line 49... Line 56...
49
		}
56
		}
50
	}
57
	}
Line 51... Line 58...
51
	
58
	
52
	
-
 
53
	private function recupererIndexMaillesDansBbox() {
59
	
54
		// recuperer toutes les mailles qui couvrent l'espace a requeter
60
	private function recupererIndexMaillesDansBbox() {
55
		$conditionsLongitude = "";
61
		$conditionsLongitude = "";
56
		if ($this->bbox['ouest'] >  $this->bbox['est']) {
62
		if ($this->bbox['ouest'] >  $this->bbox['est']) {
57
			$conditionsLongitude = "NOT(debut>=".$this->bbox['ouest']." AND fin<=".$this->bbox['est'].")";
63
			$conditionsLongitude = "NOT(debut>=".$this->bbox['ouest']." AND fin<=".$this->bbox['est'].")";
Line 64... Line 70...
64
				"(axe='lat' AND fin>=".$this->bbox['sud']." AND debut<=".$this->bbox['nord'].") ".
70
				"(axe='lat' AND fin>=".$this->bbox['sud']." AND debut<=".$this->bbox['nord'].") ".
65
				"OR (axe='lng' AND {$conditionsLongitude})".
71
				"OR (axe='lng' AND {$conditionsLongitude})".
66
			") ORDER BY axe, position";
72
			") ORDER BY axe, position";
67
		$indexMailles = $this->getBdd()->recupererTous($requete);
73
		$indexMailles = $this->getBdd()->recupererTous($requete);
Line 68... Line -...
68
		
-
 
69
		
74
		
70
		foreach ($indexMailles as $index) {
75
		foreach ($indexMailles as $index) {
71
			if ($index['axe'] == 'lng') {
76
			if ($index['axe'] == 'lng') {
72
				$this->indexLongitude[$index['position']] = array($index['debut'], $index['fin']);
77
				$this->indexLongitude[$index['position']] = array($index['debut'], $index['fin']);
73
			} else {
78
			} else {
74
				$this->indexLatitude[$index['position']]  = array($index['debut'], $index['fin']);
79
				$this->indexLatitude[$index['position']]  = array($index['debut'], $index['fin']);
75
			}
80
			}
76
		}
81
		}
Line 77... Line 82...
77
	}	
82
	}
78
	
83
	
79
	private function getBdd() {
84
	private function getBdd() {
80
		if (is_null($this->bdd)) {
85
		if (is_null($this->bdd)) {
81
			$this->bdd = new Bdd();
86
			$this->bdd = new Bdd();
82
		}
-
 
83
		$nomBdd = Config::get('bdd_eflore');
-
 
84
		if (is_null($nomBdd)) {
-
 
85
			$nomBdd = Config::get('bdd_nom');
87
		}
86
		}
88
		$nomBdd = Config::get('bdd_nom_eflore');
87
		$this->bdd->requeter("USE ".$nomBdd);
89
		$this->bdd->requeter("USE ".$nomBdd);
Line 88... Line 90...
88
		return $this->bdd;
90
		return $this->bdd;
89
	}
91
	}
90
	
92
	
-
 
93
	
91
	
94
	public function ajouterStations(& $stations) {
92
	public function ajouterPoints(& $points) {
95
		foreach ($stations as $station) {
93
		foreach ($points as $point) {
96
			$longitude = $station['longitude'];
94
			list($longitude, $latitude) = $this->obtenirCoordonneesPoint($point);
97
			$latitude = $station['latitude'];
Line 95... Line 98...
95
			list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude);
98
			list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude);
96
			$this->mailles[$indexLatitude][$indexLongitude]->ajouterPoint($point);
99
			$this->mailles[$indexLatitude][$indexLongitude]->ajouterStation($station, $this->source);
97
		}
100
		}
98
	}
101
	}
99
	
102
	
100
	public function ajouterMailles(& $mailles) {
103
	public function ajouterMailles(& $mailles) {
101
		foreach ($mailles as $maille) {
-
 
102
			$longitude = ($maille->longitudeOuest + $maille->longitudeEst) / 2;
-
 
103
			$latitude  = ($maille->latitudeSud    + $maille->latitudeNord) / 2;
-
 
104
			list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude);
-
 
105
			$this->mailles[$indexLatitude][$indexLongitude]->combinerMailles($maille);
-
 
106
		}
-
 
107
	}
-
 
108
	
-
 
109
	private function obtenirCoordonneesPoint($point) {
-
 
110
		$longitude = 0;
-
 
111
		$latitude = 0;
-
 
112
		if (!isset($point['type_site']) || $point['type_site'] == 'STATION') {
-
 
113
			$longitude = $point['longitude'];
104
		foreach ($mailles as $maille) {
114
			$latitude = $point['latitude'];
-
 
115
		} else {
105
			$longitude = ($maille['ouest'] + $maille['est'])  / 2;
116
			$longitude = $point['lng_commune'];
106
			$latitude  = ($maille['sud']   + $maille['nord']) / 2;
117
			$latitude = $point['lat_commune'];
107
			list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude);
118
		}
108
			$this->mailles[$indexLatitude][$indexLongitude]->combinerMailles($maille, $this->source);
119
		return array($longitude, $latitude);
109
		}
120
	}
110
	}
121
	
111
		
122
	private function rechercherIndexMaille($longitude, $latitude) {
112
	private function rechercherIndexMaille($longitude, $latitude) {
123
		$indexLatitude = 0;
113
		$indexLatitude = 0;
124
		$indexLongitude = 0;
114
		$indexLongitude = 0;
125
		while ($indexLatitude < count($this->indexLatitude) - 1
115
		while ($indexLatitude < count($this->indexLatitude) - 1
126
			&& $this->mailles[$indexLatitude][0]->getLatitudeNord() < $latitude) {
116
			&& $this->mailles[$indexLatitude][0]->getLatitudeNord() < $latitude) {
127
			$indexLatitude ++;
117
			$indexLatitude ++;
128
		}
118
		}
129
		while ($indexLongitude < count($this->indexLongitude) - 1
119
		while ($indexLongitude < count($this->indexLongitude) - 1
Line 130... Line 120...
130
			&& $this->mailles[$indexLatitude][$indexLongitude]->getLongitudeEst() < $longitude) {
120
			&& $this->mailles[$indexLatitude][$indexLongitude]->getLongitudeEst() < $longitude) {
131
			$indexLongitude ++;
121
				$indexLongitude ++;
132
		}
122
		}
133
		return array($indexLongitude, $indexLatitude);
123
		return array($indexLongitude, $indexLatitude);
134
	}
124
	}
135
 
125
 
136
	public function formaterSortie($toutesLesMailles = false) {
126
	public function formaterSortie() {
137
		$mailles_resume = array();
127
		$mailles_resume = array();
138
		foreach ($this->mailles as $ligne) {
128
		foreach ($this->mailles as $ligne) {
139
			foreach ($ligne as $maille) {
129
			foreach ($ligne as $maille) {
140
				$nombrePoints = $maille->getNombrePoints();
130
				$nombreStations = $maille->getNombrestations();
141
				if ($nombrePoints > 0 || $toutesLesMailles) {
131
				if ($nombreStations > 0) {
142
					$mailles_resume[] = array(
132
					$mailles_resume[] = array(
143
						'zoom'      => $this->zoom,
133
						'type_site' => 'MAILLE',
144
						'sud'       => $maille->getLatitudeSud(),
-
 
145
						'ouest'     => $maille->getLongitudeOuest(),
134
						'sud'       => $maille->getLatitudeSud(),
146
						'nord'      => $maille->getLatitudeNord(),
135
						'ouest'     => $maille->getLongitudeOuest(),
147
						'est'       => $maille->getLongitudeEst(),
136
						'nord'      => $maille->getLatitudeNord(),
148
						'points'    => $nombrePoints,
137
						'est'       => $maille->getLongitudeEst(),
149
						'observations' => $maille->getNombreObservations(),
138
						'stations'     => $maille->getStations(),
150
						'type_site' => 'MAILLE'
139
						'observations' => $maille->getObservations()
151
					);
140
					);
152
				}
141
				}
Line 153... Line -...
153
			}
-
 
154
		}
142
			}
Line 155... Line 143...
155
		if (count($mailles_resume) == 0 || count($mailles_resume[0]) == 0)
143
		}
156
			return array();
144
		if (count($mailles_resume) == 0 || count($mailles_resume[0]) == 0)