5,7 → 5,7 |
|
private $sourceDonnees; |
|
public function __construct($source) { |
public function __construct($source = '') { |
$this->sourceDonnees = $source; |
} |
|
14,23 → 14,24 |
$objetJSON = new StdClass(); |
$objetJSON->type = "FeatureCollection"; |
$objetJSON->stats = new StdClass(); |
$objetJSON->stats->communes = 0; |
$objetJSON->stats->stations = 0; |
$objetJSON->stats->source = $this->sourceDonnees; |
$objetJSON->stats->formeDonnees = ''; |
if (count($stations) > 0) { |
$objetJSON->stats->formeDonnees = ($stations[0]['type_site'] == 'MAILLE') ? 'maille' : 'point'; |
} |
$objetJSON->stats->sites = 0; |
$objetJSON->stats->observations = 0; |
$objetJSON->features = array(); |
|
foreach ($stations as $station) { |
$stationJSON = NULL; |
// construction d'un objet feature adapte a la structure des donnees spatiales |
if ($station['type_site'] == 'MAILLE') { |
$stationJSON = $this->formaterMaille($station); |
$objetJSON->stats->sites += $station['points']; |
} else { |
if ($station['type_site'] == 'STATION') { |
$objetJSON->stats->communes ++; |
} else { |
$objetJSON->stats->stations ++; |
} |
$objetJSON->stats->sites ++; |
$stationJSON = $this->formaterPoint($station); |
} |
$objetJSON->stats->observations += $station['observations']; |
if (!is_null($stationJSON)) { |
$objetJSON->features[] = $stationJSON; |
} |
44,6 → 45,7 |
$json->geometry = new StdClass(); |
$json->properties = new StdClass(); |
$json->geometry->type = "Point"; |
$json->properties->source = $this->sourceDonnees; |
$json->properties->typeSite = $station['type_site']; |
if ($this->sourceDonnees == 'floradata' && $station['type_site'] == 'COMMUNE') { |
$json->geometry->coordinates = array($station['lat_commune'], $station['lng_commune']); |
54,7 → 56,6 |
if ($this->sourceDonnees == 'floradata') { |
$json->properties->nom = $this->construireNomStationFloradata($station); |
} else { |
$station['code_insee'] = ''; |
$codeDepartement = $this->extraireCodeDepartement($station['code_insee']); |
$json->properties->nom = trim($station['nom'])." ({$codeDepartement})"; |
} |
71,7 → 72,7 |
if (strlen($nom) == 0) { |
$nom = 'station sans nom, '.trim($station['zone_geo']); |
} |
$nom .= " ({$codeDepartement})";; |
$nom .= " ({$codeDepartement})"; |
} |
return $nom; |
} |
87,9 → 88,6 |
|
|
private function formaterMaille($maille) { |
if ($maille['points'] == 0) { |
return null; |
} |
$json = new StdClass(); |
$json->type = "Feature"; |
$json->geometry = new StdClass(); |
102,7 → 100,8 |
array(floatval($maille['sud']), floatval($maille['ouest'])) |
); |
$json->properties = new StdClass(); |
$json->properties->typeSite = $maille['type_site']; |
$json->properties->source = $this->sourceDonnees; |
$json->properties->typeSite = 'MAILLE'; |
$json->properties->nombrePoints = $maille['points']; |
return $json; |
} |
136,6 → 135,20 |
return $url; |
} |
|
public function formaterMaillesVides($mailles) { |
$objetJSON = new StdClass(); |
$objetJSON->type = "FeatureCollection"; |
$objetJSON->stats = new StdClass(); |
$objetJSON->stats->source = ''; |
$objetJSON->stats->formeDonnees = 'maille'; |
$objetJSON->stats->sites = 0; |
$objetJSON->features = array(); |
foreach ($mailles as $maille) { |
$objetJSON->features[] = $this->formaterMaille($maille); |
} |
return $objetJSON; |
} |
|
} |
|
?> |