This commit is contained in:
Tykayn 2025-06-03 16:19:07 +02:00 committed by tykayn
parent 9390a38adf
commit 248140d78a
7 changed files with 92 additions and 73 deletions

View file

@ -10,6 +10,14 @@ class Motocultrice
private $overpassApiUrl = 'https://overpass-api.de/api/interpreter';
private $osmApiUrl = 'https://www.openstreetmap.org/api/0.6';
public $overpass_base_places = '
(
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall)$"](area.searchArea);
nw["shop"](area.searchArea);
nw["healthcare"](area.searchArea);
nw["office"](area.searchArea);
);
';
// ne pas lister les tags qui utilisent des morceaux particuliers de formulaire pour éviter que les gens aient besoin de connaître le tag OSM
public $excluded_tags_to_render = [
'name',
@ -82,34 +90,17 @@ class Motocultrice
public function get_export_query($zone) {
return <<<QUERY
[out:csv(::id,::type,::lat,::lon,name,amenity,shop,office,healthcare,"contact:email",email,"contact:phone",phone,"contact:website",website,image,url,wikidata, opening_hours,"contact:housenumber","addr:housenumber","contact:street","addr:street",note,fixme,harassment_prevention,cuisine,brand,tourism,source,zip_code,"ref:FR:SIRET")];
area["ISO3166-1"="FR"]->.france;
area["postal_code"="{$zone}"](area.france)->.searchArea;
(
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall)$"](area.searchArea);
nw["shop"](area.searchArea);
nw["healthcare"](area.searchArea);
nw["office"](area.searchArea);
);
out body;
{{geocodeArea:"{$zone}, France"}}->.searchArea;
{$this->overpass_base_places}
out skel qt;
QUERY;
}
public function get_query_places($zone) {
return <<<QUERY
[out:json][timeout:25];
area["ISO3166-1"="FR"]->.france;
area["postal_code"="{$zone}"](area.france)->.searchArea;
(
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall)$"](area.searchArea);
nw["shop"](area.searchArea);
nw["healthcare"](area.searchArea);
nw["office"](area.searchArea);
);
out body;
>;
out skel qt;
QUERY;
return '[out:json][timeout:25];
area["postal_code"="'.$zone.'"]->.searchArea;
'.$this->overpass_base_places.'
out center tags;';
}
private $more_tags = ['image', 'ref:FR:SIRET'];
@ -167,14 +158,9 @@ QUERY;
}
// Nettoyer et échapper la zone pour la requête
$zone = addslashes(trim($zone));
// //area["postal_code"="{$zone}"]->.searchArea;
$zone = addslashes(trim($zone));
$query = $this->get_query_places($zone);
if($use_places_without_email_to_reference) {
$query = $this->get_query_places($zone);
}
try {
$response = $this->client->request('POST', $this->overpassApiUrl, [
'body' => ['data' => $query]
@ -212,7 +198,7 @@ QUERY;
return $places;
} catch (\Exception $e) {
var_dump($essai_query);
var_dump($query);
var_dump($e->getMessage());
die();
throw new \Exception("Erreur lors de la requête Overpass : " . $e->getMessage());