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, tokyo_geographic_srs, jgd2000_geographic_srs, jgd2000_projected_srs, gsb_file, encoding): # Step 1: 平面直角座標系(Tokyo)→ 地理座標系(Tokyo) print(f"Step 1: {os.path.basename(input_path)} を Tokyo 地理座標系に変換中...") ogr2ogr_step1 = ( f'ogr2ogr -f "ESRI Shapefile" -s_srs "{input_srs}" -t_srs "{tokyo_geographic_srs}" ' f'-lco ENCODING={encoding} "{temp1_path}" "{input_path}"' ) os.system(ogr2ogr_step1) # Step 2: 地理座標系(Tokyo)→ 地理座標系(JGD2000, GSB補正使用) print(f"Step 2: {os.path.basename(temp1_path)} を JGD2000 地理座標系に変換中...") ogr2ogr_step2 = ( f'ogr2ogr -f "ESRI Shapefile" -s_srs "+proj=latlong +nadgrids={gsb_file} +ellps=bessel" ' f'-t_srs "{jgd2000_geographic_srs}" -lco ENCODING={encoding} "{temp2_path}" "{temp1_path}"' ) os.system(ogr2ogr_step2) # Step 3: 地理座標系(JGD2000)→ 平面直角座標系(JGD2000) print(f"Step 3: {os.path.basename(temp2_path)} を JGD2000 平面直角座標系に変換中...") ogr2ogr_step3 = ( f'ogr2ogr -f "ESRI Shapefile" -s_srs "{jgd2000_geographic_srs}" -t_srs "{jgd2000_projected_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 = tokyo_projected_srs_var.get() output_srs = jgd2000_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, output_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:4301", "EPSG:4612", output_srs, gsb_file, encoding ) messagebox.showinfo("完了", "全ての変換が完了しました!") # GUI作成 root = tk.Tk() root.title("tokyo → 2000 Shapefile変換ツール") input_folder_var = tk.StringVar() temp_folder_var = tk.StringVar() output_folder_var = tk.StringVar() tokyo_projected_srs_var = tk.StringVar(value="EPSG:30170") jgd2000_projected_srs_var = tk.StringVar(value="EPSG:2452") gsb_file_var = tk.StringVar(value="C:/par/TKY2JGD.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="Tokyo 平面直角座標系 (EPSG):").grid(row=3, column=0, sticky="e") tk.Entry(root, textvariable=tokyo_projected_srs_var, width=50).grid(row=3, column=1) tk.Label(root, text="JGD2000 平面直角座標系 (EPSG):").grid(row=4, column=0, sticky="e") tk.Entry(root, textvariable=jgd2000_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()