use strict; use warnings; use utf8; use Encode qw(from_to encode decode is_utf8 encode_utf8); use Encode::Guess qw/shift-jis euc-jp 7bit-jis/; # ========================================================================= # 設定ファイル # ================================================================================ my $ver = 01;# スクリプトのバージョン my $icon = '' ;# アイコンの名前 # ture の設定 ==================================================================== my $heading_L_R = '0' ;# 直進[0]:右から左を見る[R] :左から右を見る[L] my $flug_line = 1 ;# ライン(線)を描く[1] :描かない[0] my $flug_place = 1 ;# ポントをマークする[1] :しない[0] my $flug_ture = 1 ;# ツアーをする[1] :しない[0] my $range = 0 ;# altitude に足される my @levelmode = ('relativeToGround','clampToGround','absolute','relativeToSeaFloor','clampToSeaFloor'); ;# 0 , 1 2 3 4 my $gx_altitudeMode_no = 0 ;# comment2 = ('relativeToGround','clampToGround','absolute','relativeToSeaFloor','clampToSeaFloor'); # 0:relativeToGround : の値を地面からのメートル単位の距離 # 1:clampToGround : の指定を無視して Camera の位置を地面に設定 # 2:absolute : の値を海面からのメートル単位の距離 # 3:relativeToSeaFloor : 値を海底(又は地上)からのメートル単位の高さ # 4:clampToSeaFloor : の指定を無視し、Camera を海底上に配置 my $gx_altitudeMode = $levelmode[$gx_altitudeMode_no]; my $altitude = 2500;# 高度 my $tilt = 75;# 伏角、下が[0] :近くをみるなら30度:遠くをみるなら80度くらい my $back2_2 = 0.5;# 高度と伏角が大きいと離れ過ぎてしまうので、離れる距離を小さくする # 赤道での全周が40077km: # 1度は 40,077km /360度 = 約111,325 m: # 0.1 度 = 約 11,132 m: # 0.01 度 = 約 1,113 m: # 0.0001度 = 約 11 m: # 1 秒 = 約 31 m: # line の 設定 ========================================================================== my $line_cut = 30;# ラインのポイントがあまりに多い場合に間引く。もっと多い場合は、増やす # kmlの作成モードの取り込み=================================== my $make_kml_mode = "init";# make_kml_mode [init== normal][data == data依存][stvi == streetview_mode] my $open = 1; # 0:データを畳み込む; 1:データを展開する # 設定ファイル終了======================================================================== # ファイルの読み込み=================================== opendir(DRC,".");my @f_s = grep(/_u_place\.txt/i,readdir(DRC));closedir(DRC); my @f_u; @f_u = map(decode("shift-jis",$_),@f_s); if((@f_s) == 0) { print encode("sjis","[データが見当たりません!]\n終了します!!!");; exit; } else { print encode("sjis","[@f_u]を処理します。[改行]");; foreach my $data_s (@f_s) { my (@line,@place,@ture); @line = @place = @ture = (); open(IN,"< $data_s");while() {next if /^ *#/;push(@place,$_);}close(IN); @line = @ture = @place; # 出力ファイルの生成 my $out_name_s = $data_s; if ($out_name_s =~ /_place\.txt/i) {$out_name_s =~ s/_place\.txt/_place_$ver\.kml/i; } if ($make_kml_mode =~ /init/) {$out_name_s =~ s/\.kml/_init\.kml/i;} elsif($make_kml_mode =~ /data/) {$out_name_s =~ s/\.kml/_data\.kml/i;} elsif($make_kml_mode =~ /stvi/) {$out_name_s =~ s/\.kml/_street_view\.kml/i;} my $data_u_shori = decode("shift-jis",$data_s); my $out_name_u = decode("shift-jis",$out_name_s); open(OU,"> $out_name_s"); #================================================== # kml の処理 = #================================================== # kml ヘッダの出力 my %mark = (); my ($titole_s,$titole_u); $titole_s = $data_s; $titole_u = decode("shift-jis",$titole_s); if ($make_kml_mode =~ /init/) {$titole_u =~ s/\.txt/_initツアー/;} elsif($make_kml_mode =~ /data/) {$titole_u =~ s/\.txt/_dataツアー/;} elsif($make_kml_mode =~ /stvi/) {$titole_u =~ s/\.txt/_street viewツアー/;} &heder($titole_u,$icon); #================================================== # place & ture & line の処理 = #================================================== # ture と place の underwater_no 処理 if($flug_place == 1 && $flug_ture == 1) { my ($underwater_no_place,$no_place); my ($place,$point,$description,$long,$lat,$hight); my $place_last = $place[$#place]; $no_place = 0; foreach my $place (@place) { $no_place++; $underwater_no_place = "underwater" . $no_place; chomp($place); # print "place[#place]";; ($point,$description,$long,$lat,$hight) = split(",",$place); $mark{$point} = $underwater_no_place; } ($point,$description,$long,$lat,$hight) = split(",",$place_last); $no_place++; $underwater_no_place = "underwater" . $no_place; $mark{$point} = $underwater_no_place; } # ture back2 定数 の計算 ========================================================= # 高度と伏角によって、placeの[long]:[lat] から、どれだけカメラ視点の距離を離すかの計算 my $pi = atan2(1,1) * 4; my $sin1 = sin(((90 - $tilt) / 180) * $pi); my $cos1 = cos(((90 - $tilt) / 180) * $pi); my $tan1 = $sin1 / $cos1; my $atan1 = 1 / $tan1; my $back2m = $altitude * $atan1 * $back2_2;# [$back2_2]は設定ファイルに書かれた、割引数 my $back2 = ($back2m / 11 ) * 0.0001 ; # 0.0001度は =約 11 m # make_ture ======================================= #出発点の方向を進行方向に合わせる計算 my (@ture_old); my @ture_old0 = split(/,/,$place[0]); my @ture_old1 = split(/,/,$place[1]); $ture_old[0] = $ture_old[1] = ""; $ture_old[2] = $ture_old0[2] + ($ture_old0[2] - $ture_old1[2]); $ture_old[3] = $ture_old0[3] + ($ture_old0[3] - $ture_old1[3]); #print "@ture_old";; # #終点に到着した時に振返る計算 # push(@ture,$place[$#place -1 ]); # ture make begin ===================================== if($flug_ture == 1) { &ture_heder($titole_u); my ($point,$description,$long,$lat,$hight,$heading); my $no = 0; # print "ture_body[@ture]";; # &ture_begin($long,$lat,$altitude,$heading,$tilt,$range,$gx_altitudeMode,$no); # open(HOI,"> _houi.txt"); # 角度 方位 経度 緯度 foreach my $ture(@ture) { $no++; chomp($ture); my @ture2 = ($point,$description,$long,$lat,$hight) = split(",",$ture); # print "ture2[@ture2]";; if ($make_kml_mode =~ /init/) { ;} elsif($make_kml_mode =~ /data/) { $back2m = $hight * $atan1 * $back2_2;# [$back2_2]は設定ファイルに書かれた、割引数 $back2 = ($back2m / 11 ) * 0.0001 ; # 0.0001度は =約 11 m } elsif($make_kml_mode =~ /stvi/) {$back2 = (2.4 / 11 ) * 0.0001 ;} # $heading = ' # カメラの方位角 :0は真北:0~360度'; # place の角度とカメラの方位は違う(面倒だぁ~) # place の角度計算 my $x = $long - $ture_old[2]; my $y = $lat - $ture_old[3]; my $atan = atan2($y,$x) * 180 / $pi; # print "no1=[$no]:atan =[$atan]:";; if ($heading_L_R =~ /R/i) {$atan -= 90;} elsif ($heading_L_R =~ /L/i) {$atan += 90;} # print "no2=[$no]:atan =[$atan]:\n"; # 進行方向、後ろ側から見るように、place の long lat を加減算する my $atan2 = $atan / 180 * $pi; my $cos2 = cos($atan2) ; my $sin2 = sin($atan2) ; # print "atan2 = $atan2:cos=[$cos2]:sin=[$sin2]";; my $long2 = $back2 * $cos2; my $lat2 = $back2 * $sin2; # print HOI "long_old[$long]:lat_old[$lat]\n"; $long -= $long2;$lat -= $lat2; # print HOI "long_new[$long]:lat_new[$lat]\n"; # カメラの方位角の計算 if ($atan < -180 ) {$atan += 360;} # print "no3=[$no]:atan =[$atan]:\n"; elsif ($atan > 180 ) {$atan -= 360;} # print "no3=[$no]:atan =[$atan]:\n"; if ($atan >= -180 && $atan <= 90) {$heading = 90 - $atan ;} elsif ($atan > 90 && $atan <= 180) {$heading = 450 - $atan ;} # print "no4=[$no]:atan =[$atan]:heading[$heading]";; # elsif ($atan > 180 && $atan <= 360) {$heading = 360 - $atan + 90;} # print "no4=[$no]:atan =[$atan]:heading[$heading]";; #------------------------------------------------------------------------ #print "atan [$atan]:heading[$heading]";; if($heading eq "") {$heading = 0}; # print HOI "@ture2\n"; # print HOI "@ture_old\n"; # print HOI "x = $x : y = $y : atan = $atan : heading:$heading\n"; # print "x = $x : y = $y : atan = $atan : heading:$heading";; @ture_old = @ture2; if ($make_kml_mode =~ /init/i) { ;} elsif($make_kml_mode =~ /data/i) {$altitude = $hight;} elsif($make_kml_mode =~ /stvi/i) {$altitude = 2.4;} &ture_body($long,$lat,$altitude,$heading,$tilt,$range,$gx_altitudeMode,$mark{$point}); } $no++; if ($make_kml_mode =~ /init/) { ;} elsif($make_kml_mode =~ /data/) {$altitude = $hight;} elsif($make_kml_mode =~ /stvi/) {$altitude = 2.4;} &ture_futter($long,$lat,$altitude,$heading,$tilt,$range,$gx_altitudeMode,$mark{$point}); # print "[ture_END]";; } # line =============================================== # line の作成 = if($flug_line == 1) { my $file_count++; &line_heder($file_count); foreach my $line (@line) { # print "line[$line]";; chomp($line); # print "[$line]";; my @a = split(",",$line); # print "$line2[2],$line2[3],$line2[4]";; # print "$a[2],$a[3],$a[4]\n"; #; print OU "$a[2],$a[3],$a[4]\n"; # print OU "$line2[2],$line2[3],$line2[4]\n"; } &line_futter; # print "[line_END]";; } #================================================ # place = if($flug_place == 1) { my ($underwater_no_place,$no_place); my ($place,$point,$description,$long,$lat,$hight); my $place_last = pop(@place); $no_place = 0; foreach my $place (@place) { $no_place++; $underwater_no_place = "underwater" . $no_place; chomp($place); # print "place[#place]";; ($point,$description,$long,$lat,$hight) = split(",",$place); $mark{$point} = $underwater_no_place; &place_body_hedder1($underwater_no_place,$point,$description,$long,$lat,$hight,$icon); # if($point eq 1) { print "point[$point]";;} if($make_kml_mode =~ /stvi/) { &place_street_view( $point,$description,$long,$lat,$hight); } &place_body_hedder2($underwater_no_place,$point,$description,$long,$lat,$hight,$icon); # if($point eq 1) { print "point[$point]";;} &place_body_middle( $underwater_no_place,$point,$description,$long,$lat,$hight,$icon); # if($point eq 1) { print "point[$point]";;} &place_body_futter( $underwater_no_place,$point,$description,$long,$lat,$hight,$icon); # if($point eq 1) { print "point[$point]";;} } ($point,$description,$long,$lat,$hight) = split(",",$place_last); $no_place++; $underwater_no_place = "underwater" . $no_place; &place_futter($underwater_no_place,$point,$description,$long,$lat,$hight,$icon); # if($point eq 1) { print "point[$point]";;} } # kml フッタの出力 &futter; close(OU); } print encode("sjis","ファイルの処理は完了しました。「改行」を押してください");; } # sub ========================================================================================= # place ========================================================================================== sub place_body_hedder1 { my ($underwater_no_place,$point,$description,$long,$lat,$hight) = @_; # if($point eq 1) { print "point[$point]";;} my $point_u = decode("utf-8",$point); my $place_body = <$point_u EOF print OU encode("utf-8",$place_body); } sub place_street_view { my ($point,$description,$long,$lat,$hight) = @_; my $point_u = decode("utf-8",$point); my $place_street_view = < $long $lat 2.4 90 0 relativeToGround relativeToSeaFloor EOF print OU encode("utf-8",$place_street_view); } sub place_body_hedder2 { my ($underwater_no_place,$point,$description,$long,$lat,$hight) = @_; # if($point eq 1) { print "point[$point]";;} my $point_u = decode("utf-8",$point); my $description_u = decode("utf-8",$description); my $place_body = <

