Subversion Repositories eFlore/Applications.moissonnage

Rev

Rev 26 | Rev 34 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26 Rev 31
Line 3... Line 3...
3
 
3
 
Line 4... Line 4...
4
class FormateurJson {
4
class FormateurJson {
Line 5... Line 5...
5
	
5
	
6
	private $sourceDonnees;
6
	private $sourceDonnees;
7
	
7
	
Line 8... Line 8...
8
	public function __construct($source) {
8
	public function __construct($source = '') {
9
		$this->sourceDonnees = $source;
9
		$this->sourceDonnees = $source;
10
	}
10
	}
11
	
11
	
-
 
12
	
-
 
13
	public function formaterStations($stations) {
-
 
14
		$objetJSON = new StdClass();
-
 
15
		$objetJSON->type = "FeatureCollection";
-
 
16
		$objetJSON->stats = new StdClass();
12
	
17
		$objetJSON->stats->source = $this->sourceDonnees;
13
	public function formaterStations($stations) {
18
		$objetJSON->stats->formeDonnees = '';
14
		$objetJSON = new StdClass();
19
		if (count($stations) > 0) {
15
		$objetJSON->type = "FeatureCollection";
-
 
16
		$objetJSON->stats = new StdClass();
20
			$objetJSON->stats->formeDonnees = ($stations[0]['type_site'] == 'MAILLE') ? 'maille' : 'point';
17
		$objetJSON->stats->communes = 0;
21
		}
18
		$objetJSON->stats->stations = 0;
-
 
19
		$objetJSON->features = array();
22
		$objetJSON->stats->sites = 0;
20
		
23
		$objetJSON->stats->observations = 0;
-
 
24
		$objetJSON->features = array();
21
		foreach ($stations as $station) {
25
		foreach ($stations as $station) {
22
			$stationJSON = NULL;
-
 
23
			// construction d'un objet feature adapte a la structure des donnees spatiales
-
 
24
			if ($station['type_site'] == 'MAILLE') {
-
 
25
				$stationJSON = $this->formaterMaille($station);
26
			$stationJSON = NULL;
26
			} else {
-
 
27
				if ($station['type_site'] == 'STATION') {
27
			if ($station['type_site'] == 'MAILLE') {
28
					$objetJSON->stats->communes ++;
28
				$stationJSON = $this->formaterMaille($station);
-
 
29
				$objetJSON->stats->sites += $station['points'];
29
				} else {
30
			} else {
30
					$objetJSON->stats->stations ++;
31
				$objetJSON->stats->sites ++;
31
				}
32
				$stationJSON = $this->formaterPoint($station);
32
				$stationJSON = $this->formaterPoint($station);
33
			}
33
			}
34
			$objetJSON->stats->observations += $station['observations'];
Line 42... Line 43...
42
		$json = new StdClass();
43
		$json = new StdClass();
43
		$json->type = "Feature";
44
		$json->type = "Feature";
44
		$json->geometry = new StdClass();
45
		$json->geometry = new StdClass();
45
		$json->properties = new StdClass();
46
		$json->properties = new StdClass();
46
		$json->geometry->type = "Point";
47
		$json->geometry->type = "Point";
-
 
48
		$json->properties->source = $this->sourceDonnees;
47
		$json->properties->typeSite = $station['type_site'];
49
		$json->properties->typeSite = $station['type_site'];
48
		if ($this->sourceDonnees == 'floradata' && $station['type_site'] == 'COMMUNE') {
50
		if ($this->sourceDonnees == 'floradata' && $station['type_site'] == 'COMMUNE') {
49
			$json->geometry->coordinates = array($station['lat_commune'], $station['lng_commune']);
51
			$json->geometry->coordinates = array($station['lat_commune'], $station['lng_commune']);
50
		} else {
52
		} else {
51
			$json->geometry->coordinates = array($station['latitude'], $station['longitude']);
53
			$json->geometry->coordinates = array($station['latitude'], $station['longitude']);
52
		}
54
		}
Line 53... Line 55...
53
		
55
		
54
		if ($this->sourceDonnees == 'floradata') {
56
		if ($this->sourceDonnees == 'floradata') {
55
			$json->properties->nom = $this->construireNomStationFloradata($station);
57
			$json->properties->nom = $this->construireNomStationFloradata($station);
56
		} else {
-
 
57
			$station['code_insee'] = '';
58
		} else {
58
			$codeDepartement = $this->extraireCodeDepartement($station['code_insee']);
59
			$codeDepartement = $this->extraireCodeDepartement($station['code_insee']);
59
			$json->properties->nom = trim($station['nom'])." ({$codeDepartement})";
60
			$json->properties->nom = trim($station['nom'])." ({$codeDepartement})";
Line 60... Line 61...
60
		}
61
		}
Line 69... Line 70...
69
			$nom = $station['zone_geo'] . " ({$codeDepartement})";
70
			$nom = $station['zone_geo'] . " ({$codeDepartement})";
70
		} else {
71
		} else {
71
			if (strlen($nom) == 0) {
72
			if (strlen($nom) == 0) {
72
				$nom = 'station sans nom, '.trim($station['zone_geo']);
73
				$nom = 'station sans nom, '.trim($station['zone_geo']);
73
			}
74
			}
74
			$nom .= " ({$codeDepartement})";;
75
			$nom .= " ({$codeDepartement})";
75
		}
76
		}
76
		return $nom;
77
		return $nom;
77
	}
78
	}
Line 78... Line 79...
78
	
79
	
Line 85... Line 86...
85
		return $codeDepartement;
86
		return $codeDepartement;
86
	}
87
	}
