GPSカメラ55 からエクスポートした KML/KMZ を後処理する方法
このページでは、GPSカメラ55 からエクスポートした KML/KMZ ファイルを、外部ツールでさらに扱いやすくするための後処理の例を紹介します。
特に次のような場面で役立ちます。
- エクスポート後にプレースマーク名を整えたい
- Google Earth や QGIS で見やすい KML にしたい
- エクスポートしたデータを独自のワークフローに合わせて調整したい
準備:
- GPSカメラ55 からエクスポート:ポイントを KMZ/KML としてエクスポートします。
- KML を取り出す:必要に応じて KMZ を解凍します。
imageNotes から KML プレースマーク名を更新する
このガイドでは、imageNotes フィールドから情報を抽出して、KML ファイルのプレースマーク名を自動更新する方法を示します。
概要
GPSカメラ55 からポイントをエクスポートすると、アプリは写真やポイントのタイトルに基づいた <name> を持つプレースマークを KML に書き出します。メモの内容(「Note 1」「Note 2」など)は、タブ区切りの値として imageNotes フィールドに格納されます。このスクリプトを使うと、その中からメモを抽出し、必要に応じてプレースマーク名として利用できます。
もっとも手軽なのは、撮影時に重要な情報をタイトルに入れておくことです。このスクリプトは、そうしていなかった場合や、KML の後処理の具体例が知りたい場合に役立ちます。
ユースケース
前:
- プレースマーク名にタイムスタンプが入っている:
15Nov25 16:25、12Nov25 17:24 - 実際のメモは
imageNotesフィールドに隠れている:Note 1、Note 2
後:
- プレースマーク名に意味のあるメモが表示される:
Note 1、Note 2 - マッピングアプリで一目でポイントを識別できる
KML ファイルの構造
エクスポートされた KML ファイルには、次の構造のプレースマークが含まれています。
<Placemark>
<name>15Nov25 16:25</name>
<ExtendedData>
<SchemaData schemaUrl="#blcPointSchema">
<SimpleData name="imageNotes"><![CDATA[15Nov25 16:25 Note 1 Ad-hoc V Třešňovce 227/12...]]></SimpleData>
</SchemaData>
</ExtendedData>
<Point>
<coordinates>14.502834,50.095184,239.0</coordinates>
</Point>
</Placemark>
imageNotes フィールドはタブ区切りの値で構成されています。
- フィールド 0:タイムスタンプ(
15Nov25 16:25) - フィールド 1:メモのテキスト(
Note 1)← ここを抽出します - フィールド 2:空
- フィールド 3:タイプ(
Ad-hoc) - フィールド 4:住所
解決策:Python スクリプト
KML ファイルを自動的に処理し、imageNotes の内容に基づいてプレースマーク名を更新する Python スクリプトを用意しました。
スクリプトの機能
- 自動抽出:タブ区切りの
imageNotesフィールドを解析します。 - 位置指定:フィールド内の特定の位置からメモを抽出します(既定では位置 1)。
- 汎用:この構造に従う任意の KML ファイルで動作します。
- 安全:ファイルを上書きする前にバックアップを作成します。
- 柔軟:新しいファイルに書き出すことも、その場で更新することもできます。
仕組み
- KML ファイルを解析:XML 構造を読み取ります。
- プレースマークを探す:すべての
<Placemark>要素を取得します。 - メモを抽出:
imageNotesをタブで分割し、位置 1 のメモを取り出します。 - 名前を更新:
<name>要素を、抽出したメモで完全に置き換えます。 - 出力を保存:更新した KML をファイルに書き出します。
インストールと使い方
前提条件
- Python 3(macOS にはプリインストール。Windows の場合は python.org からダウンロード)
- 追加ライブラリは不要です(標準ライブラリのみ使用)。
手順
1. スクリプトをダウンロード
update_kml_names.py をダウンロードし、対象の KML ファイルと同じフォルダに置きます。
2. スクリプトを実行
macOS/Linux:
# KMLファイルのあるフォルダへ移動
cd ~/Downloads/Points_20251115_163211
# 実行(バックアップを作成したうえで元ファイルを更新)
python3 update_kml_names.py doc.kml
# あるいは、元ファイルを残して別ファイルに出力
python3 update_kml_names.py doc.kml updated_points.kml
Windows:
# KMLファイルのあるフォルダへ移動
cd %USERPROFILE%\Downloads\Points_20251115_163211
# 実行(バックアップを作成したうえで元ファイルを更新)
python update_kml_names.py doc.kml
# あるいは、元ファイルを残して別ファイルに出力
python update_kml_names.py doc.kml updated_points.kml
3. 結果を確認
スクリプトは更新内容を出力します。
Updated: '15Nov25 16:25' -> 'Note 1'
Updated: '12Nov25 17:24' -> 'Note 2'
Completed! Updated 2 placemark(s).
Output saved to: doc.kml
応用
メモの位置を変える
imageNotes フィールドの構造が異なり、メモの位置が別の場所にある場合は、位置を指定できます。
# 位置2(3番目のフィールド、0から数える)からメモを抽出
python3 update_kml_names.py doc.kml output.kml 2
一括処理
複数の KML ファイルを一度に処理する簡単なスクリプト例です。
macOS/Linux:
for file in *.kml; do
python3 update_kml_names.py "$file"
done
Windows(PowerShell):
Get-ChildItem -Filter *.kml | ForEach-Object {
python update_kml_names.py $_.Name
}
例:処理前後
処理前
<Placemark>
<name>15Nov25 16:25</name>
<SimpleData name="imageNotes">15Nov25 16:25 Note 1 Ad-hoc Address...</SimpleData>
</Placemark>
<Placemark>
<name>12Nov25 17:24</name>
<SimpleData name="imageNotes">12Nov25 17:24 Note 2 Ad-hoc Address...</SimpleData>
</Placemark>
処理後
<Placemark>
<name>Note 1</name>
<SimpleData name="imageNotes">15Nov25 16:25 Note 1 Ad-hoc Address...</SimpleData>
</Placemark>
<Placemark>
<name>Note 2</name>
<SimpleData name="imageNotes">12Nov25 17:24 Note 2 Ad-hoc Address...</SimpleData>
</Placemark>
技術的な詳細
実装
スクリプトは Python 組み込みの XML パーサー(xml.etree.ElementTree)を使用しています。
- 適切な名前空間処理で KML ファイルを解析
- XML 構造をたどってプレースマーク要素を探索
- タブ区切り値の抽出と加工
- ファイル構造を保ったまま要素を更新
互換性
- KML バージョン:2.2(標準形式)
- Python バージョン:3.6 以上
- OS:macOS、Windows、Linux
- アプリ:Google Earth、QGIS、ArcGIS など、KML に対応するアプリケーションと互換性があります。
トラブルシューティング
問題:スクリプトが見つからない
原因: Python がインストールされていないか、システム PATH に含まれていません。
解決策:
- macOS:Python 3 は通常プリインストールされています。
- Windows: python.org からダウンロードし、インストール時に「Add to PATH」のチェックを忘れずに付けてください。
問題:更新後に名前が空になる
原因: メモフィールドが空か、期待と異なる位置にあります。
解決策: スクリプトは警告を表示します。imageNotes の形式を確認し、位置パラメータを調整してください。
ワークフローへの組み込み
このスクリプトは、自動化ワークフローの一部として組み込めます。
- GPSカメラ55 からエクスポート:ポイントを KMZ/KML としてエクスポート
- KML を取り出す:必要に応じて KMZ を解凍
- スクリプトを実行:KML を処理して名前を更新
- GIS に読み込む:Google Earth、QGIS、その他のツールで利用
ソースコード
#!/usr/bin/env python3
"""
Script to update KML placemark names with Note from imageNotes field.
Extracts the note from the tab-separated imageNotes field (position 2) and replaces the placemark name.
"""
import xml.etree.ElementTree as ET
import sys
import os
def update_kml_with_notes(input_file, output_file=None, note_position=1):
"""
Update KML placemark names by extracting Note from tab-separated imageNotes field.
Args:
input_file: Path to input KML file
output_file: Path to output KML file (if None, overwrites input)
note_position: Position of the note in tab-separated imageNotes (0-indexed, default 1)
"""
# Parse the KML file
tree = ET.parse(input_file)
root = tree.getroot()
# Define namespace
ns = {'kml': 'http://www.opengis.net/kml/2.2'}
# Find all Placemark elements
placemarks = root.findall('.//kml:Placemark', ns)
updated_count = 0
for placemark in placemarks:
# Get the current name
name_elem = placemark.find('kml:name', ns)
if name_elem is None:
continue
current_name = name_elem.text
# Find the imageNotes field
image_notes_elem = placemark.find('.//kml:SimpleData[@name="imageNotes"]', ns)
if image_notes_elem is not None and image_notes_elem.text:
image_notes = image_notes_elem.text
# Split by tab to get the note (tab-separated format)
parts = image_notes.split('\t')
if len(parts) > note_position and parts[note_position].strip():
note_text = parts[note_position].strip()
# Update the name - replace entirely with the note
name_elem.text = note_text
print(f"Updated: '{current_name}' -> '{note_text}'")
updated_count += 1
else:
print(f"Warning: No note found at position {note_position} in imageNotes for placemark '{current_name}'")
print(f" imageNotes content: {image_notes}")
else:
print(f"Warning: No imageNotes found for placemark '{current_name}'")
# Determine output file
if output_file is None:
output_file = input_file
# Write the updated KML
tree.write(output_file, encoding='utf-8', xml_declaration=True)
print(f"\nCompleted! Updated {updated_count} placemark(s).")
print(f"Output saved to: {output_file}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python3 update_kml_names.py <input_kml_file> [output_kml_file] [note_position]")
print("\nArguments:")
print(" input_kml_file: Path to the KML file to process")
print(" output_kml_file: (Optional) Output file path. If not provided, input will be overwritten.")
print(" note_position: (Optional) 0-indexed position of note in tab-separated imageNotes (default: 1)")
print("\nExample:")
print(" python3 update_kml_names.py doc.kml")
print(" python3 update_kml_names.py doc.kml doc_updated.kml")
print(" python3 update_kml_names.py doc.kml doc_updated.kml 1")
sys.exit(1)
input_file = sys.argv[1]
output_file = sys.argv[2] if len(sys.argv) > 2 else None
note_position = int(sys.argv[3]) if len(sys.argv) > 3 else 1
if not os.path.exists(input_file):
print(f"Error: Input file '{input_file}' not found.")
sys.exit(1)
# Create backup if overwriting
if output_file is None:
backup_file = input_file + '.backup'
import shutil
shutil.copy2(input_file, backup_file)
print(f"Backup created: {backup_file}\n")
update_kml_with_notes(input_file, output_file, note_position)
サポート
ご不明な点やトラブルが発生した場合:
- Python 3 が正しくインストールされているかご確認ください。
imageNotesがタブ区切りの値であることをご確認ください。
ライセンス
このスクリプトは、本アプリのエクスポートと組み合わせて利用いただくことを想定し、現状のまま提供しています。個別のニーズに合わせて自由に改変してお使いください。
関連ドキュメント
エクスポートとインポート
- 写真/ポイントの共有オプション — KMZ、KML、GPX、CSV 形式でポイントをエクスポートする方法
- コレクションでポイントを整理する — エクスポート前のデータ構造を理解するために
Google Earth での作業
- Google Earth 上の KMZ の調整・カスタマイズ — バルーンスタイルのカスタマイズや、生の KML へのアクセス方法
関連するワークフロー
- バッチエクスポート向けのファイル名カスタマイズ — バッチ処理スクリプトで扱いやすいファイル名を
- ワークフロー自動化のための設定バックアップ — ワークフロープロファイルをプログラム的に管理
- 位置情報付き写真のインポート — エクスポート/処理/インポートのループを完結させる
最終更新:2025 年 11 月