import os import shutil location="G:\\guanzhouall\\BAIYUN400-100" #Target folder path…
- User
import os import shutil location="G:\guanzhou_all\BAIYUN_400-100" #Target folder path folder_parameter="centerline_30" #Folder name path_parameter=os.path.join(location,folder_parameter) #define workspace creat floder path_testpoint="G:\guanzhou_all\BAIYUN_400-100\TP" #Test point folder path path_building="G:\guanzhou_all\BAIYUN_400-100\BAIYUN_400-100.shp" #Building .shp file path if os.path.exists(path_parameter): shutil.rmtree(path_parameter) #delete the old folder if it exists
import arcpy from arcpy import env #https://blog.csdn.net/qq_32813465/article/details/119276327 from arcpy.sa import *
os.mkdir(path_parameter) env.workspace = path_parameter #define workspace radius=0.002
paths_shp = [os.path.join(path_testpoint, j) for j in os.listdir(path_testpoint) if j.endswith('.shp')] #find the paths of all shp files print(paths_shp)
for i in range(len(paths_shp)): path_shp = paths_shp[i] print("path_shp") print(path_shp) filename=os.path.basename(path_shp) #read the file names of all shp files print(filename) filename_buffer='buffer_'+filename # name the output files in buffer analysis filename_square= 'square_'+filename # 在要素包络矩形转面中命名输出文件. filename_clip ='clip_'+filename # name the output files in clip analysis path_site = os.path.join(path_parameter, os.path.splitext(filename)[0]) #define a path for each site (the file extension is excluded) os.mkdir(path_site) print(path_site) folder_backup = "backup" # 命名备份文件夹 path_backup = os.path.join(path_site, folder_backup) #备份文件夹路径=测点文件夹下新建 os.mkdir(path_backup) # 创建指定文件夹路径
path_buffer_backup = os.path.join(path_backup,filename_buffer) #在备份文件夹中创建buffer文件 path_square_backup = os.path.join(path_backup,filename_square)#在备份文件夹中创建square文件 print("circle path") print(path_buffer_backup) path_clip_backup = os.path.join(path_backup,filename_clip)#在备份文件夹中创建clip文件 print(path_clip_backup) arcpy.Buffer_analysis(path_shp, path_buffer_backup, radius) #create a buffer area for each testpoint, arcpy.FeatureEnvelopeToPolygon_management(path_buffer_backup, path_square_backup, "SINGLEPART") #create a square area for each buffer arcpy.Clip_analysis(path_square_backup, path_building, path_clip_backup) #clip the building area as a whole for each buffer area folder_temp1 = "temp1" folder_temp2 = "temp2" folder_temp3 = "temp3" folder_temp4 = "temp4" folder_temp5 = "temp5" folder_temp6 = "temp6" path_temp1 = os.path.join(path_site, folder_temp1) path_temp2 = os.path.join(path_site, folder_temp2) path_temp3 = os.path.join(path_site, folder_temp3) path_temp4 = os.path.join(path_site, folder_temp4) path_temp5 = os.path.join(path_site, folder_temp5) path_temp6 = os.path.join(path_site, folder_temp6) os.mkdir(path_temp1) os.mkdir(path_temp2) os.mkdir(path_temp3) os.mkdir(path_temp4) os.mkdir(path_temp5) os.mkdir(path_temp6) print('3done!') print(path_temp1) print(path_temp6) arcpy.SplitByAttributes_analysis(path_clip_backup,path_temp1,"TP") #split the clipped building area arcpy.SplitByAttributes_analysis(path_square_backup,path_temp6, "TP") #split the buffer area print('4done!') paths_shp_temp1 = [os.path.join(path_temp1, k) for k in os.listdir(path_temp1) if k.endswith('.shp')] #find the paths of all temp shp files print('5done!') print(paths_shp_temp1) for m in range(len(paths_shp_temp1)): path_shp_temp1 = paths_shp_temp1[m] filename_temp1 = os.path.basename(path_shp_temp1) #read the file names of all shp files print(filename_temp1) filename_temp2 = 'separate_' + filename_temp1 #name the output files in MultipartToSinglepart process print(filename_temp2) filename_temp3 = 'raster_' + os.path.splitext(filename_temp1)[0] #name the output files in Euclidean allocation process (the file extension is excluded) filename_temp4 = 'polygon_' + filename_temp1 filename_temp5 = 'polyline_' + filename_temp1 filename_temp6 = filename_temp1 path_filename_temp2 = os.path.join(path_temp2,filename_temp2) path_filename_temp3 = os.path.join(path_temp3,filename_temp3) path_filename_temp4 = os.path.join(path_temp4,filename_temp4) path_filename_temp5 = os.path.join(path_temp5,filename_temp5) path_filename_temp6 = os.path.join(path_temp6,filename_temp6) path_filename_site = os.path.join(path_site,filename_temp1) print(path_filename_temp2) arcpy.MultipartToSinglepart_management(path_shp_temp1,path_filename_temp2) #explode the whole building area into multiple parts arcpy.env.extent = path_filename_temp6 #set the extent (environment) following the extent of the corresponding buffer area eucAllocate = EucAllocation(path_filename_temp2,"","",0.000001,"FID") #calcuate and allocate the Euc distances based on the exploded building polygons print('6done!') eucAllocate.save(path_filename_temp3) arcpy.RasterToPolygon_conversion(path_filename_temp3,path_filename_temp4) arcpy.PolygonToLine_management(path_filename_temp4,path_filename_temp5) arcpy.AddGeometryAttributes_management(path_filename_temp5, "LINE_START_MID_END") print('7done!') with arcpy.da.UpdateCursor(path_filename_temp5, "LEFT_FID") as cursor: for row in cursor: if (row[0] == -1): cursor.deleteRow() arcpy.DeleteIdentical_management(path_filename_temp5,["START_X","START_Y","END_X","END_Y"]) # delete the duplicated centerlines arcpy.Clip_analysis(path_filename_temp5, path_filename_temp6, path_filename_site) # clip the centerlines inside the buffer area arcpy.env.extent = "default" #set the extent (environment) back to default print("道路中心线创建完成。") - Assistant
The code provided is a Python script that performs a series of spatial analyses on test point shapefiles. The script uses the ArcPy module from the ArcGIS Python API to execute geoprocessing tools.
Here is a breakdown of the script's main steps:
- Import necessary modules:
osfor file and folder manipulation,shutilfor folder deletion, andarcpyfor spatial analysis. - Define the target folder path, folder name, and workspace folder.
- Create the target folder if it doesn't exist and set it as the workspace.
- Set the radius value for buffer analysis.
- Get the paths of all test point shapefiles in the test point folder.
- Loop through each shapefile path.
- Create backup folders for each site.
- Perform buffer analysis on the test point shapefile to create buffer areas.
- Create square areas for each buffer area using Feature Envelope to Polygon tool.
- Clip the building area using the square areas for each buffer area.
- Create temporary folders for further analysis.
- Split the clipped building area by attributes based on test points.
- Split the buffer area by attributes based on test points.
- Loop through the temporary shapefile paths.
- Explode the building area into multiple parts using the Multipart to Singlepart tool.
- Calculate and allocate the Euclidean distances based on the exploded building polygons.
- Convert the Euclidean distance raster to polygon.
- Convert the polygon to a polyline and add geometry attributes.
- Delete duplicate centerlines.
- Clip the centerlines inside the buffer area.
- Reset the extent back to default.
- Print a completion message.
Note: The code assumes that the necessary licenses for ArcGIS and the required extensions (Spatial Analyst) are available.
Overall, the script is designed to automate the process of creating buffer areas around test points, analyzing the building area within the buffer, and generating road centerlines within the buffer area.
- Import necessary modules:
- User
为什么会输出如下错误:FATAL ERROR (INFDEF) DIRECTORY FULL
- Assistant
The error message "FATAL ERROR (INFDEF) DIRECTORY FULL" indicates that the directory or disk where the script is trying to write output files is full. This error occurs when the script is unable to allocate space to write the output files due to insufficient disk space.
To resolve this issue, you can try the following steps:
- Check the available disk space on the drive where the output files are being written. Free up some disk space if it is nearly full.
- Verify that the output folder specified in the script has sufficient space to accommodate the output files. If not, change the output folder to a location with more available space.
- Make sure that you have write permissions for the directory or disk where the output files are being written. If not, ensure that you have the necessary permissions to write files in that location.
- If you are working in a network environment, check if the network drive or directory has sufficient space available. Contact your system administrator to verify the available space and permissions.
By addressing these issues, you should be able to resolve the "FATAL ERROR (INFDEF) DIRECTORY FULL" error and successfully execute the script.
- User
请用中文回答
- Assistant
错误消息"FATAL ERROR (INFDEF) DIRECTORY FULL"表示脚本尝试写入输出文件的目录或磁盘已满。这种错误发生在由于磁盘空间不足而无法分配空间来写入输出文件时。
要解决此问题,您可以尝试以下步骤:
- 检查输出文件所在的驱动器上的可用磁盘空间。如果接近满了,请释放一些磁盘空间。
- 确认脚本中指定的输出文件夹具有足够的空间来容纳输出文件。如果不够,请更改输出文件夹到具有更多可用空间的位置。
- 确保您对输出文件所在的目录或磁盘具有写入权限。如果没有,请确保您具有在该位置写入文件所需的权限。
- 如果您在网络环境中工作,请检查网络驱动器或目录是否有足够的可用空间。联系您的系统管理员验证可用空间和权限。
通过解决这些问题,您应该能够解决"FATAL ERROR (INFDEF) DIRECTORY FULL"错误并成功执行脚本。