Line 87... Line 88...
87
	
88
	
88
	
-
 
89
	private function formaterMaille($maille) {
-
 
90
		if ($maille['points'] == 0) {
-
 
91
			return null;
89
	
92
		}
90
	private function formaterMaille($maille) {
93
		$json = new StdClass();
91
		$json = new StdClass();
94
		$json->type = "Feature";
92
		$json->type = "Feature";
95
		$json->geometry = new StdClass();
93
		$json->geometry = new StdClass();
Line 100... Line 98...
100
			array(floatval($maille['nord']), floatval($maille['est'])),
98
			array(floatval($maille['nord']), floatval($maille['est'])),
101
			array(floatval($maille['nord']), floatval($maille['ouest'])),
99
			array(floatval($maille['nord']), floatval($maille['ouest'])),
102
			array(floatval($maille['sud']),  floatval($maille['ouest']))
100
			array(floatval($maille['sud']),  floatval($maille['ouest']))
103
		);
101
		);
104
		$json->properties = new StdClass();
102
		$json->properties = new StdClass();
-
 
103
		$json->properties->source = $this->sourceDonnees;
105
		$json->properties->typeSite = $maille['type_site'];
104
		$json->properties->typeSite = 'MAILLE';
106
		$json->properties->nombrePoints = $maille['points'];
105
		$json->properties->nombrePoints = $maille['points'];
107
		return $json;
106
		return $json;
108
	}
107
	}
Line 134... Line 133...
134
			$url = 'http://www.tela-botanica.org/bdtfx-nn-'.$observation['nn'];
133
			$url = 'http://www.tela-botanica.org/bdtfx-nn-'.$observation['nn'];
135
		}
134
		}
136
		return $url;
135
		return $url;
137
	}
136
	}
Line -... Line 137...
-
 
137
	
-
 
138
	public function formaterMaillesVides($mailles) {
-
 
139
		$objetJSON = new StdClass();
-
 
140
		$objetJSON->type = "FeatureCollection";
-
 
141
		$objetJSON->stats = new StdClass();
-
 
142
		$objetJSON->stats->source = '';
-
 
143
		$objetJSON->stats->formeDonnees = 'maille';
-
 
144
		$objetJSON->stats->sites = 0;
-
 
145
		$objetJSON->features = array();
-
 
146
		foreach ($mailles as $maille) {
-
 
147
			$objetJSON->features[] = $this->formaterMaille($maille);
-
 
148
		}
-
 
149
		return $objetJSON;
-
 
150
	}
138
	
151
	
Line 139... Line 152...
139
}
152
}
140
 
153