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

March 28, 2017

Dear Mr. Barbacki,

RE: Deliverable 2 Create a Feature Class from XY Data for GISC9317 Advanced Programming for
GIS.
Please accept this letter as my formal submission of Deliverable 2 Create a Feature Class from XY Data
for GISC 9317 Advanced Programming for GIS.
The purpose of the following deliverable is to write a Python script to create point feature class from an XY
text file. Python is an optimal tool for automating process such as creating feature classes from a text file.
Two text files were used to determine the number of wineries present within a specific extent. Using a text
file of farms and wineries, the file was converted into a feature class and then into a shapefile. A single
shapefile entitled “npfarm.shp” was created showing the merging between the farms and wineries text file.
Based on the Python code, it concluded that there are 36 different wineries within the extent.
One challenge with the Python code was setting the environment workspace. Within the code, the
workspace is defined several times. This was to ensure that the right workspace was being used to allow
the code to run optimally. Garbage cleanup was performed at the end of the code to ensure residual data
has been deleted.
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.) DrouinWGISC9317D2.py (Python Code).


#DrouinWGISC9317D2.py
#Author: Winona Drouin
#Date: March 21, 2018
#Deliverable 2: Create a Feature Class from XY Data
#GISC9317 Advanced Programming for GIS

#Import modules necessary to complete the program.


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

#Setting workspace
arcpy.env.workspace=r'C:\temp\d2RawData'

#Create new folder to store shapefiles. Source: https://stackoverflow.com/questions/27135470/python-


how-to-create-a-directory-and-overwrite-an-existing-one-if-necessary
newFolder=r'C:\temp\DrouinWD2ProcData'
if os.path.exists(newFolder):
tmp=tempfile.mktemp(dir=os.path.dirname(newFolder))
shutil.move(newFolder, tmp)
shutil.rmtree(tmp)
os.makedirs(newFolder)

#Lists the text files ending with .txt extension


TextFiles=arcpy.ListFiles("*.txt")

#Creation of loop
for txtFile in TextFiles:

#Splits the name of the file from the extension.


Split=txtFile.split(".")[0]

arcpy.env.overwriteOutput=True

#Defining the spatial reference system.


SpatialReference="Projected Coordinate Systems/UTM/NAD 1983/NAD 1983 UTM Zone 17N"

#Makes a layer file or feature class from the text file.


arcpy.MakeXYEventLayer_management(txtFile, "EastingM", "NorthingM", Split, SpatialReference)

#Converts feature class or layer file into shapefile.


arcpy.FeatureClassToShapefile_conversion(Split, newFolder)

#Re-defining workspace
arcpy.env.workspace=newFolder

#Create a list of all shapefiles


shapeFile= arcpy.ListFiles("*.shp")
#Merges all shapefiles in the folder and makes a new shapefile called npfarm
arcpy.Merge_management (shapeFile, "npfarm.shp")

#Re-defining workspace.
arcpy.env.workspace=newFolder

#Sets the extent of the analysis.


arcpy.env.extent=arcpy.Extent(610000, 4760000, 660000, 4780000)

#Gets the number of wineries within the extent.


results=arcpy.GetCount_management("npfarm.shp")

#Prints results of the number of wineries.


print results

#Garbage Clean-up
del newFolder
del TextFiles
del Split
del shapeFile
del results

You might also like