Пример #1
0
 private function GetElevation()
 {
     //Determine which lines are most probable to have an Elevation.
     //NOTE:  Still doesn't capture maximum elevation.
     //global $this->Label;
     $PregWords1 = "([\\d,]{2,5})";
     $PregWords2 = "(\\b(meters|m.|m|feet|ft.|ft|msnm)\\b)";
     $PregWords3 = "(\\b(elevation|elev|altitude|alt)\\b)";
     $RankArray = array();
     $match = array();
     $Start = 0;
     $End = 0;
     for ($L = 0; $L < count($this->LabelArray); $L++) {
         $RankArray[$L] = 0;
         if ($this->LineStart[$L] == 'minimumElevationInMeters') {
             $RankArray[$L] += 100;
         }
         //Adjust for some possible confusing lines
         if ($this->LineStart[$L] == 'recordedBy') {
             $RankArray[$L] -= 100;
         }
         //elevation won't be here
         if ($this->LineStart[$L] == 'locality') {
             $RankArray[$L] += 10;
         }
         //Often in this line
         if ($this->LineStart[$L] == 'habitat') {
             $RankArray[$L] += 5;
         }
         //Sometimes in this line
         //Look for the PregWords and adjust rank.
         $Found = preg_match_all($PregWords1, $this->LabelLines[$L], $match);
         if ($Found > 0) {
             $RankArray[$L] += 5;
         }
         $Found = 10 * preg_match_all($PregWords2, $this->LabelLines[$L], $match);
         $Found = 20 * preg_match_all($PregWords2, $this->LabelLines[$L], $match);
         $RankArray[$L] += $Found;
         if (preg_match("([0-9,]{2,6})", $this->LabelLines[$L]) != 1) {
             $RankArray[$L] -= 100;
         }
         //There must be an appropriate numeric entry somewhere for elevation
     }
     //Sort the lines in rank order
     asort($RankArray);
     $RankArray = array_reverse($RankArray, true);
     //$this->PrintRank($RankArray,"Elev");
     //Now have an array of probable lines sorted most probable first.
     //ScoreArray will be filled with possible elevations and a score for each.
     $ScoreArray = array();
     foreach ($RankArray as $L => $Value) {
         //Iterate through the lines from most to least likely, cutting off if value gets below a threshold.
         //echo "Testing $L, $Value: {$this->LabelLines[$L]}<br>";
         if ($Value < 5) {
             break;
         }
         $TempString = $this->LabelLines[$L];
         //$Found = preg_match("(([a|A]lt|[e|E]lev)[\S]*[\s]*[about ]*([0-9,-]+)([\s]*)(m(eter)?s?\b|f(ee)?t?\b|\'))",$TempString,$match);
         $Found = preg_match("(([a|A]lt|[e|E]lev)[\\S]*[\\s]*[about ]*([0-9, -]+)\\s?\\d?([\\s]*)(m(eter|snm)?s?\\b|f(ee)?t?\\b|\\'))i", $TempString, $match);
         if ($Found === 1) {
             //$this->printr($match,"Elev match 1");
             $ScoreArray[$match[0]] = $Value + 10;
             if (max($ScoreArray) == $Value + 10) {
                 $FoundElev = $match[2];
             }
         }
         if ($Found !== 1) {
             $Found = preg_match("((ca\\.?\\s)?([0-9,]+)([ ]*)(m(eter|snm)?s?\\b|f(ee)?t?\\b|\\')[\\S]*[\\s]*([a|A]lt|[e|E]lev)[ation]?[\\S]*)", $TempString, $match);
             if ($Found === 1) {
                 //$this->printr($match,"Elev match 2");
                 $ScoreArray[$match[0]] = $Value + 10;
                 if (max($ScoreArray) == $Value + 10) {
                     $FoundElev = $match[1];
                 }
             }
         }
         if ($Found !== 1) {
             $Found = preg_match("(\\A(ca\\.?\\s)?([0-9,]+)([ ]*)(m(eter|snm)?s?\\b|f(ee)?t?\\b|\\'))", $TempString, $match);
             if ($Found === 1) {
                 //$this->printr($match,"Elev match 3");
                 $Score = $Value + 2;
                 if ($match[1] > 1000 && $match[1] < 12000) {
                     $Score += 2;
                 }
                 //Increase score if altitude in reasonable range
                 $ScoreArray[$match[0]] = $Score;
                 if (max($ScoreArray) == $Score) {
                     $FoundElev = $match[1];
                 }
             }
         }
         if ($Found !== 1) {
             //Least certain, just a number followed by feet or meters in middle of a line.  Could be height, distance, etc.
             $Found = preg_match_all("((ca\\.?\\s)?\\b([0-9,]+)(\\s?)(m(eter|snm)?s?\\b|f(ee)?t?\\b|\\'))", $TempString, $match);
             if ($Found > 0) {
                 //$this->printr($match,"Elev Match 4");
                 $Score = $Value;
                 $Elev = $match[0][0];
                 if ($Found > 1 && strpos($match[0][1], "m") > 1) {
                     $Elev = $match[0][1];
                 }
                 if ($Elev > 1000 && $Elev < 12000) {
                     $Score += 2;
                 }
                 //Increase score if altitude in reasonable range
                 $ScoreArray[$Elev] = $Score;
                 if (max($ScoreArray) == $Score) {
                     $FoundElev = $Elev;
                 }
             }
         }
     }
     //All potential altitudes are found and in $ScoreArray.  Now sort by most likely and accept the top one.
     if (count($ScoreArray) == 0) {
         return;
     }
     asort($ScoreArray);
     end($ScoreArray);
     //Select the last (highest) element in the scores array
     //$this->printr($ScoreArray,"ScoreArray");
     $TempString = key($ScoreArray);
     //Should be the best line.
     for ($L = 0; $L < count($this->LabelLines); $L++) {
         if (strpos($this->LabelLines[$L], $TempString) !== false) {
             //$L = array_search($TempString, $this->LabelLines);
             $TempString = $this->RemoveStartWordsFromString($TempString, 'minimumElevationInMeters');
             break;
         }
     }
     if ($L >= 0 && $L < count($this->LabelLines)) {
         $this->LabelLines[$L] = $this->RemoveStartWordsFromString($this->LabelLines[$L], 'minimumElevationInMeters');
         //echo "To this: {$this->LabelLines[$L]}<br>";
     }
     $Preg = "(\\d+[a to-]+{$TempString})";
     $Found = preg_match($Preg, $this->Label, $match);
     if ($Found > 0) {
         $TempString = $match[0];
         $TempString = str_replace("to", "-", $TempString);
     }
     $this->AddToResults('verbatimElevation', $TempString, $L);
     $Found = false;
     for ($L = 0; $L < count($this->LabelLines) && !$Found; $L++) {
         if (strpos($this->LabelLines[$L], $TempString) !== false) {
             $this->LabelLines[$L] = str_replace($TempString, "", $this->LabelLines[$L]);
             $Found = true;
         }
     }
     //Replace Spanish "a" with a hyphen
     $TempString = preg_replace("((\\d\\s?)(a)(\\s?\\d))", "\$1-\$3", $TempString);
     //Remove comma from thousands place for simpler calculations
     $TempString = preg_replace("(([0-9]),([0-9]))", "\\1\\2", $TempString);
     $TempString = trim(str_ireplace(array("altitude", "elevation", "about", "ca"), "", $TempString));
     //echo "Tempstring = $TempString<br>";
     //$TempString = "1000 - 1200 m";
     $OU = new OccurrenceUtilities();
     $El = $OU->parseVerbatimElevation($TempString);
     $Found = false;
     //$this->printr($El,"El");
     if (isset($El['minelev'])) {
         //$this->printr($El,"El Return");
         $Alt = $El['minelev'];
         if ($Alt >= 0 && $Alt < 5000) {
             $this->AddToResults('minimumElevationInMeters', $Alt, $L);
             $Found = true;
             if (isset($El['maxelev'])) {
                 $this->AddToResults('maximumElevationInMeters', $El['maxelev'], $L);
             }
         }
     }
     if ($Found) {
         return;
     }
 }
