mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-06-20 01:44:42 +02:00
search by insee code
This commit is contained in:
parent
8081889f1e
commit
8d83186a68
7 changed files with 130 additions and 78 deletions
|
@ -41,7 +41,8 @@ class Motocultrice
|
|||
];
|
||||
|
||||
// quand un commerce a fermé, on peut supprimer ces tags
|
||||
public $obsolete_tags = ["phone", "website", "email", "description", "brand", "opening_hours",
|
||||
public $obsolete_tags = [
|
||||
"phone", "website", "email", "description", "brand", "opening_hours",
|
||||
"check_date:opening_hours", "internet_access",
|
||||
"indoor_seating", "takeaway", "female", "male", "unisex",
|
||||
"ref:FR:NAF", "ref:FR:FINESS", "ref:FR:SIRET", "ref:FR:SIREN", "ref:vatin",
|
||||
|
@ -52,10 +53,12 @@ class Motocultrice
|
|||
"mobile", "sport", "produce", "lottery", "supermarket", "information",
|
||||
"tourism", "government", "brewery"
|
||||
];
|
||||
public $tags_to_remove = ["diet:", "contact:", "name:", "payment:", "delivery:", "type:FR:", "ref:FR:SDIS:",
|
||||
public $tags_to_remove = [
|
||||
"diet:", "contact:", "name:", "payment:", "delivery:", "type:FR:", "ref:FR:SDIS:",
|
||||
"brand:", "fuel:", "service:", "description:", "operator:", "tickets:", "healthcare:"
|
||||
];
|
||||
public $tags_to_convert = ["shop" => "was:shop",
|
||||
public $tags_to_convert = [
|
||||
"shop" => "was:shop",
|
||||
"information" => "was:information",
|
||||
"office" => "was:office",
|
||||
"amenity" => "was:amenity",
|
||||
|
@ -98,7 +101,7 @@ QUERY;
|
|||
|
||||
public function get_query_places($zone) {
|
||||
return '[out:json][timeout:25];
|
||||
area["postal_code"="'.$zone.'"]->.searchArea;
|
||||
area["ref:INSEE"="'.$zone.'"]->.searchArea;
|
||||
'.$this->overpass_base_places.'
|
||||
out center tags;';
|
||||
}
|
||||
|
@ -150,20 +153,9 @@ out center tags;';
|
|||
|
||||
public function labourer(string $zone): array
|
||||
{
|
||||
|
||||
$use_places_without_email_to_reference = $_ENV['USE_PLACES_WITHOUT_EMAIL_TO_REFERENCE'] ?? false;
|
||||
|
||||
if (!$zone) {
|
||||
throw new \InvalidArgumentException("La zone ne peut pas être vide");
|
||||
}
|
||||
|
||||
// Nettoyer et échapper la zone pour la requête
|
||||
$zone = addslashes(trim($zone));
|
||||
$query = $this->get_query_places($zone);
|
||||
|
||||
try {
|
||||
$response = $this->client->request('POST', $this->overpassApiUrl, [
|
||||
'body' => ['data' => $query]
|
||||
'body' => ['data' => $this->get_query_places($zone)]
|
||||
]);
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
|
@ -174,14 +166,6 @@ out center tags;';
|
|||
if (isset($element['tags'])) {
|
||||
|
||||
$email = "";
|
||||
if( ! $use_places_without_email_to_reference){
|
||||
|
||||
$email = $element['tags']['contact:email'] ?? $element['tags']['email'] ?? null;
|
||||
// On passe si pas d'email
|
||||
if (!$email) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$places[] = [
|
||||
'id' => $element['id'],
|
||||
|
@ -198,9 +182,6 @@ out center tags;';
|
|||
|
||||
return $places;
|
||||
} catch (\Exception $e) {
|
||||
var_dump($query);
|
||||
var_dump($e->getMessage());
|
||||
die();
|
||||
throw new \Exception("Erreur lors de la requête Overpass : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -208,14 +189,14 @@ out center tags;';
|
|||
public function get_city_osm_from_zip_code($zip_code) {
|
||||
// Requête Overpass pour obtenir la zone administrative de niveau 8 avec un nom
|
||||
$query = "[out:json][timeout:25];
|
||||
area[\"postal_code\"=\"{$zip_code}\"]->.searchArea;
|
||||
area[\"ref:INSEE\"=\"{$zip_code}\"]->.searchArea;
|
||||
(
|
||||
relation[\"admin_level\"=\"8\"][\"name\"][\"type\"=\"boundary\"][\"boundary\"=\"administrative\"](area.searchArea);
|
||||
);
|
||||
out body;
|
||||
>;
|
||||
out skel qt;";
|
||||
// $query = "area[\"postal_code\"=\"{$zip_code}\"]->.searchArea;";
|
||||
|
||||
$response = $this->client->request('POST', $this->overpassApiUrl, [
|
||||
'body' => ['data' => $query]
|
||||
]);
|
||||
|
@ -225,14 +206,12 @@ out center tags;';
|
|||
return $city;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public function get_osm_object_data($osm_kind = 'node', $osm_object_id = 12855459190)
|
||||
{
|
||||
$object_id = "https://www.openstreetmap.org/api/0.6/".$osm_kind."/".$osm_object_id;
|
||||
// dump($object_id);
|
||||
// die();
|
||||
|
||||
|
||||
try {
|
||||
$response = $this->client->request('GET', $object_id);
|
||||
|
@ -308,6 +287,7 @@ out center tags;';
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function migrate_tags($osm_object_data) {
|
||||
|
||||
// migrer email vers contact:email
|
||||
|
@ -373,7 +353,7 @@ out center tags;';
|
|||
$essentialTags = [
|
||||
'name',
|
||||
'opening_hours',
|
||||
// 'phone',
|
||||
// 'phone',
|
||||
'contact:email',
|
||||
'contact:phone',
|
||||
'website',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue