【Python】


picture

Usually, when we review the data achievement file, we will encounter such a problem, "the result requires the placement of all elements, and if there is no content, the layer must be left empty ". But for some data, the rules are not allowed to be empty, so we need to open the GIS and manually check whether the layers whose rules are not empty are empty. If the amount of data is too large, it will be a very time-consuming process. process.


Based on this, we propose to " use the code to determine whether each element is a null value, and remove the empty layer to determine whether the empty layer is compliant ", thereby improving the inspection efficiency.


The idea of ​​​​writing the code is as follows:


  • First traverse the folder and subfolders to find each shp file;


  • Secondly, generate the absolute path of the file through the os.path.join command for each shp file , and add it to the specified list;

  • Finally, the path list is traversed, and each shp file is judged to be empty.

The specific code is as follows:

# coding:utf-8import osimport arcpy
shpfile = []directory = r"C:\Users\dell\Desktop\test"print ("路径内shp文件:")for root,dirs,files in os.walk(directory): for file in files: if file.endswith(".shp"): print (file) pth = os.path.join(root, file) shpfile.append(pth) print ("--------------------------------\n" + "其中空文件有:")for filek in shpfile: if arcpy.management.GetCount(filek)[0] == "0": print (filek)


The inspection results are as follows:

picture

First, list all the shp files in the path to determine whether the data is complete;

Second, list the path and name of the empty file to determine whether the data is compliant.