import os import tkinter as tk from tkinter import filedialog, messagebox # Shapefile変換関数 def convert_shapefile(input_path, temp1_path, temp2_path, output_path, input_srs, intermediate_srs, final_srs, gsb_file, encoding): # Step 1: 平面直角座標系(2000)→ 地理座標系(2000) print(f"Step 1: {os.path.basename(input_path)} を2000 地理座標系に変換中...") ogr2ogr_step1 = ( f'ogr2ogr -f "ESRI Shapefile" -s_srs "{input_srs}" -t_srs "{intermediate_srs}" ' f'-lco ENCODING={encoding} "{temp1_path}" "{input_path}"' ) os.system(ogr2ogr_step1) # Step 2: 地理座標系(2000)→ 地理座標系(2011, GSB補正使用) print(f"Step 2: {os.path.basename(temp1_path)} を2011 地理座標系に変換中...") ogr2ogr_step2 = ( f'ogr2ogr -f "ESRI Shapefile" -s_srs "+proj=longlat +ellps=GRS80 +nadgrids={gsb_file} +no_defs" ' f'-t_srs "EPSG:6668" -lco ENCODING={encoding} "{temp2_path}" "{temp1_path}"' ) os.system(ogr2ogr_step2) # Step 3: 地理座標系(2011)→ 平面直角座標系(2011) print(f"Step 3: {os.path.basename(temp2_path)} を2011 平面直角座標系に変換中...") ogr2ogr_step3 = ( f'ogr2ogr -f "ESRI Shapefile" -s_srs "EPSG:6668" -t_srs "{final_srs}" ' f'-lco ENCODING={encoding} "{output_path}" "{temp2_path}"' ) os.system(ogr2ogr_step3) # GUIでの設定 def run_gui(): def browse_input_folder(): folder = filedialog.askdirectory() input_folder_var.set(folder) def browse_temp_folder(): folder = filedialog.askdirectory() temp_folder_var.set(folder) def browse_output_folder(): folder = filedialog.askdirectory() output_folder_var.set(folder) def browse_gsb_file(): file = filedialog.askopenfilename(filetypes=[("GSB Files", "*.gsb")]) gsb_file_var.set(file) def start_conversion(): input_folder = input_folder_var.get() temp_folder = temp_folder_var.get() output_folder = output_folder_var.get() input_srs = input_projected_srs_var.get() final_srs = output_projected_srs_var.get() gsb_file = gsb_file_var.get() encoding = encoding_var.get() if not all([input_folder, temp_folder, output_folder, input_srs, final_srs, gsb_file, encoding]): messagebox.showerror("Error", "全てのフィールドを入力してください!") return os.makedirs(temp_folder, exist_ok=True) os.makedirs(output_folder, exist_ok=True) for filename in os.listdir(input_folder): if filename.endswith(".shp"): input_shp = os.path.join(input_folder, filename) temp1_shp = os.path.join(temp_folder, f"temp1_{filename}") temp2_shp = os.path.join(temp_folder, f"temp2_{filename}") output_shp = os.path.join(output_folder, filename) print(f"Processing {filename}...") convert_shapefile( input_shp, temp1_shp, temp2_shp, output_shp, input_srs, "EPSG:4612", final_srs, gsb_file, encoding ) messagebox.showinfo("完了", "全ての変換が完了しました!") # GUI作成 root = tk.Tk() root.title("2000→2011 Shapefile変換ツール") input_folder_var = tk.StringVar() temp_folder_var = tk.StringVar() output_folder_var = tk.StringVar() input_projected_srs_var = tk.StringVar(value="EPSG:2452") # デフォルト値: JGD2000 平面直角座標系 output_projected_srs_var = tk.StringVar(value="EPSG:6678") # デフォルト値: JGD2011 平面直角座標系 gsb_file_var = tk.StringVar(value="C:/par/touhokutaiheiyouoki2011.gsb") # デフォルト値 encoding_var = tk.StringVar(value="UTF-8") # デフォルト値 tk.Label(root, text="入力フォルダ:").grid(row=0, column=0, sticky="e") tk.Entry(root, textvariable=input_folder_var, width=50).grid(row=0, column=1) tk.Button(root, text="参照", command=browse_input_folder).grid(row=0, column=2) tk.Label(root, text="一時フォルダ:").grid(row=1, column=0, sticky="e") tk.Entry(root, textvariable=temp_folder_var, width=50).grid(row=1, column=1) tk.Button(root, text="参照", command=browse_temp_folder).grid(row=1, column=2) tk.Label(root, text="出力フォルダ:").grid(row=2, column=0, sticky="e") tk.Entry(root, textvariable=output_folder_var, width=50).grid(row=2, column=1) tk.Button(root, text="参照", command=browse_output_folder).grid(row=2, column=2) tk.Label(root, text="2000 平面直角座標系 (EPSG):").grid(row=3, column=0, sticky="e") tk.Entry(root, textvariable=input_projected_srs_var, width=50).grid(row=3, column=1) tk.Label(root, text="2011 平面直角座標系 (EPSG):").grid(row=4, column=0, sticky="e") tk.Entry(root, textvariable=output_projected_srs_var, width=50).grid(row=4, column=1) tk.Label(root, text="GSBファイル:").grid(row=5, column=0, sticky="e") tk.Entry(root, textvariable=gsb_file_var, width=50).grid(row=5, column=1) tk.Button(root, text="参照", command=browse_gsb_file).grid(row=5, column=2) tk.Label(root, text="Encoding (UTF-8, Shift_JIS, etc):").grid(row=6, column=0, sticky="e") tk.Entry(root, textvariable=encoding_var, width=50).grid(row=6, column=1) tk.Button(root, text="変換開始", command=start_conversion).grid(row=7, column=1) root.mainloop() # 実行 if __name__ == "__main__": run_gui()