public static function convertUtmToLL($e, $n, $z, $d)
 {
     return OccurrenceUtilities::convertUtmToLL($e, $n, $z, $d);
 }
Esempio n. 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>");
         }
     }
 }
 public static function parseVerbatimCoordinates($inStr, $target = '')
 {
     $retArr = array();
     if (strpos($inStr, ' to ')) {
         return $retArr;
     }
     if (strpos($inStr, ' betw ')) {
         return $retArr;
     }
     //Get rid of curly quotes
     $search = array("’", "‘", "`", "”", "“");
     $replace = array("'", "'", "'", '"', '"');
     $inStr = str_replace($search, $replace, $inStr);
     //Try to parse lat/lng
     $latDeg = 'null';
     $latMin = 0;
     $latSec = 0;
     $latNS = 'N';
     $lngDeg = 'null';
     $lngMin = 0;
     $lngSec = 0;
     $lngEW = 'W';
     //Grab lat deg and min
     if (!$target || $target == 'LL') {
         if (preg_match('/([\\sNSns]{0,1})(-?\\d{1,2}\\.{1}\\d+)\\D{0,1}\\s{0,1}([NSns]{0,1})\\D{0,1}([\\sEWew]{1})(-?\\d{1,4}\\.{1}\\d+)\\D{0,1}\\s{0,1}([EWew]{0,1})\\D*/', $inStr, $m)) {
             //Decimal degree format
             $retArr['lat'] = $m[2];
             $retArr['lng'] = $m[5];
             $latDir = $m[3];
             if (!$latDir && $m[1]) {
                 $latDir = trim($m[1]);
             }
             if ($retArr['lat'] > 0 && $latDir && ($latDir == 'S' || $latDir == 's')) {
                 $retArr['lat'] = -1 * $retArr['lat'];
             }
             $lngDir = $m[6];
             if (!$lngDir && $m[4]) {
                 $lngDir = trim($m[4]);
             }
             if ($retArr['lng'] > 0 && $latDir && ($lngDir == 'W' || $lngDir == 'w')) {
                 $retArr['lng'] = -1 * $retArr['lng'];
             }
         } elseif (preg_match('/(\\d{1,2})\\D{1,3}\\s{0,2}(\\d{1,2}\\.{0,1}\\d*)[\'m]{1}(.*)/i', $inStr, $m)) {
             //DMS format
             $latDeg = $m[1];
             $latMin = $m[2];
             $leftOver = str_replace("''", '"', trim($m[3]));
             //Grab lat NS and lng EW
             if (stripos($inStr, 'N') === false && strpos($inStr, 'S') !== false) {
                 $latNS = 'S';
             }
             if (stripos($inStr, 'W') === false && stripos($inStr, 'E') !== false) {
                 $lngEW = 'E';
             }
             //Grab lat sec
             if (preg_match('/^(\\d{1,2}\\.{0,1}\\d*)["s]{1}(.*)/i', $leftOver, $m)) {
                 $latSec = $m[1];
                 if (count($m) > 2) {
                     $leftOver = trim($m[2]);
                 }
             }
             //Grab lng deg and min
             if (preg_match('/(\\d{1,3})\\D{1,3}\\s{0,2}(\\d{1,2}\\.{0,1}\\d*)[\'m]{1}(.*)/i', $leftOver, $m)) {
                 $lngDeg = $m[1];
                 $lngMin = $m[2];
                 $leftOver = trim($m[3]);
                 //Grab lng sec
                 if (preg_match('/^(\\d{1,2}\\.{0,1}\\d*)["s]{1}(.*)/i', $leftOver, $m)) {
                     $lngSec = $m[1];
                     if (count($m) > 2) {
                         $leftOver = trim($m[2]);
                     }
                 }
                 if (is_numeric($latDeg) && is_numeric($latMin) && is_numeric($lngDeg) && is_numeric($lngMin)) {
                     if ($latDeg < 90 && $latMin < 60 && $lngDeg < 180 && $lngMin < 60) {
                         $latDec = $latDeg + $latMin / 60 + $latSec / 3600;
                         $lngDec = $lngDeg + $lngMin / 60 + $lngSec / 3600;
                         if ($latNS == 'S') {
                             $latDec = -$latDec;
                         }
                         if ($lngEW == 'W') {
                             $lngDec = -$lngDec;
                         }
                         $retArr['lat'] = round($latDec, 6);
                         $retArr['lng'] = round($lngDec, 6);
                     }
                 }
             }
         }
     }
     if (!$target && !$retArr || $target == 'UTM') {
         //UTM parsing
         $d = '';
         if (preg_match('/NAD\\s*27/i', $inStr)) {
             $d = 'NAD27';
         }
         if (preg_match('/\\D*(\\d{1,2}\\D{0,1})\\s+(\\d{6,7})E\\s+(\\d{7})N/i', $inStr, $m)) {
             $z = $m[1];
             $e = $m[2];
             $n = $m[3];
             if ($n && $e && $z) {
                 $llArr = OccurrenceUtilities::convertUtmToLL($e, $n, $z, $d);
                 if (isset($llArr['lat'])) {
                     $retArr['lat'] = $llArr['lat'];
                 }
                 if (isset($llArr['lng'])) {
                     $retArr['lng'] = $llArr['lng'];
                 }
             }
         } elseif (preg_match('/UTM/', $inStr) || preg_match('/\\d{1,2}[\\D\\s]+\\d{6,7}[\\D\\s]+\\d{6,7}/', $inStr)) {
             //UTM
             $z = '';
             $e = '';
             $n = '';
             if (preg_match('/^(\\d{1,2}\\D{0,1})[\\s\\D]+/', $inStr, $m)) {
                 $z = $m[1];
             }
             if (!$z && preg_match('/[\\s\\D]+(\\d{1,2}\\D{0,1})$/', $inStr, $m)) {
                 $z = $m[1];
             }
             if (!$z && preg_match('/[\\s\\D]+(\\d{1,2}\\D{0,1})[\\s\\D]+/', $inStr, $m)) {
                 $z = $m[1];
             }
             if ($z) {
                 if (preg_match('/(\\d{6,7})E{1}[\\D\\s]+(\\d{7})N{1}/i', $inStr, $m)) {
                     $e = $m[1];
                     $n = $m[2];
                 } elseif (preg_match('/E{1}(\\d{6,7})[\\D\\s]+N{1}(\\d{7})/i', $inStr, $m)) {
                     $e = $m[1];
                     $n = $m[2];
                 } elseif (preg_match('/(\\d{7})N{1}[\\D\\s]+(\\d{6,7})E{1}/i', $inStr, $m)) {
                     $e = $m[2];
                     $n = $m[1];
                 } elseif (preg_match('/N{1}(\\d{7})[\\D\\s]+E{1}(\\d{6,7})/i', $inStr, $m)) {
                     $e = $m[2];
                     $n = $m[1];
                 } elseif (preg_match('/(\\d{6})[\\D\\s]+(\\d{7})/', $inStr, $m)) {
                     $e = $m[1];
                     $n = $m[2];
                 } elseif (preg_match('/(\\d{7})[\\D\\s]+(\\d{6})/', $inStr, $m)) {
                     $e = $m[2];
                     $n = $m[1];
                 }
                 if ($e && $n) {
                     $llArr = OccurrenceUtilities::convertUtmToLL($e, $n, $z, $d);
                     if (isset($llArr['lat'])) {
                         $retArr['lat'] = $llArr['lat'];
                     }
                     if (isset($llArr['lng'])) {
                         $retArr['lng'] = $llArr['lng'];
                     }
                 }
             }
         }
     }
     //Clean
     if ($retArr) {
         if ($retArr['lat'] < -90 || $retArr['lat'] > 90) {
             return;
         }
         if ($retArr['lng'] < -180 || $retArr['lng'] > 180) {
             return;
         }
     }
     return $retArr;
 }
Esempio n. 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;
 }