0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GeoJSONファイルから特定地域のデータを抽出

Last updated at Posted at 2025-02-05

GeoJSONファイルから特定地域のデータを抽出して保存するPythonスクリプト

はじめに

このスクリプトは、GeoJSONファイルから特定の地域のデータを抽出し、新しいGeoJSONファイルとして保存するものです。地理空間データの分割処理に活用できます。

必要なライブラリ

import geopandas as gpd

GeoJSONファイルの読み込み

file_path = r"データフォルダ\土砂災害警戒区域データ.geojson"
gdf = gpd.read_file(file_path)

データの確認

print(gdf.columns)

出力先フォルダの設定

output_folder = r"出力先フォルダ"

抽出する地域名の設定

regions = ["地域A", "地域B", "地域C", "地域D"]

データの抽出と保存

for region in regions:
filtered_gdf = gdf[gdf['地域カラム'].str.contains(region, na=False)]

if not filtered_gdf.empty:
output_file = f"{output_folder}\{region}.geojson"
filtered_gdf.to_file(output_file, driver="GeoJSON")
print(f"{region} のデータを保存しました: {output_file}")
else:
print(f"{region} のデータはありませんでした。")

ポイント

  • 具体的な地域名やパスは実際の環境に合わせて調整してください
  • 大容量データの処理には注意が必要です
  • エラーハンドリングを追加することをおすすめします

注意事項

  • 事前にgeopandasのインストールが必要です
  • データの著作権や利用規約を必ず確認してください
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?