Professional Documents
Culture Documents
############################
# QURESHIAGISC9317D3.py
# Name: Ali Qureshi
# Date: Thursday April 12
# Description: This python code is created for Deliverable 3 of GISC9317D2. The
purpose of this
# code is to count the number of points in a polygon and return the data in a
feature class attribute table.
###################################################################################
#############################
# Create a new folder variable name that will contain the new geodatabase.
newFolder = r'C:\temp\d3ProcDataQureshiA'
# Create a new geodatabase variable name that will contain all new feature classes.
Output_path = "C:/temp/d3ProcDataQureshiA/d3Proc.gdb"
if os.path.exists(newFolder):
# rename the folder before deleting it, this technique works around a problem
where it takes a while to delete the folder
# https://stackoverflow.com/questions/27135470/python-how-to-create-a-
directory-and-overwrite-an-existing-one-if-necessary
tmp = tempfile.mktemp(dir=os.path.dirname(newFolder))
shutil.move(newFolder, tmp)
shutil.rmtree(tmp) # delete a directory/folder and all its contents
os.makedirs(newFolder) # create a new file in the following folder
C:\temp\QureshiAD2ProcData
# Delete the fields listed below from the countyFarm feature class
arcpy.DeleteField_management("countyFarm",
"PRCDCSD;POP2001;DWELL2001;AREA_SQKM;POP1996A;PROV")
# Alter the FREQUENCY column name to NumOfFarm and the NAME column name to
countyName
arcpy.AlterField_management("countyFarm", "FREQUENCY", "NumOfFarm")
arcpy.AlterField_management("countyFarm", "NAME", "CountyName", "CountyName")
# Delete the npFarm, SpatialJoin and SpatialJoinTable feature classes/tables
arcpy.Delete_management("npFarm")
arcpy.Delete_management("SpatialJointable")
arcpy.Delete_management("SpatialJoin")
# Set variable for actual time at the end of the code
endtime = time.time()
# Garbage Clean Up
for name in dir():
if not name.startswith('_'):
del globals()[name]
del name