addresses: add postcode in address reference load command

This commit is contained in:
nobohan 2021-05-18 07:58:48 +02:00
parent bbb9dc2561
commit 5f8a506c84

View File

@ -51,7 +51,7 @@ class LoadAddressReferenceCommand extends Command
*/ */
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$addressReferenceArray = static::fetchVendeeBAL(); $addressReferenceArray = $this->fetchWFS();
$em = $this->entityManager; $em = $this->entityManager;
foreach($addressReferenceArray as $a) { foreach($addressReferenceArray as $a) {
@ -78,10 +78,11 @@ class LoadAddressReferenceCommand extends Command
* //TODO move this function in App and make the command generic by accepting a fetcher as an argument * //TODO move this function in App and make the command generic by accepting a fetcher as an argument
* @see \Symfony\Component\Console\Command\Command::execute() * @see \Symfony\Component\Console\Command\Command::execute()
*/ */
public static function fetchVendeeBAL(): array private function fetchWFS(): array
{ {
$dataSource = 'Vendée Base d\'adresses locale'; $dataSource = 'BAL GeoVendee';
$countryCode = 'FR';
$addressReferenceArray = array(); $addressReferenceArray = array();
@ -92,35 +93,43 @@ class LoadAddressReferenceCommand extends Command
$jsonContent = json_decode($wfsContent, true); $jsonContent = json_decode($wfsContent, true);
dump($jsonContent);
foreach ($jsonContent['features'] as $key => $value) { foreach ($jsonContent['features'] as $key => $value) {
dump($key);
dump($value);
$a = new AddressReference(); $a = new AddressReference();
$x = $value['geometry']['coordinates'][0]; $x = $value['geometry']['coordinates'][0];
$y = $value['geometry']['coordinates'][1]; //TODO get the coordinates in EPSG:4326 $y = $value['geometry']['coordinates'][1];
$lon = -1.4 + 0.01 * rand(-5, 5); $lon = -1.4 + 0.01 * rand(-5, 5); //TODO temp: get the coordinates in EPSG:4326
$lat = 46.5 + 0.01 * rand(-5, 5); //TODO temp $lat = 46.5 + 0.01 * rand(-5, 5); //TODO temp: get the coordinates in EPSG:4326
$point = Point::fromLonLat($lon, $lat); $point = Point::fromLonLat($lon, $lat);
$em = $this->entityManager;
$country = $em
->getRepository('ChillMainBundle:Country')
->findOneBy(array('countryCode' => $countryCode));
$postcode = $em
->getRepository('ChillMainBundle:PostalCode')
->findOneBy(array('code' => $value['properties']['CODE_POST'], 'country' => $country));
$a->setRefId($value['properties']['OBJECTID']); $a->setRefId($value['properties']['OBJECTID']);
$a->setStreet($value['properties']['NOM_AFNOR']); $a->setStreet($value['properties']['NOM_AFNOR']);
$a->setStreetNumber($value['properties']['NUMERO']); $a->setStreetNumber($value['properties']['NUMERO']);
$a->setPoint($point); $a->setPoint($point);
//$a->setPostcode('1000'); //TODO find postal code from the postal code in $value['properties']['CODE_POST'] //TODO store postcode if not found??? $a->setPostcode($postcode);
$a->setMunicipalityCode($value['properties']['CODE_INSEE']); $a->setMunicipalityCode($value['properties']['CODE_INSEE']);
$a->setSource($dataSource); $a->setSource($dataSource);
$addressReferenceArray[] = $a; $addressReferenceArray[] = $a;
} }
dump($addressReferenceArray);
return $addressReferenceArray; return $addressReferenceArray;
} }
} }