Tripal Plant PopGen Submit
standard_coord.inc
Go to the documentation of this file.
1 <?php
2 
19 function tpps_standard_coord($raw_coordinate) {
20  // Patch added on 3/22/2022 - Reported by Emily Strickland
21  if(stripos($raw_coordinate,'‐') !== FALSE) {
22  // this is a strange character, so replace it with standard minus
23  $raw_coordinate = str_ireplace('‐','-', $raw_coordinate);
24  }
25 
26 
27  $matches = array();
28  if (preg_match('/(([0-9]+)° ?([0-9]+)\' ?([0-9|\.]+)" ?([N|S])),? ?(([0-9]+)° ?([0-9]+)\' ?([0-9|\.]+)" ?([E|W]))/', $raw_coordinate, $matches)) {
29  $lat = $matches[2] + ($matches[3] / 60) + ($matches[4] / 3600);
30  $long = $matches[7] + ($matches[8] / 60) + ($matches[9] / 3600);
31  }
32  elseif (preg_match('/(([0-9]+)° ?([0-9|\.]+)\' ?([N|S])),? ?(([0-9]+)° ?([0-9|\.]+)\' ?([E|W]))/', $raw_coordinate, $matches)) {
33  $lat = $matches[2] + ($matches[3] / 60);
34  $long = $matches[6] + ($matches[7] / 60);
35  }
36  elseif (preg_match('/([0-9|\.]+), ?[\+|-]?([0-9|\.]+)/', $raw_coordinate, $matches)) {
37  $lat = $matches[1];
38  $long = $matches[2];
39  }
40  elseif (preg_match('/([0-9|\.]+)°? ?([N|S]),? ?([0-9|\.]+)°? ?([E|W])/', $raw_coordinate, $matches)) {
41  $lat = $matches[1];
42  $long = $matches[3];
43  }
44  else {
45  return FALSE;
46  }
47 
48  if ($lat > 180 or $long > 180) {
49  return FALSE;
50  }
51 
52  if (preg_match('/(-).+,/', $raw_coordinate, $matches)) {
53  $lat = $lat * -1;
54  }
55  if (preg_match('/,.*(-)/', $raw_coordinate, $matches)) {
56  $long = $long * -1;
57  }
58 
59  if (preg_match('/([N|S]).+([E|W])/', $raw_coordinate, $matches)) {
60  if ($matches[1] == 'S') {
61  $lat = $lat * -1;
62  }
63  if ($matches[2] == 'W') {
64  $long = $long * -1;
65  }
66  }
67 
68  return "$lat,$long";
69 }
tpps_standard_coord($raw_coordinate)