ここは[$point_u][$description_u]です。

EOF print OU encode("utf-8",$place_body); } sub place_body_middle { my ($underwater_no_place,$point,$description,$long,$lat,$hight) = @_; # if($point eq 1) { print "point[$point]";;} my $place_body; my $point_u = decode("utf-8",$point); my $description_u = decode("utf-8",$description); if($description_u =~ /jpg|png|bmp/) { # if($description =~ /jpg/) { $place_body = < EOF print OU encode("utf-8",$place_body); } elsif($description_u =~ /http:/) { $place_body = < ここをクリック>http://$point_u EOF print OU encode("utf-8",$place_body); } } sub place_body_futter { my ($underwater_no_place,$point,$description,$long,$lat,$hight,$icon) = @_; # if($point eq 1) { print "point[$point]";;} my $icon_name = $icon; $icon_name =~ s/\.[a-z]+$//; my $place_body = < #$icon_name relativeToGround$long,$lat,$hight EOF print OU encode("utf-8",$place_body); } sub place_futter { #my ($underwater_no_place,$point,$description,$long,$lat,$hight) = @_; # if($point eq 1) { print "point[$point]";;} my ($underwater_no_place,$point,$description,$long,$lat,$hight,$icon) = @_; # if($point eq 1) { print "point[$point]";;} my $icon_name = $icon; if($icon_name ne "") {$icon_name =~ s/\.[a-z]+$//;} else {$icon_name = "dumy";} print OU <$point1#$icon_name$long,$lat,$hight EOF } # sub ture ====================================================== sub ture_heder { my ($titole_u) = @_; my $ture_hedder = < $titole_u スタート EOF print OU encode("utf-8",$ture_hedder); } # ----- sub ture_begin { my ($long,$lat,$altitude,$heading,$tilt,$range,$gx_altitudeMode,$no) = @_; print OU < 8 smooth $long$lat$altitude$heading$tilt$range$gx_altitudeMode 0.01 3.0 0.00 EOF } # ----- sub ture_body { my ($long,$lat,$altitude,$heading,$tilt,$range,$gx_altitudeMode,$no) = @_; # print "heading[$heading]:sub ture_body_no[$no]";; print OU < 8 smooth $long$lat$altitude$heading$tilt$range$gx_altitudeMode 0.01 3.0 0.00 EOF } sub ture_futter { my ($long,$lat,$altitude,$heading,$tilt,$range,$gx_altitudeMode,$no) = @_; print OU <3smooth$long$lat$altitude$heading$tilt$range$gx_altitudeMode 0.01 3.0 EOF } # line ========================================================================================= sub line_heder { my ($file_count) = @_; # my $line_heder = <7f0000ff4 #linestyleExample 軌跡$file_count 1 1 EOF print OU encode("utf-8",$line_heder); } sub line_futter { print OU < EOF } # header & futter =============================================================================== sub heder { my ($titole_u,$icon) = @_; my $icon_name = $icon; $icon_name =~ s/\.[a-z]+$//; my $heder = < $titole_u $open EOF print OU encode("utf-8",$heder); } sub futter { print OU < EOF }