Skip to content

Commit

Permalink
Import co-ordinates from _PLAC records
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed Aug 8, 2020
1 parent 42516cd commit f96f510
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion app/Functions/FunctionsImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static function importRecord(string $gedrec, Tree $tree, bool $update): v
if ($tree->getPreference('GENERATE_UIDS') === '1' && !str_contains($gedrec, "\n1 _UID ")) {
$gedrec .= "\n1 _UID " . GedcomTag::createUid();
}
} elseif (preg_match('/0 (HEAD|TRLR|_PLAC_DEFN)/', $gedrec, $match)) {
} elseif (preg_match('/0 (HEAD|TRLR|_PLAC |_PLAC_DEFN)/', $gedrec, $match)) {
$type = $match[1];
$xref = $type; // For records without an XREF, use the type as a pseudo XREF.
} else {
Expand Down Expand Up @@ -429,6 +429,10 @@ public static function importRecord(string $gedrec, Tree $tree, bool $update): v
}
break;

case '_PLAC ':
self::importTNGPlac($gedrec);
return;

case '_PLAC_DEFN':
self::importLegacyPlacDefn($gedrec);
return;
Expand Down Expand Up @@ -486,6 +490,45 @@ private static function importLegacyPlacDefn(string $gedcom): void
}
}

/**
* Legacy Family Tree software generates _PLAC_DEFN records containing LAT/LONG values
*
* @param string $gedcom
*/
private static function importTNGPlac(string $gedcom): void
{
$gedcom_service = new GedcomService();

if (preg_match('/^0 _PLAC (.+)/', $gedcom, $match)) {
$place_name = $match[1];
} else {
return;
}

if (preg_match('/\n2 LATI (.+)/', $gedcom, $match)) {
$latitude = (float) $match[1];
} else {
return;
}

if (preg_match('/\n2 LONG (.+)/', $gedcom, $match)) {
$longitude = (float) $match[1];
} else {
return;
}

$location = new PlaceLocation($place_name);

if ($location->latitude() === 0.0 && $location->longitude() === 0.0) {
DB::table('placelocation')
->where('pl_id', '=', $location->id())
->update([
'pl_lati' => $latitude,
'pl_long' => $longitude,
]);
}
}

/**
* Extract all level 2 places from the given record and insert them into the places table
*
Expand Down

0 comments on commit f96f510

Please sign in to comment.