mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-06-20 01:44:42 +02:00
service motocultrice, traductions
This commit is contained in:
parent
528ebb672a
commit
f5ab0c8205
16 changed files with 427 additions and 128 deletions
91
src/Service/Motocultrice.php
Normal file
91
src/Service/Motocultrice.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class Motocultrice
|
||||
{
|
||||
private $overpassApiUrl = 'https://overpass-api.de/api/interpreter';
|
||||
|
||||
public function __construct(
|
||||
private HttpClientInterface $client
|
||||
) {
|
||||
}
|
||||
|
||||
public function labourer(string $zone): array
|
||||
{
|
||||
$query = <<<QUERY
|
||||
[out:json][timeout:25];
|
||||
area["name"="{$zone}"]->.searchArea;
|
||||
(
|
||||
nwr["shop"](area.searchArea);
|
||||
);
|
||||
out body;
|
||||
>;
|
||||
out skel qt;
|
||||
QUERY;
|
||||
|
||||
try {
|
||||
$response = $this->client->request('POST', $this->overpassApiUrl, [
|
||||
'body' => ['data' => $query]
|
||||
]);
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
|
||||
$shops = [];
|
||||
if (isset($data['elements'])) {
|
||||
foreach ($data['elements'] as $element) {
|
||||
if (isset($element['tags']['shop'])) {
|
||||
$shops[] = [
|
||||
'id' => $element['id'],
|
||||
'type' => $element['type'],
|
||||
'name' => $element['tags']['name'] ?? 'Sans nom',
|
||||
'shop_type' => $element['tags']['shop'],
|
||||
'lat' => $element['lat'] ?? null,
|
||||
'lon' => $element['lon'] ?? null,
|
||||
'tags' => $element['tags']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $shops;
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("Erreur lors de la requête Overpass : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function get_osm_object_data($osm_object_id = 12855459190)
|
||||
{
|
||||
$object_id = "https://www.openstreetmap.org/api/0.6/node/".$osm_object_id;
|
||||
|
||||
try {
|
||||
$response = $this->client->request('GET', $object_id);
|
||||
$xml = simplexml_load_string($response->getContent());
|
||||
$json = json_encode($xml);
|
||||
$osm_object_data = json_decode($json, true);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("Impossible de récupérer les données OSM : " . $e->getMessage());
|
||||
}
|
||||
|
||||
// convertir les tags en clés et valeurs
|
||||
$osm_object_data['tags_converted'] = [];
|
||||
|
||||
foreach ($osm_object_data['node']['tag'] as $attribute) {
|
||||
$osm_object_data['node']['tags_converted'][$attribute['@attributes']['k']] = $attribute['@attributes']['v'];
|
||||
}
|
||||
|
||||
return $osm_object_data['node'];
|
||||
}
|
||||
|
||||
public function semer(): string
|
||||
{
|
||||
return "La motocultrice sème les graines";
|
||||
}
|
||||
|
||||
public function récolter(): string
|
||||
{
|
||||
return "La motocultrice récolte les cultures";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue