#!/usr/bin/perl # create_kml.pl # # Generates .kml nodemapfile for google earth/map # # Example of how to link to output: # http://maps.google.com/maps?q=http://svn.wirelessleiden.nl/svn/projects/genesisID/wl_nodes.kml # # Called from node_list.sh # $scriptname="create_kml.pl"; $author ="Ous"; $versionstring="0.1"; $versiondate="06Jun07"; # License: WL # # History: # ver: date: Desc: # 0.1 07jun07 Initial attempt, split from convert_nodecoords.pl # # Todo: # node master_ip in descriptor # figure out google maps icon control # interlink activity representation # # Known issues: # Google maps complains about "parts of could not be displayed because it is too large # bug or sizelimiting feature? # ======================================================================================== $coord_file = "./node_coords_converted.txt"; $link_coordinates="./linkcoords_list.txt"; $link_trafic="./simtraf.txt" $klm_outputfile = "./wl_nodes.kml"; #===========Main======= &initialize_stuff; &kml_header; &process_nodelist; &process_linklist; &kml_footer; exit; #====================== #======================= sub initialize_stuff { $date= localtime; print "$date\n"; ($dat_weekday, $dat_month, $dat_day, $dat_time, $dat_year)= split(/\s+/,$date); $lastchange="$dat_day $dat_month $dat_year"; open (NODELIST,$coord_file) or die "Cant't open $coord_file"; open (LINKLIST,$link_coordinates) or die "Can't find $link_coordinates"; open (KMLFILE,">$klm_outputfile") or die "Can't open $klm_outputfile for writing"; open (LINKTRAF,"$link_trafic") or die "Can't open $link_trafic"; } #======================= #======================= sub process_nodelist { while($line=) { chomp($line); if ($line !~ /^#/) { # my(@listline)=(@listline,@line); ($nodename, ,$nodestatus, $master_ip, $RDX, $RDY, $lon, $lat) = split(/\t/,$line); $nodename =~ s/\s.+//; &kml_body_nodes; } } close(NODELIST); } #=======================i #======================= sub process_linklist { while($line=){ chomp($line); if ($line !~ /^#/) { ($nodefrom,$nodeto,$fromRDXY,$toRDXY,$from_longlat,$to_longlat)=split(/\t+/,$line); if ($from_longlat>0 and $to_longlat>0) { &kml_body_links ; } }#fi }#elihw close (LINKLIST); } #======================= #======================= sub kml_header { print KMLFILE "\<\?xml version\=\"1.0\" encoding\=\"UTF-8\"\?\>\n"; print KMLFILE "\\n"; print KMLFILE "\\n"; print KMLFILE " \Wireless Leiden Nodemap\<\/name\>\n"; print KMLFILE " \Generated from Genesis data on $lastchange:$dat_time by $scriptname ver.$versionstring auth:$author\<\/description\>\n"; } #======================= #======================= sub kml_body_nodes { print KMLFILE "\n\\n"; if ( $nodestatus =~ /planned/) { &kml_style_planned }; if ( $nodestatus =~ /down/) { &kml_style_down }; print KMLFILE " \$nodename\<\/name\>\n"; print KMLFILE " \status:$nodestatus\<\/description\>\n"; print KMLFILE " \\n"; print KMLFILE " \$lon,$lat,0\<\/coordinates\>\n"; print KMLFILE " \<\/Point\>\n"; print KMLFILE "\<\/Placemark\>\n"; } #======================= sub kml_body_links { print KMLFILE "\n\\n"; print KMLFILE " \Interlink $nodefrom - $nodeto\<\/name\>\n"; print KMLFILE " \Interlink $nodefrom - $nodeto\<\/description\>\n"; print KMLFILE " \\n"; print KMLFILE " \\n"; print KMLFILE " \99ff0000\<\/color\>\n"; print KMLFILE " \5\<\/width\>\n"; print KMLFILE " \<\/LineStyle\>\n"; print KMLFILE " \<\/Style\>\n"; print KMLFILE " \\n"; print KMLFILE " \$from_longlat,0 $to_longlat,0\<\/coordinates\>\n"; print KMLFILE " \<\/LineString\>\n"; print KMLFILE "\<\/Placemark\>\n"; } #======================= sub kml_footer { print KMLFILE "\<\/Document\>\n"; print KMLFILE "\<\/kml\>\n"; close(KMLFILE) } #======================= #======================= sub kml_style_planned { print KMLFILE "\n \\n"; print KMLFILE " \<\IconStyle\>\n"; print KMLFILE " \\n"; print KMLFILE " \root\:\/\/icons\/palette\-3\.png\<\/href\>\n"; print KMLFILE " \64\<\/x\>\n"; print KMLFILE " \32\<\/y\>\n"; print KMLFILE " \32\<\/w\>\n"; print KMLFILE " \32\<\/h\>\n"; print KMLFILE " \<\/Icon\>\n"; print KMLFILE " \<\/IconStyle\>\n"; print KMLFILE " \<\/Style\>\n\n"; } #======================= #======================= sub kml_style_down { print KMLFILE "\n \\n"; print KMLFILE " \<\IconStyle\>\n"; print KMLFILE " \\n"; print KMLFILE " \root\:\/\/icons\/palette\-3\.png\<\/href\>\n"; print KMLFILE " \64\<\/x\>\n"; print KMLFILE " \64\<\/y\>\n"; print KMLFILE " \32\<\/w\>\n"; print KMLFILE " \32\<\/h\>\n"; print KMLFILE " \<\/Icon\>\n"; print KMLFILE " \<\/IconStyle\>\n"; print KMLFILE " \<\/Style\>\n\n"; } #======================= #======================= sub round { my($number) = shift; return int($number + .5 * ($number <=> 0) ); } #======================= #=======================