Skip to content

Commit 41d0883

Browse files
committed
added parse_geom
1 parent dc988d6 commit 41d0883

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Util.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,34 @@ public static function zip($files = [], $destination = '', $overwrite = false) {
951951
return false;
952952
}
953953
}
954+
955+
// https://stackoverflow.com/questions/16482303/convert-well-known-text-wkt-from-mysql-to-google-maps-polygons-with-php
956+
public static function parse_geom($ps) {
957+
$arr = array();
958+
959+
//match '(' and ')' plus contents between them which contain anything other than '(' or ')'
960+
preg_match_all('/\([^\(\)]+\)/', $ps, $matches);
961+
962+
if ($matches = $matches[0]) {
963+
foreach ($matches as $match) {
964+
preg_match_all('/-?\d+\.?\d*/', $match, $tmp_matches);
965+
if ($tmp_matches = $tmp_matches[0]) {
966+
//convert all the coordinate sets in tmp from strings to Numbers and convert to LatLng objects
967+
$position = array();
968+
for ($i = 0; $i < count($tmp_matches); $i += 2) {
969+
$lng = (float)$tmp_matches[$i];
970+
$lat = (float)$tmp_matches[$i + 1];
971+
$position[] = array($lat, $lng);
972+
}
973+
974+
$arr[] = $position;
975+
}
976+
}
977+
}
978+
979+
//array of arrays of LatLng objects, or empty array
980+
return $arr;
981+
}
954982
}
955983

956984
?>

0 commit comments

Comments
 (0)