Extract coordinates from KML using shell tools

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>Test.kmz</name>
<Placemark>
<name>Test</name>
<LookAt>
<longitude>48.7893522149238</longitude>
<latitude>35.11072013511394</latitude>
<altitude>0</altitude>
<heading>-0.1257146222858709</heading>
<tilt>27.02159138599089</tilt>
<range>804.546845381412</range>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#m_ylw-pushpin160</styleUrl>
<Point>
<gx:drawOrder>1</gx:drawOrder>
<coordinates>48.78741496263481,35.11017636516465,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
I would like to extract the 48.78741496263481,35.11017636516465 from a KML (but in reverse order) as 35.11017636516465,48.78741496263481. Is this a task for sed or awk?
Thanks in advance.
awk sed geolocation
add a comment |Â
up vote
0
down vote
favorite
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>Test.kmz</name>
<Placemark>
<name>Test</name>
<LookAt>
<longitude>48.7893522149238</longitude>
<latitude>35.11072013511394</latitude>
<altitude>0</altitude>
<heading>-0.1257146222858709</heading>
<tilt>27.02159138599089</tilt>
<range>804.546845381412</range>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#m_ylw-pushpin160</styleUrl>
<Point>
<gx:drawOrder>1</gx:drawOrder>
<coordinates>48.78741496263481,35.11017636516465,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
I would like to extract the 48.78741496263481,35.11017636516465 from a KML (but in reverse order) as 35.11017636516465,48.78741496263481. Is this a task for sed or awk?
Thanks in advance.
awk sed geolocation
Consider using an XML parser for this e.g.xmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -c '//kml:coordinates/text()' -n yourfile.xmlorxmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -v 'concat(//kml:latitude,",",//kml:longitude)' -n yourfile.xml. See for example Why does this XPath expression not return the correct value in xmlstarlet?
â steeldriver
Jul 30 at 12:39
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>Test.kmz</name>
<Placemark>
<name>Test</name>
<LookAt>
<longitude>48.7893522149238</longitude>
<latitude>35.11072013511394</latitude>
<altitude>0</altitude>
<heading>-0.1257146222858709</heading>
<tilt>27.02159138599089</tilt>
<range>804.546845381412</range>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#m_ylw-pushpin160</styleUrl>
<Point>
<gx:drawOrder>1</gx:drawOrder>
<coordinates>48.78741496263481,35.11017636516465,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
I would like to extract the 48.78741496263481,35.11017636516465 from a KML (but in reverse order) as 35.11017636516465,48.78741496263481. Is this a task for sed or awk?
Thanks in advance.
awk sed geolocation
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>Test.kmz</name>
<Placemark>
<name>Test</name>
<LookAt>
<longitude>48.7893522149238</longitude>
<latitude>35.11072013511394</latitude>
<altitude>0</altitude>
<heading>-0.1257146222858709</heading>
<tilt>27.02159138599089</tilt>
<range>804.546845381412</range>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#m_ylw-pushpin160</styleUrl>
<Point>
<gx:drawOrder>1</gx:drawOrder>
<coordinates>48.78741496263481,35.11017636516465,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
I would like to extract the 48.78741496263481,35.11017636516465 from a KML (but in reverse order) as 35.11017636516465,48.78741496263481. Is this a task for sed or awk?
Thanks in advance.
awk sed geolocation
asked Jul 30 at 8:08
Luis Paganini
132
132
Consider using an XML parser for this e.g.xmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -c '//kml:coordinates/text()' -n yourfile.xmlorxmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -v 'concat(//kml:latitude,",",//kml:longitude)' -n yourfile.xml. See for example Why does this XPath expression not return the correct value in xmlstarlet?
â steeldriver
Jul 30 at 12:39
add a comment |Â
Consider using an XML parser for this e.g.xmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -c '//kml:coordinates/text()' -n yourfile.xmlorxmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -v 'concat(//kml:latitude,",",//kml:longitude)' -n yourfile.xml. See for example Why does this XPath expression not return the correct value in xmlstarlet?
â steeldriver
Jul 30 at 12:39
Consider using an XML parser for this e.g.
xmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -c '//kml:coordinates/text()' -n yourfile.xml or xmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -v 'concat(//kml:latitude,",",//kml:longitude)' -n yourfile.xml . See for example Why does this XPath expression not return the correct value in xmlstarlet?â steeldriver
Jul 30 at 12:39
Consider using an XML parser for this e.g.
xmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -c '//kml:coordinates/text()' -n yourfile.xml or xmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -v 'concat(//kml:latitude,",",//kml:longitude)' -n yourfile.xml . See for example Why does this XPath expression not return the correct value in xmlstarlet?â steeldriver
Jul 30 at 12:39
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
Using AWK:
awk -F '[>,]' '/coordinates/ print $3","$2' file
- search for the pattern coordinates and prints the 3rd field and 2nd field.
add a comment |Â
up vote
0
down vote
awk -F"[<>]" '/longitude/long=$3/latitude/print $3","long' file.txt
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Using AWK:
awk -F '[>,]' '/coordinates/ print $3","$2' file
- search for the pattern coordinates and prints the 3rd field and 2nd field.
add a comment |Â
up vote
0
down vote
accepted
Using AWK:
awk -F '[>,]' '/coordinates/ print $3","$2' file
- search for the pattern coordinates and prints the 3rd field and 2nd field.
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Using AWK:
awk -F '[>,]' '/coordinates/ print $3","$2' file
- search for the pattern coordinates and prints the 3rd field and 2nd field.
Using AWK:
awk -F '[>,]' '/coordinates/ print $3","$2' file
- search for the pattern coordinates and prints the 3rd field and 2nd field.
edited Jul 30 at 8:42
answered Jul 30 at 8:37
SivaPrasath
3,46311535
3,46311535
add a comment |Â
add a comment |Â
up vote
0
down vote
awk -F"[<>]" '/longitude/long=$3/latitude/print $3","long' file.txt
add a comment |Â
up vote
0
down vote
awk -F"[<>]" '/longitude/long=$3/latitude/print $3","long' file.txt
add a comment |Â
up vote
0
down vote
up vote
0
down vote
awk -F"[<>]" '/longitude/long=$3/latitude/print $3","long' file.txt
awk -F"[<>]" '/longitude/long=$3/latitude/print $3","long' file.txt
answered Jul 30 at 8:22
Kamaraj
2,5341312
2,5341312
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f459279%2fextract-point-coordinates-from-kml-using-shell-tools%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Consider using an XML parser for this e.g.
xmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -c '//kml:coordinates/text()' -n yourfile.xmlorxmlstarlet sel -N kml='http://www.opengis.net/kml/2.2' -t -v 'concat(//kml:latitude,",",//kml:longitude)' -n yourfile.xml. See for example Why does this XPath expression not return the correct value in xmlstarlet?â steeldriver
Jul 30 at 12:39