Skip to content

Commit

Permalink
coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu committed Dec 26, 2024
1 parent b805908 commit 2792588
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions app/Services/Wikidata/WikidataImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services\Wikidata;

use App\Dto\Coordinate;
use App\Dto\Wikidata\WikidataEntity;
use App\Exceptions\Wikidata\FetchException;
use App\Models\Station;
Expand Down Expand Up @@ -39,16 +40,14 @@ public static function importStation(string $qId): Station {
throw new \InvalidArgumentException('No name found for entity ' . $qId);
}

$coordinates = $wikidataEntity->getClaims('P625')[0]['mainsnak']['datavalue']['value'] ?? null; //P625 = coordinate location
$coordinates = self::getCoordinates($wikidataEntity);
if ($coordinates === null) {
throw new \InvalidArgumentException('No coordinates found for entity ' . $qId);
}

$latitude = $coordinates['latitude'];
$longitude = $coordinates['longitude'];
$ibnr = $wikidataEntity->getClaims('P954')[0]['mainsnak']['datavalue']['value'] ?? null; //P954 = IBNR
$rl100 = $wikidataEntity->getClaims('P8671')[0]['mainsnak']['datavalue']['value'] ?? null; //P8671 = RL100
$ifopt = $wikidataEntity->getClaims('P12393')[0]['mainsnak']['datavalue']['value'] ?? null; //P12393 = IFOPT
$ibnr = $wikidataEntity->getClaims('P954')[0]['mainsnak']['datavalue']['value'] ?? null; //P954 = IBNR
$rl100 = $wikidataEntity->getClaims('P8671')[0]['mainsnak']['datavalue']['value'] ?? null; //P8671 = RL100
$ifopt = $wikidataEntity->getClaims('P12393')[0]['mainsnak']['datavalue']['value'] ?? null; //P12393 = IFOPT
if ($ifopt !== null) {
$splittedIfopt = explode(':', $ifopt);
}
Expand All @@ -61,8 +60,8 @@ public static function importStation(string $qId): Station {
return Station::create(
[
'name' => $name,
'latitude' => $latitude,
'longitude' => $longitude,
'latitude' => $coordinates->latitude,
'longitude' => $coordinates->longitude,
'wikidata_id' => $qId,
'rilIdentifier' => $rl100,
'ibnr' => $ibnr,
Expand Down Expand Up @@ -142,4 +141,12 @@ public static function isTypeSupported(WikidataEntity $entity): bool {
return false;
}

public static function getCoordinates(WikidataEntity $entity): ?Coordinate {
$coordinates = $entity->getClaims('P625')[0]['mainsnak']['datavalue']['value'] ?? null; //P625 = coordinate location
if ($coordinates === null) {
return null;
}
return new Coordinate($coordinates['latitude'], $coordinates['longitude']);
}

}

0 comments on commit 2792588

Please sign in to comment.