R Code for Regional Analysis: Leaflet-based Mapping of Geotagged Photos with QGIS-ready Exports (PPGIS and Fieldwork Records) 地域分析のためのRコード:ジオタグ付き写真のLeaflet地図化とQGIS向け出力(PPGIS・フィールド記録)
Abstract
スマートフォンで撮影したジオタグ付き写真のフォルダから、EXIFの位置情報と撮影メタデータを読み取り、次の三つを出力するRスクリプトである。 Leafletの地図(HTML1ファイル。地点をクリックすると写真が表示される) 写真ごとの座標・撮影時刻・方位・水平誤差の一覧(CSV) 同じ内容の点レイヤ(GeoPackage。QGISで直接開ける) 研究プロトコル「Collaborative Spatial Visualization's Impact on Place Attachment: A Cluster Randomized Trial in Japan's Chita District」(SSRN 6536760)で構想した、住民が撮影した「お気に入りの場所」を地図化する参加型GIS(PPGIS)の道具として作成した。住民自身の写真を評価的イメージ(Nasar 1990; Barros et al. 2022)の単位に用いる点と、サーバや外部データベースを要しない点が特徴である。同じ仕組みは巡検や現地調査の写真記録にもそのまま使える。 使い方 スマートフォンの位置情報サービスを有効にして撮影する 写真をSNSやチャットを経由せず、原本のままPCへ移す(経由すると位置情報が失われる) スクリプトと同じ階層に photos フォルダを作り、写真を置く geotag_photos.R を実行する。初回は exiftoolr::install_exiftool() を実行しておく output フォルダに HTML・CSV・GeoPackage・サムネイルが生成される 出力のHTMLは単独で表示できる。QGISでは、GeoPackageを開き、レイヤプロパティ→表示名のHTMLに次を設定して「ビュー」→「地図のTipsを表示」を有効にすると、地図上で写真が表示される。 必要パッケージ:exiftoolr, sf, magick, leaflet, htmlwidgets, base64enc v2.0での変更点 EXIF読み取りを exif パッケージから exiftoolr に変更(HEICと画像の向きに対応) 地図のHTMLをファイルとして書き出すようにした(v1はRのViewer表示のみ)。埋め込む画像は縮小したサムネイルとし、原寸は埋め込まない CSVとGeoPackageの出力を追加し、QGISでも読めるようにした 地理院タイルの出典表記を国土地理院の指定形式に改めた スクリプト名を geotag_photos.R に変更し、コメントを英語にした v1の出力例(ppgis_geotag_place_attachment_output.png)は比較のため残した。v1のスクリプトは本レコードのv1に収録されている 出力例の背景地図は地理院タイルである。 生成AIの利用 v1のコードはGoogle Gemini、v2.0のコードはAnthropic Claudeの支援を受けて作成した。設計・検証・本文の記述は著者による。 参考文献 Barros, M. S., Degbelo, A., & Filomena, G. (2022). Evaluative image 2.0: A web mapping approach to capture people's perceptions of a city. Transactions in GIS, 26(2), 1116–1139. https://doi.org/10.1111/tgis.12867Nasar, J. L. (1990). The evaluative image of the city. Journal of the American Planning Association, 56(1), 41–53. https://doi.org/10.1080/01944369008975742Moteki, Y. (2026). Collaborative Spatial Visualization's Impact on Place Attachment: A Cluster Randomized Trial in Japan's Chita District. SSRN. https://doi.org/10.2139/ssrn.6536760 [English] Description An R script that reads GPS coordinates and capture metadata from a folder of geotagged smartphone photos and produces three outputs: A Leaflet map as a single HTML file; clicking a point shows the photo A per-photo table of coordinates, timestamp, direction, and horizontal positioning error (CSV) The same records as a point layer (GeoPackage), which opens directly in QGIS The script was written as a Public Participation GIS (PPGIS) tool for mapping residents' "favorite places," as proposed in the research protocol "Collaborative Spatial Visualization's Impact on Place Attachment: A Cluster Randomized Trial in Japan's Chita District" (SSRN 6536760). It uses residents' own photographs as the unit of the evaluative image (Nasar 1990; Barros et al. 2022) and requires no server or external database. The same workflow serves for photo records from field trips and site surveys. Usage Enable location services on the smartphone camera and take photos Transfer the original files to a PC without passing through social media or chat apps, which strip location data Create a photos folder next to the script and place the photos in it Run geotag_photos.R. On first use, run exiftoolr::install_exiftool() HTML, CSV, GeoPackage, and thumbnails are written to the output folder The HTML output can be viewed on its own. In QGIS, open the GeoPackage, set the following as the HTML map tip under Layer Properties > Display, and enable View > Show Map Tips to show photos on the map: Required packages: exiftoolr, sf, magick, leaflet, htmlwidgets, base64enc Changes in v2.0 EXIF reading switched from the exif package to exiftoolr (adds HEIC and image-orientation support) The map is now written to an HTML file (v1 displayed it only in the R Viewer). Embedded images are downscaled thumbnails, not full-size photos CSV and GeoPackage exports added for use in QGIS GSI tile attribution changed to the form specified by the Geospatial Information Authority of Japan Script renamed to geotag_photos.R; comments are in English The v1 output example (ppgis_geotag_place_attachment_output.png) is retained for comparison; the v1 script is available in version v1 of this record The basemap in the output examples is GSI Tiles. Use of generative AI The v1 code was written with assistance from Google Gemini and the v2.0 code with assistance from Anthropic Claude. Design, verification, and the text of this record are the author's. References Barros, M. S., Degbelo, A., & Filomena, G. (2022). Evaluative image 2.0: A web mapping approach to capture people's perceptions of a city. Transactions in GIS, 26(2), 1116–1139. https://doi.org/10.1111/tgis.12867Nasar, J. L. (1990). The evaluative image of the city. Journal of the American Planning Association, 56(1), 41–53. https://doi.org/10.1080/01944369008975742Moteki, Y. (2026). Collaborative Spatial Visualization's Impact on Place Attachment: A Cluster Randomized Trial in Japan's Chita District. SSRN. https://doi.org/10.2139/ssrn.6536760