Пример #2
0
 protected function loadRecord($recMap)
 {
     //Only import record if at least one of the minimal fields have data
     if (array_key_exists('dbpk', $recMap) && $recMap['dbpk'] || array_key_exists('catalognumber', $recMap) && $recMap['catalognumber'] || array_key_exists('recordedby', $recMap) && $recMap['recordedby'] || array_key_exists('eventdate', $recMap) && $recMap['eventdate'] || array_key_exists('locality', $recMap) && $recMap['locality'] || array_key_exists('sciname', $recMap) && $recMap['sciname'] || array_key_exists('scientificname', $recMap) && $recMap['scientificname']) {
         //Trim all field values
         foreach ($recMap as $k => $v) {
             $recMap[$k] = trim($v);
         }
         //Remove institution and collection codes when they match what is in omcollections
         if (array_key_exists('institutioncode', $recMap) && $recMap['institutioncode'] == $this->collMetadataArr["institutioncode"]) {
             unset($recMap['institutioncode']);
         }
         if (array_key_exists('collectioncode', $recMap) && $recMap['collectioncode'] == $this->collMetadataArr["collectioncode"]) {
             unset($recMap['collectioncode']);
         }
         //Date cleaning
         if (array_key_exists('eventdate', $recMap) && $recMap['eventdate']) {
             if (is_numeric($recMap['eventdate'])) {
                 if ($recMap['eventdate'] > 2100 && $recMap['eventdate'] < 45000) {
                     //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
                     $recMap['eventdate'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['eventdate'] - 1, 1900));
                 } elseif ($recMap['eventdate'] > 2200000 && $recMap['eventdate'] < 2500000) {
                     //Date is in the Gregorian format
                     $dArr = explode('/', jdtogregorian($recMap['eventdate']));
                     $recMap['eventdate'] = $dArr[2] . '-' . $dArr[0] . '-' . $dArr[1];
                 } elseif ($recMap['eventdate'] > 19000000) {
                     //Format: 20120101 = 2012-01-01
                     $recMap['eventdate'] = substr($recMap['eventdate'], 0, 4) . '-' . substr($recMap['eventdate'], 4, 2) . '-' . substr($recMap['eventdate'], 6, 2);
                 }
             } else {
                 //Make sure event date is a valid format or drop into verbatimEventDate
                 $dateStr = OccurrenceUtilities::formatDate($recMap['eventdate']);
                 if ($dateStr) {
                     //if(strpos('-00',$dateStr)) $this->outputMsg($recMap['eventdate'].' => '.$dateStr."<br/>");
                     if ($recMap['eventdate'] != $dateStr && (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate'])) {
                         $recMap['verbatimeventdate'] = $recMap['eventdate'];
                     }
                     $recMap['eventdate'] = $dateStr;
                 } else {
                     if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                         $recMap['verbatimeventdate'] = $recMap['eventdate'];
                     }
                     unset($recMap['eventdate']);
                 }
             }
         }
         if (array_key_exists('latestdatecollected', $recMap) && $recMap['latestdatecollected'] && is_numeric($recMap['latestdatecollected'])) {
             if ($recMap['latestdatecollected'] > 2100 && $recMap['latestdatecollected'] < 45000) {
                 //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
                 $recMap['latestdatecollected'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['latestdatecollected'] - 1, 1900));
             } elseif ($recMap['latestdatecollected'] > 2200000 && $recMap['latestdatecollected'] < 2500000) {
                 $dArr = explode('/', jdtogregorian($recMap['latestdatecollected']));
                 $recMap['latestdatecollected'] = $dArr[2] . '-' . $dArr[0] . '-' . $dArr[1];
             } elseif ($recMap['latestdatecollected'] > 19000000) {
                 $recMap['latestdatecollected'] = substr($recMap['latestdatecollected'], 0, 4) . '-' . substr($recMap['latestdatecollected'], 4, 2) . '-' . substr($recMap['latestdatecollected'], 6, 2);
             }
         }
         if (array_key_exists('verbatimeventdate', $recMap) && $recMap['verbatimeventdate'] && is_numeric($recMap['verbatimeventdate']) && $recMap['verbatimeventdate'] > 2100 && $recMap['verbatimeventdate'] < 45000) {
             //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
             $recMap['verbatimeventdate'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['verbatimeventdate'] - 1, 1900));
         }
         if (array_key_exists('dateidentified', $recMap) && $recMap['dateidentified'] && is_numeric($recMap['dateidentified']) && $recMap['dateidentified'] > 2100 && $recMap['dateidentified'] < 45000) {
             //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
             $recMap['dateidentified'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['dateidentified'] - 1, 1900));
         }
         //If month, day, or year are text, avoid SQL error by converting to numeric value
         if (array_key_exists('year', $recMap) || array_key_exists('month', $recMap) || array_key_exists('day', $recMap)) {
             $y = array_key_exists('year', $recMap) ? $recMap['year'] : '00';
             $m = array_key_exists('month', $recMap) ? $recMap['month'] : '00';
             $d = array_key_exists('day', $recMap) ? $recMap['day'] : '00';
             $vDate = trim($y . '-' . $m . '-' . $d, '- ');
             if (isset($recMap['day']) && !is_numeric($recMap['day'])) {
                 if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                     $recMap['verbatimeventdate'] = $vDate;
                 }
                 unset($recMap['day']);
                 $d = '00';
             }
             if (isset($recMap['year']) && !is_numeric($recMap['year'])) {
                 if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                     $recMap['verbatimeventdate'] = $vDate;
                 }
                 unset($recMap['year']);
             }
             if (isset($recMap['month']) && $recMap['month'] && !is_numeric($recMap['month'])) {
                 if (strlen($recMap['month']) > 2) {
                     $monAbbr = strtolower(substr($recMap['month'], 0, 3));
                     if (array_key_exists($monAbbr, OccurrenceUtilities::$monthNames)) {
                         $recMap['month'] = OccurrenceUtilities::$monthNames[$monAbbr];
                         $recMap['eventdate'] = OccurrenceUtilities::formatDate(trim($y . '-' . $recMap['month'] . '-' . ($d ? $d : '00'), '- '));
                     } else {
                         if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                             $recMap['verbatimeventdate'] = $vDate;
                         }
                         unset($recMap['month']);
                     }
                 } else {
                     if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                         $recMap['verbatimeventdate'] = $vDate;
                     }
                     unset($recMap['month']);
                 }
             }
             if ($vDate && (!array_key_exists('eventdate', $recMap) || !$recMap['eventdate'])) {
                 $recMap['eventdate'] = OccurrenceUtilities::formatDate($vDate);
             }
         }
         //eventDate NULL && verbatimEventDate NOT NULL && year NOT NULL
         if ((!array_key_exists('eventdate', $recMap) || !$recMap['eventdate']) && array_key_exists('verbatimeventdate', $recMap) && $recMap['verbatimeventdate'] && (!array_key_exists('year', $recMap) || !$recMap['year'])) {
             $dateStr = OccurrenceUtilities::formatDate($recMap['verbatimeventdate']);
             if ($dateStr) {
                 $recMap['eventdate'] = $dateStr;
             }
         }
         if (isset($recMap['recordnumberprefix']) && $recMap['recordnumberprefix'] || isset($recMap['recordnumbersuffix']) && $recMap['recordnumbersuffix']) {
             $recNumber = $recMap['recordnumber'];
             if (isset($recMap['recordnumberprefix']) && $recMap['recordnumberprefix']) {
                 $recNumber = $recMap['recordnumberprefix'] . '-' . $recNumber;
             }
             if (isset($recMap['recordnumbersuffix']) && $recMap['recordnumbersuffix']) {
                 if (is_numeric($recMap['recordnumbersuffix']) && $recMap['recordnumber']) {
                     $recNumber .= '-';
                 }
                 $recNumber .= $recMap['recordnumbersuffix'];
             }
             $recMap['recordnumber'] = $recNumber;
         }
         //If lat or long are not numeric, try to make them so
         if (array_key_exists('decimallatitude', $recMap) || array_key_exists('decimallongitude', $recMap)) {
             $latValue = array_key_exists('decimallatitude', $recMap) ? $recMap['decimallatitude'] : '';
             $lngValue = array_key_exists('decimallongitude', $recMap) ? $recMap['decimallongitude'] : '';
             if ($latValue && !is_numeric($latValue) || $lngValue && !is_numeric($lngValue)) {
                 $llArr = OccurrenceUtilities::parseVerbatimCoordinates(trim($latValue . ' ' . $lngValue), 'LL');
                 if (array_key_exists('lat', $llArr) && array_key_exists('lng', $llArr)) {
                     $recMap['decimallatitude'] = $llArr['lat'];
                     $recMap['decimallongitude'] = $llArr['lng'];
                 } else {
                     unset($recMap['decimallatitude']);
                     unset($recMap['decimallongitude']);
                 }
                 $vcStr = '';
                 if (array_key_exists('verbatimcoordinates', $recMap) && $recMap['verbatimcoordinates']) {
                     $vcStr .= $recMap['verbatimcoordinates'] . '; ';
                 }
                 $vcStr .= $latValue . ' ' . $lngValue;
                 if (trim($vcStr)) {
                     $recMap['verbatimcoordinates'] = trim($vcStr);
                 }
             }
         }
         if (array_key_exists('verbatimcoordinates', $recMap) && $recMap['verbatimcoordinates'] && (!isset($recMap['decimallatitude']) || !$recMap['decimallatitude'])) {
             $coordArr = OccurrenceUtilities::parseVerbatimCoordinates($recMap['verbatimcoordinates']);
             if ($coordArr) {
                 if (array_key_exists('lat', $coordArr)) {
                     $recMap['decimallatitude'] = $coordArr['lat'];
                 }
                 if (array_key_exists('lng', $coordArr)) {
                     $recMap['decimallongitude'] = $coordArr['lng'];
                 }
             }
         }
         //Convert UTM to Lat/Long
         if (array_key_exists('utmnorthing', $recMap) && $recMap['utmnorthing'] || array_key_exists('utmeasting', $recMap) && $recMap['utmeasting']) {
             $no = array_key_exists('utmnorthing', $recMap) ? $recMap['utmnorthing'] : '';
             $ea = array_key_exists('utmeasting', $recMap) ? $recMap['utmeasting'] : '';
             $zo = array_key_exists('utmzoning', $recMap) ? $recMap['utmzoning'] : '';
             $da = array_key_exists('geodeticdatum', $recMap) ? $recMap['geodeticdatum'] : '';
             if (!array_key_exists('decimallatitude', $recMap) || !$recMap['decimallatitude']) {
                 if ($no && $ea && $zo) {
                     //Northing, easting, and zoning all had values
                     $llArr = OccurrenceUtilities::convertUtmToLL($ea, $no, $zo, $da);
                     if (isset($llArr['lat'])) {
                         $recMap['decimallatitude'] = $llArr['lat'];
                     }
                     if (isset($llArr['lng'])) {
                         $recMap['decimallongitude'] = $llArr['lng'];
                     }
                 } else {
                     //UTM was a single field which was placed in UTM northing field within uploadspectemp table
                     $coordArr = OccurrenceUtilities::parseVerbatimCoordinates(trim($zo . ' ' . $ea . ' ' . $no), 'UTM');
                     if ($coordArr) {
                         if (array_key_exists('lat', $coordArr)) {
                             $recMap['decimallatitude'] = $coordArr['lat'];
                         }
                         if (array_key_exists('lng', $coordArr)) {
                             $recMap['decimallongitude'] = $coordArr['lng'];
                         }
                     }
                 }
             }
             $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
             if (!($no && strpos($vCoord, $no))) {
                 $recMap['verbatimcoordinates'] = ($vCoord ? $vCoord . '; ' : '') . $zo . ' ' . $ea . 'E ' . $no . 'N';
             }
         }
         //Transfer verbatim Lat/Long to verbatim coords
         if (isset($recMap['verbatimlatitude']) && $recMap['verbatimlatitude'] || isset($recMap['verbatimlongitude']) && $recMap['verbatimlongitude']) {
             //Attempt to extract decimal lat/long
             if (!array_key_exists('decimallatitude', $recMap) || !$recMap['decimallatitude']) {
                 $coordArr = OccurrenceUtilities::parseVerbatimCoordinates($recMap['verbatimlatitude'] . ' ' . $recMap['verbatimlongitude'], 'LL');
                 if ($coordArr) {
                     if (array_key_exists('lat', $coordArr)) {
                         $recMap['decimallatitude'] = $coordArr['lat'];
                     }
                     if (array_key_exists('lng', $coordArr)) {
                         $recMap['decimallongitude'] = $coordArr['lng'];
                     }
                 }
             }
             //Place into verbatim coord field
             $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
             if ($vCoord) {
                 $vCoord .= '; ';
             }
             if (stripos($vCoord, $recMap['verbatimlatitude']) === false && stripos($vCoord, $recMap['verbatimlongitude']) === false) {
                 $recMap['verbatimcoordinates'] = $vCoord . $recMap['verbatimlatitude'] . ', ' . $recMap['verbatimlongitude'];
             }
         }
         //Transfer DMS to verbatim coords
         if (isset($recMap['latdeg']) && $recMap['latdeg'] && isset($recMap['lngdeg']) && $recMap['lngdeg']) {
             //Attempt to create decimal lat/long
             if (is_numeric($recMap['latdeg']) && is_numeric($recMap['lngdeg']) && (!isset($recMap['decimallatitude']) || !$recMap['decimallatitude']) && (!isset($recMap['decimallongitude']) || !$recMap['decimallongitude'])) {
                 $latDec = $recMap['latdeg'];
                 if (isset($recMap['latmin']) && $recMap['latmin'] && is_numeric($recMap['latmin'])) {
                     $latDec += $recMap['latmin'] / 60;
                 }
                 if (isset($recMap['latsec']) && $recMap['latsec'] && is_numeric($recMap['latsec'])) {
                     $latDec += $recMap['latsec'] / 3600;
                 }
                 if (stripos($recMap['latns'], 's') === 0 && $latDec > 0) {
                     $latDec *= -1;
                 }
                 $lngDec = $recMap['lngdeg'];
                 if (isset($recMap['lngmin']) && $recMap['lngmin'] && is_numeric($recMap['lngmin'])) {
                     $lngDec += $recMap['lngmin'] / 60;
                 }
                 if (isset($recMap['lngsec']) && $recMap['lngsec'] && is_numeric($recMap['lngsec'])) {
                     $lngDec += $recMap['lngsec'] / 3600;
                 }
                 if (stripos($recMap['lngew'], 'e') === 0) {
                     $lngDec *= -1;
                 }
                 $recMap['decimallatitude'] = round($latDec, 6);
                 $recMap['decimallongitude'] = round($lngDec, 6);
             }
             //Place into verbatim coord field
             $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
             if ($vCoord) {
                 $vCoord .= '; ';
             }
             $vCoord .= $recMap['latdeg'] . '° ';
             if (isset($recMap['latmin']) && $recMap['latmin']) {
                 $vCoord .= $recMap['latmin'] . 'm ';
             }
             if (isset($recMap['latsec']) && $recMap['latsec']) {
                 $vCoord .= $recMap['latsec'] . 's ';
             }
             if (isset($recMap['latns'])) {
                 $vCoord .= $recMap['latns'] . '; ';
             }
             $vCoord .= $recMap['lngdeg'] . '° ';
             if (isset($recMap['lngmin']) && $recMap['lngmin']) {
                 $vCoord .= $recMap['lngmin'] . 'm ';
             }
             if (isset($recMap['lngsec']) && $recMap['lngsec']) {
                 $vCoord .= $recMap['lngsec'] . 's ';
             }
             if (isset($recMap['lngew'])) {
                 $vCoord .= $recMap['lngew'];
             }
             $recMap['verbatimcoordinates'] = $vCoord;
         }
         //Transfer TRS to verbatim coords
         if (isset($recMap['trstownship']) && $recMap['trstownship'] && isset($recMap['trsrange']) && $recMap['trsrange']) {
             $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
             if ($vCoord) {
                 $vCoord .= '; ';
             }
             $vCoord .= (stripos($recMap['trstownship'], 't') === false ? 'T' : '') . $recMap['trstownship'] . ' ';
             $vCoord .= (stripos($recMap['trsrange'], 'r') === false ? 'R' : '') . $recMap['trsrange'] . ' ';
             if (isset($recMap['trssection'])) {
                 $vCoord .= (stripos($recMap['trssection'], 's') === false ? 'sec' : '') . $recMap['trssection'] . ' ';
             }
             if (isset($recMap['trssectiondetails'])) {
                 $vCoord .= $recMap['trssectiondetails'];
             }
             $recMap['verbatimcoordinates'] = trim($vCoord);
         }
         //Check to see if evelation are valid numeric values
         if (isset($recMap['minimumelevationinmeters']) && $recMap['minimumelevationinmeters'] && !is_numeric($recMap['minimumelevationinmeters']) || isset($recMap['maximumelevationinmeters']) && $recMap['maximumelevationinmeters'] && !is_numeric($recMap['maximumelevationinmeters'])) {
             $vStr = isset($recMap['verbatimelevation']) ? $recMap['verbatimelevation'] : '';
             if (isset($recMap['minimumelevationinmeters']) && $recMap['minimumelevationinmeters']) {
                 $vStr .= ($vStr ? '; ' : '') . $recMap['minimumelevationinmeters'];
             }
             if (isset($recMap['maximumelevationinmeters']) && $recMap['maximumelevationinmeters']) {
                 $vStr .= '-' . $recMap['maximumelevationinmeters'];
             }
             $recMap['verbatimelevation'] = $vStr;
             $recMap['minimumelevationinmeters'] = '';
             $recMap['maximumelevationinmeters'] = '';
         }
         //Verbatim elevation
         if (array_key_exists('verbatimelevation', $recMap) && $recMap['verbatimelevation'] && (!array_key_exists('minimumelevationinmeters', $recMap) || !$recMap['minimumelevationinmeters'])) {
             $eArr = OccurrenceUtilities::parseVerbatimElevation($recMap['verbatimelevation']);
             if ($eArr) {
                 if (array_key_exists('minelev', $eArr)) {
                     $recMap['minimumelevationinmeters'] = $eArr['minelev'];
                     if (array_key_exists('maxelev', $eArr)) {
                         $recMap['maximumelevationinmeters'] = $eArr['maxelev'];
                     }
                 }
             }
         }
         //Deal with elevation when in two fields (number and units)
         if (isset($recMap['elevationnumber']) && $recMap['elevationnumber']) {
             $elevStr = $recMap['elevationnumber'] . $recMap['elevationunits'];
             //Try to extract meters
             $eArr = OccurrenceUtilities::parseVerbatimElevation($elevStr);
             if ($eArr) {
                 if (array_key_exists('minelev', $eArr)) {
                     $recMap['minimumelevationinmeters'] = $eArr['minelev'];
                     if (array_key_exists('maxelev', $eArr)) {
                         $recMap['maximumelevationinmeters'] = $eArr['maxelev'];
                     }
                 }
             }
             if (!$eArr || !stripos($elevStr, 'm')) {
                 $vElev = isset($recMap['verbatimelevation']) ? $recMap['verbatimelevation'] : '';
                 if ($vElev) {
                     $vElev .= '; ';
                 }
                 $recMap['verbatimelevation'] = $vElev . $elevStr;
             }
         }
         //Concatinate collectorfamilyname and collectorinitials into recordedby
         if (isset($recMap['collectorfamilyname']) && $recMap['collectorfamilyname'] && (!isset($recMap['recordedby']) || !$recMap['recordedby'])) {
             $recordedBy = $recMap['collectorfamilyname'];
             if (isset($recMap['collectorinitials']) && $recMap['collectorinitials']) {
                 $recordedBy .= ', ' . $recMap['collectorinitials'];
             }
             $recMap['recordedby'] = $recordedBy;
             //Need to add code that maps to collector table
         }
         if (array_key_exists("specificepithet", $recMap)) {
             if ($recMap["specificepithet"] == 'sp.' || $recMap["specificepithet"] == 'sp') {
                 $recMap["specificepithet"] = '';
             }
         }
         if (array_key_exists("taxonrank", $recMap)) {
             $tr = strtolower($recMap["taxonrank"]);
             if ($tr == 'species' || !$recMap["specificepithet"]) {
                 $recMap["taxonrank"] = '';
             }
             if ($tr == 'subspecies') {
                 $recMap["taxonrank"] = 'subsp.';
             }
             if ($tr == 'variety') {
                 $recMap["taxonrank"] = 'var.';
             }
             if ($tr == 'forma') {
                 $recMap["taxonrank"] = 'f.';
             }
         }
         //Populate sciname if null
         if (array_key_exists('sciname', $recMap) && $recMap['sciname']) {
             if (substr($recMap['sciname'], -4) == ' sp.') {
                 $recMap['sciname'] = substr($recMap['sciname'], 0, -4);
             }
             if (substr($recMap['sciname'], -3) == ' sp') {
                 $recMap['sciname'] = substr($recMap['sciname'], 0, -3);
             }
             $recMap['sciname'] = str_replace(array(' ssp. ', ' ssp '), ' subsp. ', $recMap['sciname']);
             $recMap['sciname'] = str_replace(' var ', ' var. ', $recMap['sciname']);
             $pattern = '/\\b(cf\\.|cf|aff\\.|aff)\\s{1}/';
             if (preg_match($pattern, $recMap['sciname'], $m)) {
                 $recMap['identificationqualifier'] = $m[1];
                 $recMap['sciname'] = preg_replace($pattern, '', $recMap['sciname']);
             }
         } else {
             if (array_key_exists("genus", $recMap)) {
                 //Build sciname from individual units supplied by source
                 $sciName = $recMap["genus"];
                 if (array_key_exists("specificepithet", $recMap)) {
                     $sciName .= " " . $recMap["specificepithet"];
                 }
                 if (array_key_exists("taxonrank", $recMap)) {
                     $sciName .= " " . $recMap["taxonrank"];
                 }
                 if (array_key_exists("infraspecificepithet", $recMap)) {
                     $sciName .= " " . $recMap["infraspecificepithet"];
                 }
                 $recMap['sciname'] = trim($sciName);
             } elseif (array_key_exists('scientificname', $recMap)) {
                 //Clean and parse scientific name
                 $parsedArr = OccurrenceUtilities::parseScientificName($recMap['scientificname']);
                 $scinameStr = '';
                 if (array_key_exists('unitname1', $parsedArr)) {
                     $scinameStr = $parsedArr['unitname1'];
                     if (!array_key_exists('genus', $recMap) || $recMap['genus']) {
                         $recMap['genus'] = $parsedArr['unitname1'];
                     }
                 }
                 if (array_key_exists('unitname2', $parsedArr)) {
                     $scinameStr .= ' ' . $parsedArr['unitname2'];
                     if (!array_key_exists('specificepithet', $recMap) || !$recMap['specificepithet']) {
                         $recMap['specificepithet'] = $parsedArr['unitname2'];
                     }
                 }
                 if (array_key_exists('unitind3', $parsedArr)) {
                     $scinameStr .= ' ' . $parsedArr['unitind3'];
                     if (!array_key_exists('taxonrank', $recMap) || !$recMap['taxonrank']) {
                         $recMap['taxonrank'] = $parsedArr['unitind3'];
                     }
                 }
                 if (array_key_exists('unitname3', $parsedArr)) {
                     $scinameStr .= ' ' . $parsedArr['unitname3'];
                     if (!array_key_exists('infraspecificepithet', $recMap) || !$recMap['infraspecificepithet']) {
                         $recMap['infraspecificepithet'] = $parsedArr['unitname3'];
                     }
                 }
                 if (array_key_exists('author', $parsedArr)) {
                     if (!array_key_exists('scientificnameauthorship', $recMap) || !$recMap['scientificnameauthorship']) {
                         $recMap['scientificnameauthorship'] = $parsedArr['author'];
                     }
                 }
                 $recMap['sciname'] = trim($scinameStr);
             }
         }
         //If a DiGIR load, set dbpk value
         if ($this->pKField && array_key_exists($this->pKField, $recMap) && !array_key_exists('dbpk', $recMap)) {
             $recMap['dbpk'] = $recMap[$this->pKField];
         }
         //Do some cleaning on the dbpk; remove leading and trailing whitespaces and convert multiple spaces to a single space
         if (array_key_exists('dbpk', $recMap)) {
             $recMap['dbpk'] = trim(preg_replace('/\\s\\s+/', ' ', $recMap['dbpk']));
         }
         $sqlFragments = $this->getSqlFragments($recMap, $this->fieldMap);
         $sql = 'INSERT INTO uploadspectemp(collid' . $sqlFragments['fieldstr'] . ') ' . 'VALUES(' . $this->collId . $sqlFragments['valuestr'] . ')';
         //echo "<div>SQL: ".$sql."</div>";
         if ($this->conn->query($sql)) {
             $this->transferCount++;
             if ($this->transferCount % 1000 == 0) {
                 $this->outputMsg('<li style="margin-left:10px;">Count: ' . $this->transferCount . '</li>');
             }
             ob_flush();
             flush();
             //$this->outputMsg("<li>");
             //$this->outputMsg("Appending/Replacing observation #".$this->transferCount.": SUCCESS");
             //$this->outputMsg("</li>");
         } else {
             $this->outputMsg("<li>FAILED adding record #" . $this->transferCount . "</li>");
             $this->outputMsg("<li style='margin-left:10px;'>Error: " . $this->conn->error . "</li>");
             $this->outputMsg("<li style='margin:0px 0px 10px 10px;'>SQL: {$sql}</li>");
         }
     }
 }
