Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Winona Drouin

49 Canal Bank Street


Welland, ON
L3B 3M9

Scott Barbacki,
Niagara College
135 Taylor Road
Niagara-on-the-Lake, ON
L0S 1J0

April 17, 2017

Dear Mr. Barbacki,

RE: Deliverable 3 Manipulate Attribute Table for GISC 9317 Advanced Programming for ArcGIS.
Please accept this letter as my formal submission of Deliverable 3 Manipulate Attribute Table for GISC
9317 Advanced Programming for ArcGIS.
Feature classes are a useful tool in organizing information about a single geometric field (either a point,
line or polygon) with a set of attribute fields describing the data. This attribute information allows the user
to visualize and analyze the data associated with that feature. The purpose of the following deliverable is
to create a Python script that creates a new field in a polygon feature class and aggregate a point feature
class using data provided by Niagara College. The aggregated results were then added into the polygon
feature class and the script was timed to ensure efficiency.
Python scripting is an optimal tool to perform the task of manipulating attribute data by providing the user
with an efficient and quick method. A geodatabase was created to house the feature classes and using a join
method, census, farm and county data was combined. “Garbage cleanup” was performed at the end of the
code to ensure that residual data has been deleted. This method was performed through the use of an if not
statement and deletes all data containing underscores.
Should you have any concerns regarding the enclosed documents or if there are any questions please contact
me at your convenience via e-mail at winona.drouin@gmail.com or phone at (905)932-4534. I look forward
to hearing from you.
Warm Regards,

Winona Drouin, B.Sc.


Drouin Environmental
W.D./w.d

Enclosures: 1.) DrouinWGISC9317D3.py (Python Code).


#DrouinWGISC9317D3.py
#Created by: Winona Drouin
#April 18, 2018
#Purpose: To create a Python script to create a new field in a polygon
feature class and aggregate a point feature class and add the aggregated
results into the polygon feature class.
#Deliverable 3: Manipulate attribute tables

import arcpy
from arcpy import env
import os
import tempfile
import shutil
import time

#States the input data and results folder locations.


infolder = r'C:\temp\D3RawData'
outFolder = r'C:\temp\D3ProcDataDrouinW'
tmp=''

#Creates a working directory. Source:


https://stackoverflow.com/questions/27135470/python-how-to-create-a-
directory-and-overwrite-an-existing-one-if-necessary
if os.path.exists(outFolder):
tmp = tempfile.mktemp(dir=os.path.dirname(outFolder))
shutil.move(outFolder, tmp)
shutil.rmtree(tmp)
os.makedirs(outFolder)

#Setting the program to record start time.


StartTime = time.time()

#Setting the workspace environment.


arcpy.env.workspace = outFolder
arcpy.env.overwriteOutput = True

#Creating a new geodatabase. Source: http://pro.arcgis.com/en/pro-app/tool-


reference/data-management/create-file-gdb.htm
arcpy.CreateFileGDB_management(outFolder, "d3Proc.gdb", "")

#Setting variables.
npCsd = r'C:\temp\D3RawData\d3Raw.gdb\npCsd'
npFarm = r'C:\temp\D3RawData\d3Raw.gdb\npFarm'
inputGDB = r'C:\temp\D3RawData\d3Raw.gdb'
outputGDB = r'C:\temp\D3ProcDataDrouinW\d3Proc.gdb'

#Joining and combining


csdJoin = os.path.join(inputGDB, 'npCsd')
farmJoin = os.path.join(inputGDB, 'npFarm')
countyJoin = os.path.join(outputGDB, 'countyFarm')

#Setting up variables for field mapping


fieldMapping = arcpy.FieldMap()
fieldMapping.addInputField(csdJoin, 'NAME')
fieldMap = arcpy.FieldMappings()
fieldMap.addFieldMap(fieldMapping)

#Joins attributes from one feature to another based on a spatial


relationship. Source: http://pro.arcgis.com/en/pro-app/tool-
reference/analysis/spatial-join.htm
arcpy.SpatialJoin_analysis(csdJoin, farmJoin, countyJoin, '', '', fieldMap)

#Deletes unwanted fields in the attribute tables of the created polygon


feature class.
arcpy.DeleteField_management(countyJoin, ['Target_FID'])

#Renaming column to show NumOfFarms in the attribute table.


arcpy.AlterField_management(countyJoin, 'Join_Count', 'NumOfFarm',
'NumOfFarm')

#Setting the program to record end time.


EndTime = time.time()

#Displays the amount of time the program took to run.


print EndTime - StartTime

#Deletes everything that doesn't start with an underscore.


for name in dir():
if not name.startswith('_'):
del globals()[name]
del name

You might also like