[OSGeoJapan-discuss] ジオタグだけをファイル間でコピーするには?

Yoshio MISHIMA shamrock @ for.agr.hokudai.ac.jp
2016年 5月 6日 (金) 00:47:32 PDT


奈佐原様

三島です。

連休につきしばしチェックしておりませんでした。

> 組み込んで作ったシェルスクリプトをお送りします。

たいへん便利そうですね。
たまにこの手を作業をすることがありますので助かります。
ありがとうございます。

すこしズレたお答えであることは承知していますが
動画の撮影には最近 garmin の virb xeを使っています。
GPS情報の取得はさすがに早いです。
(静止画も撮影できますが評価できるほど使っていません)
個人的にRICOHのGRにGPSがついていたらよいな、と思っています。

ではでは。

2016年5月4日 15:42 奈佐原(西田)顕郎 <24dakenlo @ gmail.com>:
> 皆様:
>
> この件、ご報告ということで, 教えていただいたコマンドを
> 組み込んで作ったシェルスクリプトをお送りします。
>
> 当方, GPSカメラはCASIOのEX-H20Gを使っておりまして,
> これはGPS性能が抜群に良い(電車の車窓から撮っても
> 良い精度で記録される)のと, 方位センサーで撮影方位も
> 記録されるのが良いのですが, いかんせんカメラとしては
> かなり古いモデルで(製造中止)、今時のカメラには画質で
> 全く敵いません。そこで, 本命の写真は別の高画像品質の
> デジカメで撮り、間髪入れずにほぼ同じ画角でEX-H20Gでも
> 撮る(GPSと撮影方位の記録のために)ということを
> やっております。そのために, 後者から前者へのジオタグの
> コピーが必要だった, というわけです。
>
> 「そんなことしなくてもこの機材を使えば十分イケルよ」
> みたいなご助言がありましたら、ぜひお聞かせ下さい。
>
> このたびのこと、重ねて御礼申し上げます。
>
> 筑波大・奈佐原
>
>
> #!/bin/sh
> # dc_copy_GPS.sh
> # copy geotags (Exif GPS tag group) from one image to another.
> # use: $ dc_copy_GPS.sh file1.jpg file2.jpg
> #   It works only if either one of file1.jpg or file2.jpg is with GPS tags,
> and
> #   another one does not have GPS geotags. You don't care about which is
> which.
> #   This program automatically detects which one should be the source.
> #   If both already have GPS tags, or both have no GPS tags, this program
> does nothing.
> # note: This program works in Ubuntu Linux 16.04.
> # note: You should install exiftool.
> # 2016/05/04 Kenlo Nishida Nasahara
>
> # maximum time difference in second. You may want to change this:
> timediff_max=8
>
> file1=$1
> file2=$2
>
> # Flags whether GPS tags exist or not in each file.
> if [ `exiftool $file1 | grep GPS | wc -l` -gt 0 ]; then GPS1=1; else GPS1=0;
> fi
> if [ `exiftool $file2 | grep GPS | wc -l` -gt 0 ]; then GPS2=1; else GPS2=0;
> fi
>
> # Exit if both files have no GPS tags
> if [ `echo $GPS1 + $GPS2 | bc` -eq 0 ]; then
>  echo "No change was done because both $file1 and $file2 have no GPS tags."
>  exit
> fi
>
> # Exit if both files have GPS tags
> if [ `echo $GPS1 + $GPS2 | bc` -eq 2 ]; then
>  echo "No change was done because both $file1 and $file2 already have GPS
> tags."
>  exit
> fi
>
> # Go beyond if one file has GPS tags and another file does not have GPS
> tags.
>
> # Get timing of the shot in seconds since 1970-01-01 00:00:00
> time1=`exiftool -createdate -d %s $file1 | awk '{print $NF}'`
> time2=`exiftool -createdate -d %s $file2 | awk '{print $NF}'`
>
> # Get (absolute value of) difference in seconds between file1 and file2
> timediff=`echo $time1 $time2 | awk '{print sqrt(($1-$2)*($1-$2))}'`
>
> # Exit if $timediff is more than the limit
> if [ $timediff -gt $timediff_max ]; then
>  echo "No change was done because too big time difference in $file1 and
> $file2 (timediff=${timediff}sec > ${timediff_max}sec)."
>  exit
> fi
>
> # Decide which is the source file (fromfile) and which is the destination
> file (tofile).
> if [ $GPS1 -eq 1 ] && [ $GPS2 -eq 0 ]; then
>  fromfile=$file1; tofile=$file2
> else
>  fromfile=$file2; tofile=$file1
> fi
>
> # Copy geotags!
> exiftool -tagsfromfile $fromfile -gps:all -comment="GPS tags copied from
> $fromfile" -overwrite_original -P $tofile
> if [ $? -eq 0 ]; then
>   echo "GPS tags of $fromfile was copied to $tofile (timediff=${timediff}sec
> <= ${timediff_max}sec)"
> fi
>
>
> 2016年5月4日 8:22 奈佐原(西田)顕郎 <24dakenlo @ gmail.com>:
>
>> 古田様・三島様・みなさま:
>>
>> ありがとうございます! 三島様のコマンド、まさしくそれが
>> 知りたかったのです! いやあ、これは思いつかなかった。
>> 私のマニュアルの読み込みが足りないのだと思います。
>> 本当に助かりました。
>>
>> 古田様も、お知恵をお貸しくださり、本当にありがとうございました!
>>
>> 筑波大・奈佐原
>>
>>
>>
>>
>>
>>
>> 2016年5月4日 0:08 Yoshio MISHIMA <shamrock @ for.agr.hokudai.ac.jp>:
>>
>>> 奈佐原さま
>>> 皆さま
>>>
>>> 三島です。
>>>
>>> 作業ログをみてみると
>>> 昔のわたしがこんなことをやってました。
>>>
>>> exiftool -tagsFromFile src.jpg -gps:all dst.jpg
>>>
>>> お試しください。
>>> GPSタグのみ書き換えられると思います。
>>>
>>> 三島啓雄@NIES
>>>
>>> 2016年5月3日 14:33 Takeshi FURUTA MQSOL LLC <furuta @ mq-sol.jp>:
>>> > 古田です。
>>> >
>>> > Bash上で以下のシェルを作って
>>> >
>>> > ----gpscopy.sh
>>> > #!/bin/bash
>>> >
>>> > # latitude 取得
>>> > lat=`exiftool $1|grep "GPS Latitude"|awk -F: '{print $2}'`
>>> > # longitude取得
>>> > lon=`exiftool $1|grep "GPS Longitude"|awk -F: '{print $2}'`
>>> >
>>> > #GPSセット
>>> > exiftool -GPSLatitude="$lat" -GPSLongitude="$lon" $2
>>> > -- ここまで
>>> >
>>> > gpscopy.sh src.jpg dst.jpg
>>> >
>>> > みたいにしたらどうでしょうか。もっとスマートに出来そうですけど。
>>> >
>>> > では
>>> >
>>> > On Tue, 3 May 2016 13:21:26 +0900
>>> > 奈佐原(西田)顕郎 <24dakenlo @ gmail.com> wrote:
>>> >
>>> >> 高橋様:
>>> >>
>>> >> ありがとうございます。実はこの記事も参考に
>>> >> したのですが、このように中間ファイル等を使うのではなく,
>>> >> シンプルにコマンド一発でできないものかと考えまして、
>>> >> もしそのようなやり方をご存知でしたら。。。
>>> >>
>>> >> exiftoolは, 相当いろんなオプションがあっていろいろ
>>> >> できそうなので、こんなシンプルなことができないはずが
>>> >> ないと思うのです。。。
>>> >>
>>> >> 奈佐原
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >> 2016年5月3日 13:01 Takahashi Y. <alpha234zero @ gmail.com>:
>>> >>
>>> >> > 奈佐原さま
>>> >> >
>>> >> > exiftool使ったことありませんが、以下のような記事は参考になるでしょうか。
>>> >> >
>>> >> > http://d.hatena.ne.jp/haru-kichi/20101104/p1
>>> >> >
>>> >> > 「exiftool ジオタグ」でグーグルトップに出てくる記事ですので既にご存じかもしれませんが参考になれば幸いです。
>>> >> >
>>> >> > 高橋
>>> >> >
>>> >> > 2016年5月3日 12:45 奈佐原(西田)顕郎 <24dakenlo @ gmail.com>:
>>> >> > > かやまさま、ありがとうございます。ひとつは、GUIでなくCUIでやりたい
>>> >> > > こと(特に, シェルスクリプトに組み込みたい)、また、環境やバージョン
>>> >> > > によらずにシンプルに実装したいこと、というのがありまして、できれば
>>> >> > > コマンド一発でやれれば嬉しい、と思っております。奈佐原
>>> >> > >
>>> >> > > 2016年5月3日 11:56 Yoichi Kayama <yoichi.kayama @ gmail.com>:
>>> >> > >>
>>> >> > >> 奈佐原先生
>>> >> > >>
>>> >> > >> かやまです。
>>> >> > >>
>>> >> > >>
>>> >> > >> ジオとオープンソースに関連する話題ならばとりあえずここにふっていただいて大丈夫です。答えられる人がいるかどうかはというのはありますが。
>>> >> > >>
>>> >> > >> Exiftoolは使ったことあります。
>>> >> > >> いろんなオプションあったと思います。
>>> >> > >>
>>> >> > >> 今、外出中なので帰宅したらみてみます。
>>> >> > >>
>>> >> > >> Exifデータを書き込むだけなら、その他にも色々ツールあるみたいです。
>>> >> > >>
>>> >> > >> 取得と書き込みを分けてやるという手段もあると思います。
>>> >> > >>
>>> >> > >> 2016/05/03 11:43 "奈佐原(西田)顕郎" <24dakenlo @ gmail.com>:
>>> >> > >>
>>> >> > >> OSGeoのみなさま:
>>> >> > >>
>>> >> > >> 皆様にはGWをお楽しみのところ、失礼します。
>>> >> > >>
>>> >> > >> exiftoolコマンドなどを使って, file1.jpgのGPS情報(ジオタグ)だけ
>>> >> > >> をfile2.jpgにコピーしたい(file1.jpgとfile2.jpgは同じ場所で
>>> >> > >> 撮ったけどfile2.jpgにはジオタグがついてないため), という
>>> >> > >> とき, どのようなコマンド(Linux)でできますでしょうか?
>>> >> > >>
>>> >> > >> いろいろしらべて, 例えば下記のコマンドをやってみたのですが,
>>> >> > >> $ exiftool -GPS* -TagsFromFile file1.jpg file2.jpg
>>> >> > >> Ignored superfluous tag name or invalid option: -GPS*
>>> >> > >> というエラーメッセージが出て, なおかつ, ジオタグだけでなく
>>> >> > >> 全てのexif情報がコピー(上書き)されてしまいます...
>>> >> > >>
>>> >> > >> また, こういうコネタ的な質問は, そもそもこのMLでOKでしょうか?
>>> >> > >> (NGな場合, 「こっちでどう?」みたいなご助言を頂けると幸いです)
>>> >> > >>
>>> >> > >> 筑波大・奈佐原顕郎
>>> >> > >>
>>> >> > >> _______________________________________________
>>> >> > >> OSGeoJapan-discuss mailing list
>>> >> > >> OSGeoJapan-discuss @ lists.osgeo.org
>>> >> > >> http://lists.osgeo.org/mailman/listinfo/osgeojapan-discuss
>>> >> > >
>>> >> > >
>>> >> > >
>>> >> > > _______________________________________________
>>> >> > > OSGeoJapan-discuss mailing list
>>> >> > > OSGeoJapan-discuss @ lists.osgeo.org
>>> >> > > http://lists.osgeo.org/mailman/listinfo/osgeojapan-discuss
>>> >> > _______________________________________________
>>> >> > OSGeoJapan-discuss mailing list
>>> >> > OSGeoJapan-discuss @ lists.osgeo.org
>>> >> > http://lists.osgeo.org/mailman/listinfo/osgeojapan-discuss
>>> >> >
>>> >
>>> > ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
>>> > 合同会社 マップクエストソリューションズ
>>> >  ( http://mq-sol.jp/>>> > 代表 古田 武士 ( furuta @ mq-sol.jp )
>>> > 住所: 〒331-0013 埼玉県戸田市喜沢1−33−8
>>> >           ベルテラス板橋202
>>> > 電話: 03-5843-5923 携帯:090-8985-1587
>>> > FAX:  048-229-0554
>>> > ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
>>> >
>>> >
>>> > _______________________________________________
>>> > OSGeoJapan-discuss mailing list
>>> > OSGeoJapan-discuss @ lists.osgeo.org
>>> > http://lists.osgeo.org/mailman/listinfo/osgeojapan-discuss
>>>
>>>
>>>
>>> --
>>> 三島 啓雄 (MISHIMA Yoshio)
>>> ------------------------------------------
>>> 北海道大学農学研究院
>>> 環境資源学部門 森林管理保全学分野
>>> 森林生態系管理学研究室 学術研究員
>>> 〒060-8589 札幌市北区北9条西9丁目
>>> TEL & FAX: 011-706-2515
>>> shamrock @ for.agr.hokudai.ac.jp
>>> ------------------------------------------
>>> _______________________________________________
>>> OSGeoJapan-discuss mailing list
>>> OSGeoJapan-discuss @ lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/osgeojapan-discuss
>>
>>
>
>
> _______________________________________________
> OSGeoJapan-discuss mailing list
> OSGeoJapan-discuss @ lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/osgeojapan-discuss



-- 
三島 啓雄 (MISHIMA Yoshio)
------------------------------------------
北海道大学農学研究院
環境資源学部門 森林管理保全学分野
森林生態系管理学研究室 学術研究員
〒060-8589 札幌市北区北9条西9丁目
TEL & FAX: 011-706-2515
shamrock @ for.agr.hokudai.ac.jp
------------------------------------------


OSGeoJapan-discuss メーリングリストの案内