앱에서 내보낸 원본 kml/kmz 파일을 처리하는 예시
이 페이지는 유용할 수 있는 kmz/kml 파일 후처리 예시를 제공합니다.
준비:
- GPS 카메라에서 내보내기: KMZ/KML로 포인트 내보내기
- KML 추출: 필요시 KMZ 압축 해제
imageNotes에서 KML 표지판 이름 업데이트
이 가이드는 KML 파일의 표지판 이름을 imageNotes 필드에서 정보를 추출하여 자동으로 업데이트하는 방법을 보여줍니다.
개요
GPS 카메라에서 포인트를 내보낼 때, 앱은 사진 및 포인트 제목을 기반으로 표지판 이름을 포함하는 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:
# Navigate to the folder containing your KML file
cd ~/Downloads/Points_20251115_163211
# Run the script (creates backup, updates original)
python3 update_kml_names.py doc.kml
# Or create a new output file (keeps original)
python3 update_kml_names.py doc.kml updated_points.kml
Windows:
# Navigate to the folder containing your KML file
cd %USERPROFILE%\Downloads\Points_20251115_163211
# Run the script (creates backup, updates original)
python update_kml_names.py doc.kml
# Or create a new output file (keeps original)
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 필드의 구조가 다르고 노트가 다른 위치에 있는 경우, 위치를 지정할 수 있습니다:
# Extract note from position 2 (third field, 0-indexed)
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+
- 운영 체제: macOS, Windows, Linux
- 앱: Google Earth, QGIS, ArcGIS 및 기타 KML 지원 애플리케이션과 호환
문제 해결
문제: 스크립트를 찾을 수 없음
원인: Python이 설치되지 않았거나 시스템 PATH에 없음
해결 방법:
- macOS: Python 3이 미리 설치되어 있어야 함
- Windows: python.org 에서 다운로드하고 설치 시 “PATH에 추가” 체크
문제: 업데이트 후 빈 이름
원인: 노트 필드가 비어 있거나 잘못된 위치에 있음
해결 방법: 스크립트가 경고를 표시합니다. imageNotes 형식을 확인하고 위치 매개변수를 조정하세요.
워크플로우 통합
이 스크립트는 자동화된 워크플로우에 통합할 수 있습니다:
- GPS 카메라에서 내보내기: 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 파일을 Google Earth에서 사용자 정의, 풍선 스타일 및 원본 KML 접근
관련 워크플로우
- 일괄 내보내기를 위한 파일 이름 사용자 정의 - 일괄 처리 스크립트에서 파일 이름 자동화
- 워크플로우 자동화를 위한 설정 백업 - 프로그래밍 방식으로 워크플로우 프로파일 관리
- 위치 데이터가 있는 사진 가져오기 - 내보내기/처리/가져오기 워크플로우 완성
마지막 업데이트: 2025년 11월