KML 2 LMX
by
xeo
@ 27/08/2007
Transformez vos Google Maps en carte pour GPS Nokia
C'est l'été, à Paris tout le monde roule en vélib'.
Mon Nokia N95 est bien joli avec son GPS, mais les carte sont au format LMX. Et moi j'ai toutes mes cartes sur Google Maps, et elles sont en KML.
Que faire ?
Et bien remercions les formats ouverts car LMX et KML sont simlpement des fichiers XML.
Alors avec un peu de Perl et de recherche, voici le kml2lmx.pl :
#!/usr/bin/perl
#####
# @author: Brice DEKANY
# @mail: linuxtraveler@gmail.com
# @license: GPL
#####
use XML::Parser;
sub startElement {
my ($parseinst, $element, %attrs) = @_;
$tag = "";
SWITCH: {
if ($element eq "name") {
$tag = "name";
last SWITCH;
}
if ($element eq "description") {
$tag = "description";
last SWITCH;
}
if ($element eq "coordinates") {
$tag = "coordinates";
last SWITCH;
}
}
}
sub endElement {
my ($parseinst, $element, %attrs) = @_;
$tag ="";
SWITCH: {
if ($element eq "Placemark") {
$output = "<lm:landmark>
<lm:name>$name</lm:name>
<lm:description>$description</lm:description>
<lm:coordinates>
<lm:latitude>$coordinates[1]</lm:latitude>
<lm:longitude>$coordinates[0]</lm:longitude>
</lm:coordinates>
</lm:landmark>\n";
print LMX $output;
$output = "";
last SWITCH;
}
}
}
sub charData {
my ($parseinst, $data) = @_;
if ($tag eq "name") {
$name = $data;
}
if ($tag eq "description") {
$description = $data;
}
if ($tag eq "coordinates") {
@coordinates = split(/,/,$data);
}
}
my $KMLFile = $ARGV[0];
my $LMXFile = "plop.lmx";
my $p = XML::Parser->new();
$p->setHandlers (
Start => \&startElement,
End => \&endElement,
Char => \&charData
);
open ( LMX, "> $LMXFile");
print LMX '<?xml version="1.0" encoding="UTF-8"?>
<lm:lmx xmlns:lm="http://www.nokia.com/schemas/location/landmarks/1/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nokia.com/schemas/location/landmarks/1/0/lmx.xsd">
<lm:landmarkCollection>';
$p->parsefile($KMLFile);
print LMX '</lm:landmarkCollection>
</lm:lmx>';
close (LMX);
Par xeo
Dernière modification
28/08/2007 16:09