Пример #3
0
 public static function parseVerbatimElevation($inStr)
 {
     return OccurrenceUtilities::parseVerbatimElevation($inStr);
 }
Пример #4
0
 public static function occurrenceArrayCleaning($recMap)
 {
     //Trim all field values
     foreach ($recMap as $k => $v) {
         $recMap[$k] = trim($v);
     }
     //Date cleaning
     if (isset($recMap['eventdate']) && $recMap['eventdate']) {
         if (is_numeric($recMap['eventdate'])) {
             if ($recMap['eventdate'] > 2100 && $recMap['eventdate'] < 45000) {
                 //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
                 $recMap['eventdate'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['eventdate'] - 1, 1900));
             } elseif ($recMap['eventdate'] > 2200000 && $recMap['eventdate'] < 2500000) {
                 //Date is in the Gregorian format
                 $dArr = explode('/', jdtogregorian($recMap['eventdate']));
                 $recMap['eventdate'] = $dArr[2] . '-' . $dArr[0] . '-' . $dArr[1];
             } elseif ($recMap['eventdate'] > 19000000) {
                 //Format: 20120101 = 2012-01-01
                 $recMap['eventdate'] = substr($recMap['eventdate'], 0, 4) . '-' . substr($recMap['eventdate'], 4, 2) . '-' . substr($recMap['eventdate'], 6, 2);
             }
         } else {
             //Make sure event date is a valid format or drop into verbatimEventDate
             $dateStr = OccurrenceUtilities::formatDate($recMap['eventdate']);
             if ($dateStr) {
                 if ($recMap['eventdate'] != $dateStr && (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate'])) {
                     $recMap['verbatimeventdate'] = $recMap['eventdate'];
                 }
                 $recMap['eventdate'] = $dateStr;
             } else {
                 if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                     $recMap['verbatimeventdate'] = $recMap['eventdate'];
                 }
                 unset($recMap['eventdate']);
             }
         }
     }
     if (array_key_exists('latestdatecollected', $recMap) && $recMap['latestdatecollected'] && is_numeric($recMap['latestdatecollected'])) {
         if ($recMap['latestdatecollected'] > 2100 && $recMap['latestdatecollected'] < 45000) {
             //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
             $recMap['latestdatecollected'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['latestdatecollected'] - 1, 1900));
         } elseif ($recMap['latestdatecollected'] > 2200000 && $recMap['latestdatecollected'] < 2500000) {
             $dArr = explode('/', jdtogregorian($recMap['latestdatecollected']));
             $recMap['latestdatecollected'] = $dArr[2] . '-' . $dArr[0] . '-' . $dArr[1];
         } elseif ($recMap['latestdatecollected'] > 19000000) {
             $recMap['latestdatecollected'] = substr($recMap['latestdatecollected'], 0, 4) . '-' . substr($recMap['latestdatecollected'], 4, 2) . '-' . substr($recMap['latestdatecollected'], 6, 2);
         }
     }
     if (array_key_exists('verbatimeventdate', $recMap) && $recMap['verbatimeventdate'] && is_numeric($recMap['verbatimeventdate']) && $recMap['verbatimeventdate'] > 2100 && $recMap['verbatimeventdate'] < 45000) {
         //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
         $recMap['verbatimeventdate'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['verbatimeventdate'] - 1, 1900));
     }
     if (array_key_exists('dateidentified', $recMap) && $recMap['dateidentified'] && is_numeric($recMap['dateidentified']) && $recMap['dateidentified'] > 2100 && $recMap['dateidentified'] < 45000) {
         //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
         $recMap['dateidentified'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['dateidentified'] - 1, 1900));
     }
     //If month, day, or year are text, avoid SQL error by converting to numeric value
     if (array_key_exists('year', $recMap) || array_key_exists('month', $recMap) || array_key_exists('day', $recMap)) {
         $y = array_key_exists('year', $recMap) ? $recMap['year'] : '00';
         $m = array_key_exists('month', $recMap) ? $recMap['month'] : '00';
         $d = array_key_exists('day', $recMap) ? $recMap['day'] : '00';
         $vDate = trim($y . '-' . $m . '-' . $d, '- ');
         if (isset($recMap['day']) && !is_numeric($recMap['day'])) {
             if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                 $recMap['verbatimeventdate'] = $vDate;
             }
             unset($recMap['day']);
             $d = '00';
         }
         if (isset($recMap['year']) && !is_numeric($recMap['year'])) {
             if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                 $recMap['verbatimeventdate'] = $vDate;
             }
             unset($recMap['year']);
         }
         if (isset($recMap['month']) && $recMap['month'] && !is_numeric($recMap['month'])) {
             if (strlen($recMap['month']) > 2) {
                 $monAbbr = strtolower(substr($recMap['month'], 0, 3));
                 if (array_key_exists($monAbbr, OccurrenceUtilities::$monthNames)) {
                     $recMap['month'] = OccurrenceUtilities::$monthNames[$monAbbr];
                     $recMap['eventdate'] = OccurrenceUtilities::formatDate(trim($y . '-' . $recMap['month'] . '-' . ($d ? $d : '00'), '- '));
                 } else {
                     if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                         $recMap['verbatimeventdate'] = $vDate;
                     }
                     unset($recMap['month']);
                 }
             } else {
                 if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                     $recMap['verbatimeventdate'] = $vDate;
                 }
                 unset($recMap['month']);
             }
         }
         if ($vDate && (!array_key_exists('eventdate', $recMap) || !$recMap['eventdate'])) {
             $recMap['eventdate'] = OccurrenceUtilities::formatDate($vDate);
         }
     }
     //eventDate NULL && verbatimEventDate NOT NULL && year NOT NULL
     if ((!array_key_exists('eventdate', $recMap) || !$recMap['eventdate']) && array_key_exists('verbatimeventdate', $recMap) && $recMap['verbatimeventdate'] && (!array_key_exists('year', $recMap) || !$recMap['year'])) {
         $dateStr = OccurrenceUtilities::formatDate($recMap['verbatimeventdate']);
         if ($dateStr) {
             $recMap['eventdate'] = $dateStr;
         }
     }
     if (isset($recMap['recordnumberprefix']) && $recMap['recordnumberprefix'] || isset($recMap['recordnumbersuffix']) && $recMap['recordnumbersuffix']) {
         $recNumber = $recMap['recordnumber'];
         if (isset($recMap['recordnumberprefix']) && $recMap['recordnumberprefix']) {
             $recNumber = $recMap['recordnumberprefix'] . '-' . $recNumber;
         }
         if (isset($recMap['recordnumbersuffix']) && $recMap['recordnumbersuffix']) {
             if (is_numeric($recMap['recordnumbersuffix']) && $recMap['recordnumber']) {
                 $recNumber .= '-';
             }
             $recNumber .= $recMap['recordnumbersuffix'];
         }
         $recMap['recordnumber'] = $recNumber;
     }
     //If lat or long are not numeric, try to make them so
     if (array_key_exists('decimallatitude', $recMap) || array_key_exists('decimallongitude', $recMap)) {
         $latValue = array_key_exists('decimallatitude', $recMap) ? $recMap['decimallatitude'] : '';
         $lngValue = array_key_exists('decimallongitude', $recMap) ? $recMap['decimallongitude'] : '';
         if ($latValue && !is_numeric($latValue) || $lngValue && !is_numeric($lngValue)) {
             $llArr = OccurrenceUtilities::parseVerbatimCoordinates(trim($latValue . ' ' . $lngValue), 'LL');
             if (array_key_exists('lat', $llArr) && array_key_exists('lng', $llArr)) {
                 $recMap['decimallatitude'] = $llArr['lat'];
                 $recMap['decimallongitude'] = $llArr['lng'];
             } else {
                 unset($recMap['decimallatitude']);
                 unset($recMap['decimallongitude']);
             }
             $vcStr = '';
             if (array_key_exists('verbatimcoordinates', $recMap) && $recMap['verbatimcoordinates']) {
                 $vcStr .= $recMap['verbatimcoordinates'] . '; ';
             }
             $vcStr .= $latValue . ' ' . $lngValue;
             if (trim($vcStr)) {
                 $recMap['verbatimcoordinates'] = trim($vcStr);
             }
         }
     }
     //Transfer verbatim Lat/Long to verbatim coords
     if (isset($recMap['verbatimlatitude']) || isset($recMap['verbatimlongitude'])) {
         if (isset($recMap['verbatimlatitude']) && isset($recMap['verbatimlongitude'])) {
             if (!isset($recMap['decimallatitude']) || !isset($recMap['decimallongitude'])) {
                 if (is_numeric($recMap['verbatimlatitude']) && is_numeric($recMap['verbatimlongitude'])) {
                     if ($recMap['verbatimlatitude'] > -90 && $recMap['verbatimlatitude'] < 90 && $recMap['verbatimlongitude'] > -180 && $recMap['verbatimlongitude'] < 180) {
                         $recMap['decimallatitude'] = $recMap['verbatimlatitude'];
                         $recMap['decimallongitude'] = $recMap['verbatimlongitude'];
                     }
                 } else {
                     //Attempt to extract decimal lat/long
                     $coordArr = OccurrenceUtilities::parseVerbatimCoordinates($recMap['verbatimlatitude'] . ' ' . $recMap['verbatimlongitude'], 'LL');
                     if ($coordArr) {
                         if (array_key_exists('lat', $coordArr)) {
                             $recMap['decimallatitude'] = $coordArr['lat'];
                         }
                         if (array_key_exists('lng', $coordArr)) {
                             $recMap['decimallongitude'] = $coordArr['lng'];
                         }
                     }
                 }
             }
         }
         //Place into verbatim coord field
         $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
         if ($vCoord) {
             $vCoord .= '; ';
         }
         if (stripos($vCoord, $recMap['verbatimlatitude']) === false && stripos($vCoord, $recMap['verbatimlongitude']) === false) {
             $recMap['verbatimcoordinates'] = $vCoord . $recMap['verbatimlatitude'] . ', ' . $recMap['verbatimlongitude'];
         }
     }
     //Transfer DMS to verbatim coords
     if (isset($recMap['latdeg']) && $recMap['latdeg'] && isset($recMap['lngdeg']) && $recMap['lngdeg']) {
         //Attempt to create decimal lat/long
         if (is_numeric($recMap['latdeg']) && is_numeric($recMap['lngdeg']) && (!isset($recMap['decimallatitude']) || !isset($recMap['decimallongitude']))) {
             $latDec = $recMap['latdeg'];
             if (isset($recMap['latmin']) && $recMap['latmin'] && is_numeric($recMap['latmin'])) {
                 $latDec += $recMap['latmin'] / 60;
             }
             if (isset($recMap['latsec']) && $recMap['latsec'] && is_numeric($recMap['latsec'])) {
                 $latDec += $recMap['latsec'] / 3600;
             }
             if (stripos($recMap['latns'], 's') === 0 && $latDec > 0) {
                 $latDec *= -1;
             }
             $lngDec = $recMap['lngdeg'];
             if (isset($recMap['lngmin']) && $recMap['lngmin'] && is_numeric($recMap['lngmin'])) {
                 $lngDec += $recMap['lngmin'] / 60;
             }
             if (isset($recMap['lngsec']) && $recMap['lngsec'] && is_numeric($recMap['lngsec'])) {
                 $lngDec += $recMap['lngsec'] / 3600;
             }
             if (stripos($recMap['lngew'], 'e') === 0) {
                 $lngDec *= -1;
             }
             $recMap['decimallatitude'] = round($latDec, 6);
             $recMap['decimallongitude'] = round($lngDec, 6);
         }
         //Place into verbatim coord field
         $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
         if ($vCoord) {
             $vCoord .= '; ';
         }
         $vCoord .= $recMap['latdeg'] . '° ';
         if (isset($recMap['latmin']) && $recMap['latmin']) {
             $vCoord .= $recMap['latmin'] . 'm ';
         }
         if (isset($recMap['latsec']) && $recMap['latsec']) {
             $vCoord .= $recMap['latsec'] . 's ';
         }
         if (isset($recMap['latns'])) {
             $vCoord .= $recMap['latns'] . '; ';
         }
         $vCoord .= $recMap['lngdeg'] . '° ';
         if (isset($recMap['lngmin']) && $recMap['lngmin']) {
             $vCoord .= $recMap['lngmin'] . 'm ';
         }
         if (isset($recMap['lngsec']) && $recMap['lngsec']) {
             $vCoord .= $recMap['lngsec'] . 's ';
         }
         if (isset($recMap['lngew'])) {
             $vCoord .= $recMap['lngew'];
         }
         $recMap['verbatimcoordinates'] = $vCoord;
     }
     /*
     if(array_key_exists('verbatimcoordinates',$recMap) && $recMap['verbatimcoordinates'] && (!isset($recMap['decimallatitude']) || !isset($recMap['decimallongitude']))){
     $coordArr = OccurrenceUtilities::parseVerbatimCoordinates($recMap['verbatimcoordinates']);
     if($coordArr){
     if(array_key_exists('lat',$coordArr)) $recMap['decimallatitude'] = $coordArr['lat'];
     if(array_key_exists('lng',$coordArr)) $recMap['decimallongitude'] = $coordArr['lng'];
     }
     }
     */
     //Convert UTM to Lat/Long
     if (array_key_exists('utmnorthing', $recMap) && $recMap['utmnorthing'] || array_key_exists('utmeasting', $recMap) && $recMap['utmeasting']) {
         $no = array_key_exists('utmnorthing', $recMap) ? $recMap['utmnorthing'] : '';
         $ea = array_key_exists('utmeasting', $recMap) ? $recMap['utmeasting'] : '';
         $zo = array_key_exists('utmzoning', $recMap) ? $recMap['utmzoning'] : '';
         $da = array_key_exists('geodeticdatum', $recMap) ? $recMap['geodeticdatum'] : '';
         if (!isset($recMap['decimallatitude']) || !isset($recMap['decimallongitude'])) {
             if ($no && $ea && $zo) {
                 //Northing, easting, and zoning all had values
                 $llArr = OccurrenceUtilities::convertUtmToLL($ea, $no, $zo, $da);
                 if (isset($llArr['lat'])) {
                     $recMap['decimallatitude'] = $llArr['lat'];
                 }
                 if (isset($llArr['lng'])) {
                     $recMap['decimallongitude'] = $llArr['lng'];
                 }
             } else {
                 //UTM was a single field which was placed in UTM northing field within uploadspectemp table
                 $coordArr = OccurrenceUtilities::parseVerbatimCoordinates(trim($zo . ' ' . $ea . ' ' . $no), 'UTM');
                 if ($coordArr) {
                     if (array_key_exists('lat', $coordArr)) {
                         $recMap['decimallatitude'] = $coordArr['lat'];
                     }
                     if (array_key_exists('lng', $coordArr)) {
                         $recMap['decimallongitude'] = $coordArr['lng'];
                     }
                 }
             }
         }
         $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
         if (!($no && strpos($vCoord, $no))) {
             $recMap['verbatimcoordinates'] = ($vCoord ? $vCoord . '; ' : '') . $zo . ' ' . $ea . 'E ' . $no . 'N';
         }
     }
     //Transfer TRS to verbatim coords
     if (isset($recMap['trstownship']) && $recMap['trstownship'] && isset($recMap['trsrange']) && $recMap['trsrange']) {
         $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
         if ($vCoord) {
             $vCoord .= '; ';
         }
         $vCoord .= (stripos($recMap['trstownship'], 't') === false ? 'T' : '') . $recMap['trstownship'] . ' ';
         $vCoord .= (stripos($recMap['trsrange'], 'r') === false ? 'R' : '') . $recMap['trsrange'] . ' ';
         if (isset($recMap['trssection'])) {
             $vCoord .= (stripos($recMap['trssection'], 's') === false ? 'sec' : '') . $recMap['trssection'] . ' ';
         }
         if (isset($recMap['trssectiondetails'])) {
             $vCoord .= $recMap['trssectiondetails'];
         }
         $recMap['verbatimcoordinates'] = trim($vCoord);
     }
     //Check to see if evelation are valid numeric values
     if (isset($recMap['minimumelevationinmeters']) && $recMap['minimumelevationinmeters'] && !is_numeric($recMap['minimumelevationinmeters']) || isset($recMap['maximumelevationinmeters']) && $recMap['maximumelevationinmeters'] && !is_numeric($recMap['maximumelevationinmeters'])) {
         $vStr = isset($recMap['verbatimelevation']) ? $recMap['verbatimelevation'] : '';
         if (isset($recMap['minimumelevationinmeters']) && $recMap['minimumelevationinmeters']) {
             $vStr .= ($vStr ? '; ' : '') . $recMap['minimumelevationinmeters'];
         }
         if (isset($recMap['maximumelevationinmeters']) && $recMap['maximumelevationinmeters']) {
             $vStr .= '-' . $recMap['maximumelevationinmeters'];
         }
         $recMap['verbatimelevation'] = $vStr;
         $recMap['minimumelevationinmeters'] = '';
         $recMap['maximumelevationinmeters'] = '';
     }
     //Verbatim elevation
     if (array_key_exists('verbatimelevation', $recMap) && $recMap['verbatimelevation'] && (!array_key_exists('minimumelevationinmeters', $recMap) || !$recMap['minimumelevationinmeters'])) {
         $eArr = OccurrenceUtilities::parseVerbatimElevation($recMap['verbatimelevation']);
         if ($eArr) {
             if (array_key_exists('minelev', $eArr)) {
                 $recMap['minimumelevationinmeters'] = $eArr['minelev'];
                 if (array_key_exists('maxelev', $eArr)) {
                     $recMap['maximumelevationinmeters'] = $eArr['maxelev'];
                 }
             }
         }
     }
     //Deal with elevation when in two fields (number and units)
     if (isset($recMap['elevationnumber']) && $recMap['elevationnumber']) {
         $elevStr = $recMap['elevationnumber'] . $recMap['elevationunits'];
         //Try to extract meters
         $eArr = OccurrenceUtilities::parseVerbatimElevation($elevStr);
         if ($eArr) {
             if (array_key_exists('minelev', $eArr)) {
                 $recMap['minimumelevationinmeters'] = $eArr['minelev'];
                 if (array_key_exists('maxelev', $eArr)) {
                     $recMap['maximumelevationinmeters'] = $eArr['maxelev'];
                 }
             }
         }
         if (!$eArr || !stripos($elevStr, 'm')) {
             $vElev = isset($recMap['verbatimelevation']) ? $recMap['verbatimelevation'] : '';
             if ($vElev) {
                 $vElev .= '; ';
             }
             $recMap['verbatimelevation'] = $vElev . $elevStr;
         }
     }
     //Concatenate collectorfamilyname and collectorinitials into recordedby
     if (isset($recMap['collectorfamilyname']) && $recMap['collectorfamilyname'] && (!isset($recMap['recordedby']) || !$recMap['recordedby'])) {
         $recordedBy = $recMap['collectorfamilyname'];
         if (isset($recMap['collectorinitials']) && $recMap['collectorinitials']) {
             $recordedBy .= ', ' . $recMap['collectorinitials'];
         }
         $recMap['recordedby'] = $recordedBy;
         //Need to add code that maps to collector table
     }
     if (array_key_exists("specificepithet", $recMap)) {
         if ($recMap["specificepithet"] == 'sp.' || $recMap["specificepithet"] == 'sp') {
             $recMap["specificepithet"] = '';
         }
     }
     if (array_key_exists("taxonrank", $recMap)) {
         $tr = strtolower($recMap["taxonrank"]);
         if ($tr == 'species' || !$recMap["specificepithet"]) {
             $recMap["taxonrank"] = '';
         }
         if ($tr == 'subspecies') {
             $recMap["taxonrank"] = 'subsp.';
         }
         if ($tr == 'variety') {
             $recMap["taxonrank"] = 'var.';
         }
         if ($tr == 'forma') {
             $recMap["taxonrank"] = 'f.';
         }
     }
     //Populate sciname if null
     if (array_key_exists('sciname', $recMap) && $recMap['sciname']) {
         if (substr($recMap['sciname'], -4) == ' sp.') {
             $recMap['sciname'] = substr($recMap['sciname'], 0, -4);
         }
         if (substr($recMap['sciname'], -3) == ' sp') {
             $recMap['sciname'] = substr($recMap['sciname'], 0, -3);
         }
         $recMap['sciname'] = str_replace(array(' ssp. ', ' ssp '), ' subsp. ', $recMap['sciname']);
         $recMap['sciname'] = str_replace(' var ', ' var. ', $recMap['sciname']);
         $pattern = '/\\b(cf\\.|cf|aff\\.|aff)\\s{1}/';
         if (preg_match($pattern, $recMap['sciname'], $m)) {
             $recMap['identificationqualifier'] = $m[1];
             $recMap['sciname'] = preg_replace($pattern, '', $recMap['sciname']);
         }
     } else {
         if (array_key_exists("genus", $recMap)) {
             //Build sciname from individual units supplied by source
             $sciName = $recMap["genus"];
             if (array_key_exists("specificepithet", $recMap)) {
                 $sciName .= " " . $recMap["specificepithet"];
             }
             if (array_key_exists("taxonrank", $recMap)) {
                 $sciName .= " " . $recMap["taxonrank"];
             }
             if (array_key_exists("infraspecificepithet", $recMap)) {
                 $sciName .= " " . $recMap["infraspecificepithet"];
             }
             $recMap['sciname'] = trim($sciName);
         } elseif (array_key_exists('scientificname', $recMap)) {
             //Clean and parse scientific name
             $parsedArr = OccurrenceUtilities::parseScientificName($recMap['scientificname']);
             $scinameStr = '';
             if (array_key_exists('unitname1', $parsedArr)) {
                 $scinameStr = $parsedArr['unitname1'];
                 if (!array_key_exists('genus', $recMap) || $recMap['genus']) {
                     $recMap['genus'] = $parsedArr['unitname1'];
                 }
             }
             if (array_key_exists('unitname2', $parsedArr)) {
                 $scinameStr .= ' ' . $parsedArr['unitname2'];
                 if (!array_key_exists('specificepithet', $recMap) || !$recMap['specificepithet']) {
                     $recMap['specificepithet'] = $parsedArr['unitname2'];
                 }
             }
             if (array_key_exists('unitind3', $parsedArr)) {
                 $scinameStr .= ' ' . $parsedArr['unitind3'];
                 if (!array_key_exists('taxonrank', $recMap) || !$recMap['taxonrank']) {
                     $recMap['taxonrank'] = $parsedArr['unitind3'];
                 }
             }
             if (array_key_exists('unitname3', $parsedArr)) {
                 $scinameStr .= ' ' . $parsedArr['unitname3'];
                 if (!array_key_exists('infraspecificepithet', $recMap) || !$recMap['infraspecificepithet']) {
                     $recMap['infraspecificepithet'] = $parsedArr['unitname3'];
                 }
             }
             if (array_key_exists('author', $parsedArr)) {
                 if (!array_key_exists('scientificnameauthorship', $recMap) || !$recMap['scientificnameauthorship']) {
                     $recMap['scientificnameauthorship'] = $parsedArr['author'];
                 }
             }
             $recMap['sciname'] = trim($scinameStr);
         }
     }
     return $recMap;
 }