I have a connection to a postgresql db its returning the following results
O4, MULTILINESTRING((-91.4272099951079 35.6984820849707,-91.2691971234476 35.8195546559061))
I4, MULTILINESTRING((-91.4668296641028 35.5407821819705,-91.3332878428544 35.7230307833947,-91.1889662757843 35.8834271551078))
using this query:
select id, astext(the_geom)from trkl
I am trying to generate a file like the following, I have to invert the cords 35.xx should be first and -91.xx last is there a easy way to do this?
"O4"
35.62200200, -88.98259200
35.62203500, -88.98240800
35.62202700, -88.98231000
35.62180000, -88.98163400
END:
"I4"
35.62200200, -88.98259200
35.62203500, -88.98240800
35.62202700, -88.98231000
35.62180000, -88.98163400
35.62175700, -88.98149000
35.62172500, -88.97881200
35.62172000, -88.97798500
35.62169800, -88.97752400
END
I'm not familiar with this PGSQL and how the result would look when fetched from the database, but I think this is what you're looking for...
$mls = '-91.4272099951079 35.6984820849707,-91.2691971234476 35.8195546559061';
$pairs = explode(',', $mls);
foreach ($pairs as $pair) {
$coords = explode(' ', $pair);
printf('%s, %s', $coords[1], $coords[0]);
}
Would output
35.6984820849707, -91.4272099951079
35.8195546559061, -91.2691971234476
Assuming that your coordinates are always fetched with MULTILINESTRING contained in the string:
$output = array();
foreach ($results as $row)
{
$row = explode(', ', $row, 2);
$output[] = '"'.$row[0].'"';
$row = explode(',', substr(rtrim($row[1], ')'), 17);
for ($i = 0, $c = count($row); $i < $c; $i++)
{
$row[$i] = explode(' ', $row[$i], 2);
$output[] = $row[$i][1].', '.$row[$i][0];
}
}
$output = implode("
", $output);
There are better solutions, but this is the most obvious one and should do the job.