|
|
@ -3,6 +3,8 @@ |
|
|
|
namespace App\Controller; |
|
|
|
|
|
|
|
use App\Form\CityToolType; |
|
|
|
use App\Form\OsmoseToolType; |
|
|
|
use App\Service\OsmoseClient; |
|
|
|
use App\Service\OverpassClient; |
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
|
|
@ -89,4 +91,123 @@ class ToolsController extends AbstractController |
|
|
|
'form' => $form, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
#[Route('/osmose', name: 'app_tools_osmose')]
|
|
|
|
public function osmose( |
|
|
|
Request $request, |
|
|
|
OsmoseClient $osmose, |
|
|
|
): Response { |
|
|
|
$form = $this->createForm(OsmoseToolType::class, $request->query->all()); |
|
|
|
$form->add('submit', SubmitType::class, ['label' => 'Générer']); |
|
|
|
|
|
|
|
$form->handleRequest($request); |
|
|
|
if ($form->isSubmitted() and $form->isValid()) { |
|
|
|
$issues = $osmose->issues([ |
|
|
|
'item' => $form->get('item')->getData(), |
|
|
|
'source' => $form->get('source')->getData(), |
|
|
|
'class' => $form->get('class')->getData(), |
|
|
|
'username' => '', |
|
|
|
'bbox' => '', |
|
|
|
'full' => 'true', |
|
|
|
'limit' => 500, |
|
|
|
]); |
|
|
|
|
|
|
|
$response = new StreamedResponse(); |
|
|
|
|
|
|
|
$response->headers->set('Content-Type', 'text/csv'); |
|
|
|
$response->headers->set( |
|
|
|
'Content-Disposition', |
|
|
|
HeaderUtils::makeDisposition( |
|
|
|
HeaderUtils::DISPOSITION_ATTACHMENT, |
|
|
|
'issues.csv' |
|
|
|
) |
|
|
|
); |
|
|
|
|
|
|
|
$features = json_decode($issues, true)['features']; |
|
|
|
|
|
|
|
$response->setCallback(function () use ($features): void { |
|
|
|
$headings = [ |
|
|
|
'name', |
|
|
|
'description', |
|
|
|
'osm', |
|
|
|
'geojson', |
|
|
|
'status', |
|
|
|
]; |
|
|
|
|
|
|
|
$csv = fopen('php://output', 'a'); |
|
|
|
|
|
|
|
fputcsv($csv, $headings); |
|
|
|
|
|
|
|
$total = count($features); |
|
|
|
foreach ($features as $index => $feature) { |
|
|
|
$name = sprintf('%s n°%d/%d', $feature['properties']['title'], $index + 1, $total); |
|
|
|
$description = <<<EOT |
|
|
|
### Issue {$feature['properties']['uuid']}
|
|
|
|
|
|
|
|
* Level {$feature['properties']['level']} |
|
|
|
* Item {$feature['properties']['item']} |
|
|
|
* Identifiant de source {$feature['properties']['source_id']} |
|
|
|
* Identifiant de classe {$feature['properties']['class']} |
|
|
|
|
|
|
|
### Osmose
|
|
|
|
|
|
|
|
[✔ Fait](https://osmose.openstreetmap.fr/api/0.3/issue/{$feature['properties']['uuid']}/done) |
|
|
|
[✘ Faux positif](https://osmose.openstreetmap.fr/api/0.3/issue/{$feature['properties']['uuid']}/false) |
|
|
|
EOT; |
|
|
|
if (isset($feature['properties']['fixes'])) { |
|
|
|
$tags = []; |
|
|
|
foreach ($feature['properties']['fixes'] as $fixItems) { |
|
|
|
foreach ($fixItems as $fixItem) { |
|
|
|
$isExpected = ( |
|
|
|
('N' === $fixItem['type']) |
|
|
|
and array_key_exists('create', $fixItem) |
|
|
|
); |
|
|
|
if (!$isExpected) { |
|
|
|
continue; |
|
|
|
} // TODO gérer tous les cas possibles ici
|
|
|
|
foreach ($fixItem['create'] as $k => $v) { |
|
|
|
$tags[$k] = $v; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$osm = \OSM\OSM::createFromArray([ |
|
|
|
'elements' => [[ |
|
|
|
'type' => 'node', |
|
|
|
'id' => -1, |
|
|
|
'lat' => (float) $feature['geometry']['coordinates'][1], |
|
|
|
'lon' => (float) $feature['geometry']['coordinates'][0], |
|
|
|
'tags' => $tags, |
|
|
|
]], |
|
|
|
]); |
|
|
|
} else { |
|
|
|
$osm = ''; |
|
|
|
} |
|
|
|
|
|
|
|
$geojson = json_encode([ |
|
|
|
'type' => 'FeatureCollection', |
|
|
|
'features' => [ |
|
|
|
$feature, |
|
|
|
], |
|
|
|
]); |
|
|
|
|
|
|
|
fputcsv($csv, [ |
|
|
|
$name, |
|
|
|
$description, |
|
|
|
$osm, |
|
|
|
$geojson, |
|
|
|
'todo', |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
fclose($csv); |
|
|
|
}); |
|
|
|
|
|
|
|
return $response; |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('tools/osmose.html.twig', [ |
|
|
|
'form' => $form, |
|
|
|
]); |
|
|
|
} |
|
|
|
} |