☰
Python(arcpy) 批量shp转raster
2026/11/6 4:50:20 网站建设 项目流程
# -*- coding: utf-8 -*-''' 批量实现shp转raster 2021/12/24 '''importarcpyimportosimportre#检查Arcgis的权限arcpy.CheckOutExtension("spatial")arcpy.gp.overwriteOutput=1#设置了输出范围及输出坐标系,这三行也可注释掉arcpy.env.overwriteOutput=Truearcpy.env.extent=arcpy.Extent(-6098370.77434,-5465665.01316,7540629.22566,4821334.98684)arcpy.env.outputCoordinateSystem=arcpy.SpatialReference("C:\\Users\\DELL\\Desktop\\test\\proj.prj")#shp文件所在文件夹input_shp_path=r"C:\\Users\\DELL\\Desktop\\test\\"#输出raster文件的文件夹output_raster_path=r"C:\\Users\\DELL\\Desktop\\select_catchment_raster\\"#读取input_shp_path中的shp文件arcpy.env.workspace=input_shp_path shps=arcpy.ListFiles("*.shp")#遍历shp文件forshpinshps:#原shp文件名格式形如 4116_Canada_03NF001_Boundary_Line.shp#提取文件名,删除编号后缀,作为输出文件的文件名printshp all_index=[substr.start()forsubstrinre.finditer('_',shp)]catchment_name=shp[int(all_index[0]+1):int(all_index[3])]print(catchment_name)raster_out_name=output_raster_path+catchment_name+".tif"#设置了栅格大小cellsize为1公里arcpy.PolygonToRaster_conversion(shp,"Area",raster_out_name,"CeLL_CENTER","Area",1000)

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询