def test(work_path): process_path = work_path + "/process" if not os.path.exists(process_path): os.makedirs(process_path) result_path = work_path + "/result" if not os.path.exists(result_path): os.makedirs(result_path) dem_tif = work_path + "/data/af_dem.tif" dir_o_tif = work_path + "/data/af_dir.tif" acc_tif = work_path + "/data/af_acc.tif" print("Get Complete Watershed...") dt.get_drainage(work_path, dem_tif, dir_o_tif, acc_tif) print("Get Watershed GeoJSON/SHP.") watershed_tif = process_path + "/watershed.tif" watershed_geoj = process_path + "/watersheds.geojson" watershed_shp = process_path + "/watersheds.shp" rp.polygonize_to_geojson(watershed_tif, watershed_geoj) rp.polygonize_to_shp(watershed_tif, watershed_shp) # print("Split Basins.") # ss.split_geojson(result_path, watershed_geoj) print("test")
def test(work_path): process_path = work_path + "/process" if not os.path.exists(process_path): os.makedirs(process_path) result_path = work_path + "/result" if not os.path.exists(result_path): os.makedirs(result_path) print("Get Dir and Acc...") dem_tif = work_path + "/preprocess/n35e115_elv.tif" dir_tif = process_path + "/dir.tif" acc_tif = process_path + "/acc.tif" gda.get_dir_acc(process_path, dem_tif, dir_tif, acc_tif) print("Get Stream...") str_tif = process_path + "/stream.tif" str_th = 30000 re.get_river(process_path, acc_tif, str_th) print("Get Watershed...") we.get_watershed(process_path, dem_tif, dir_tif, acc_tif, str_tif) print("Get Watershed GeoJSON/SHP.") watershed_tif = process_path + "/watershed.tif" watershed_geoj = process_path + "/watersheds.geojson" watershed_shp = process_path + "/watersheds.shp" rp.polygonize_to_geojson(watershed_tif, watershed_geoj) rp.polygonize_to_shp(watershed_tif, watershed_shp) print("test")
def test(work_path): process_path = work_path + "/process" if not os.path.exists(process_path): os.makedirs(process_path) result_path = work_path + "/result" if not os.path.exists(result_path): os.makedirs(result_path) dem = work_path + "/data/dem.tif" dir_o = work_path + "/data/dir.tif" dir_reclass = work_path + "/data/dir_reclass.tif" acc = work_path + "/data/acc.tif" print("Update River&Dir...") trace_starts = work_path + "/data/trace_starts.tif" final_record = work_path + "/data/final_record.txt" raf.add_final_to_river(dir_reclass, final_record, trace_starts, acc) print("Get Watershed...") we.get_watershed(process_path, dem, dir_reclass, acc, trace_starts) print("Get Watershed GeoJSON/SHP.") watershed_tif = process_path + "/watershed.tif" watershed_geoj = process_path + "/watersheds.geojson" watershed_shp = process_path + "/watersheds.shp" rp.polygonize_to_geojson(watershed_tif, watershed_geoj) rp.polygonize_to_shp(watershed_tif, watershed_shp) # print("Split Basins.") # ss.split_geojson(result_path, watershed_geoj) print("test")
def test(work_path, filename): process_path = work_path + "/process" if not os.path.exists(process_path): os.makedirs(process_path) result_path = work_path + "/result" if not os.path.exists(result_path): os.makedirs(result_path) # catalog_path = '/usr/local/large_scale_hydro/catalog' # catalog_path = '/home/liujz/data/Large_Scale_Watershed/catalog' # json_path = work_path + '/' + filename + '.geojson' # dem_tif_path = process_path + '/dem.tif' # dir_tif_path = process_path + '/dir.tif' # acc_tif_path = process_path + '/acc.tif' # lake_tif_path = process_path + '/lake.tif' # ds.data_search(catalog_path, json_path, dem_tif_path, dir_tif_path, acc_tif_path, lake_tif_path) # print("Clip DEM/Dir/Acc") # dem_clip = process_path + "/dem_clip.tif" # dir_clip = process_path + "/dir_clip.tif" # acc_clip = process_path + "/acc_clip.tif" # ct.geojson_clip_tif(json_path, dem_tif_path, dem_clip) # ct.geojson_clip_tif(json_path, dir_tif_path, dir_clip) # ct.geojson_clip_tif(json_path, acc_tif_path, acc_clip) # dem_clip = work_path + "/dem.tif" # dir_clip = work_path + "/dir.tif" # acc_clip = work_path + "/acc.tif" dem = work_path + "/dem.tif" dir = work_path + "/dir_reclass.tif" acc = work_path + "/acc.tif" bound = work_path + "/boundary.tif" print("Get Watershed...") # dt.get_drainage(process_path, dem_clip, dir_clip, acc_clip) we.get_watershed(process_path, dem, dir, acc, bound) print("Get Watershed GeoJSON/SHP.") watershed_tif = process_path + "/watershed.tif" watershed_geoj = process_path + "/watersheds.geojson" watershed_shp = process_path + "/watersheds.shp" rp.polygonize_to_geojson(watershed_tif, watershed_geoj) rp.polygonize_to_shp(watershed_tif, watershed_shp) # print("Split Basins.") # ss.split_geojson(result_path, watershed_geoj) print("test")
def pafa_divide_to_next_level(current_geoj, next_level_folder): global total_dem_tif, total_dir_o_tif, total_acc_tif, river_th temp_folder = next_level_folder + '/temp' if not os.path.exists(temp_folder): os.makedirs(temp_folder) # 获取范围内的数据 dem_tif = temp_folder + '/dem.tif' dir_tif = temp_folder + '/dir.tif' acc_tif = temp_folder + '/acc.tif' cts.geojson_clip_tif(current_geoj, total_dem_tif, dem_tif) cts.geojson_clip_tif(current_geoj, total_dir_o_tif, dir_tif) cts.geojson_clip_tif(current_geoj, total_acc_tif, acc_tif) # 进行pfafstetter编码次分处理 pfaf_1 = temp_folder + '/pfaf_1.tif' no_sub_basin = pc.get_pfafstetter_code(dir_tif, acc_tif, pfaf_1, river_th) # 若没有次级划分 if no_sub_basin: # 删除临时文件夹 shutil.rmtree(temp_folder) return no_sub_basin # 对结果进行矢量化 pfaf_1_geojson = temp_folder + '/pfaf_1.geojson' rp.polygonize_to_geojson(pfaf_1, pfaf_1_geojson) # 各次级流域分开存储 sub_basins_folder = temp_folder + '/sub_basins' if not os.path.exists(sub_basins_folder): os.makedirs(sub_basins_folder) ss.split_geojson(sub_basins_folder, pfaf_1_geojson) # 将次分的流域重命名存储到次级划分文件夹 current_basin_name = os.path.basename(current_geoj) current_pfaf_id = current_basin_name.split('.')[0] sub_basins_geojs = os.listdir(sub_basins_folder) for sub_basins_geoj in sub_basins_geojs: sub_basin_id = current_pfaf_id + sub_basins_geoj.split('.')[0] # 将pfaf_id更新到属性 properties = { "DN": sub_basin_id, "pfaf_id": sub_basin_id, } o_path = sub_basins_folder + '/' + sub_basins_geoj gup.geojson_update_properties(o_path, properties) # 将结果放在次级层级文件夹下 n_path = next_level_folder + '/' + sub_basin_id + '.geojson' shutil.copy(o_path, n_path) # 删除临时文件夹 shutil.rmtree(temp_folder) return 0
import raster_polygonize as rp if __name__ == '__main__': tif_path = r'G:\Graduation\Program\Data\38\test_one_river\pfaf_1.tif' geoj_path = r'G:\Graduation\Program\Data\38\test_one_river\pfaf_1.geojson' rp.polygonize_to_geojson(tif_path, geoj_path)
temp_folder = current_path + '/temp' if not os.path.exists(temp_folder): os.makedirs(temp_folder) # 获取范围内的数据 dem_tif = temp_folder + '/dem_p.tif' dir_tif = temp_folder + '/dir_p.tif' acc_tif = temp_folder + '/acc_p.tif' cts.geojson_clip_tif(basins_geoj_path, total_dem_tif, dem_tif) cts.geojson_clip_tif(basins_geoj_path, total_dir_o_tif, dir_tif) cts.geojson_clip_tif(basins_geoj_path, total_acc_tif, acc_tif) # 进行pfafstetter编码次分处理 pfaf_1 = temp_folder + '/pfaf_1.tif' no_sub_basin = pc.get_pfafstetter_code(dir_tif, acc_tif, pfaf_1, river_th) # 若没有次级划分 if no_sub_basin: river_th = 100.0 else: river_th = 2000000.0 cfR.start_main(temp_folder, basins_geoj_path, lakes_area_threshold, river_th) slope_surface_tif = temp_folder + '/result/slope.tif' lake_tif = temp_folder + '/result/lake_revised.tif' pfaf_id = basins_geoj.split('.')[0] slope_surface_geoj = slope_surface_folder + '/' + pfaf_id + '.geojson' rp.polygonize_to_geojson(slope_surface_tif, slope_surface_geoj) lake_geoj = lake_folder + '/' + pfaf_id + '.geojson' rp.polygonize_to_geojson(lake_tif, lake_geoj) # 删除临时文件夹 shutil.rmtree(temp_folder)