Documente Academic
Documente Profesional
Documente Cultură
py
# Name: Create Point Data Feature Class From XY data
# Date: Tuesday March 27th 2018
# Description: This python code is created for Deliverable 2 of GISC9317D2. The
purpose of this
# code is to convert text files (XY data) into shape files. This code also merges
2 shapefiles together to create
# a third shapefile and finally count the number of features in a provided extent.
# Create a list of all files that end with .txt and name the list TextFiles
TextFiles = arcpy.ListFiles("*.txt")
# For all the txtfiles in the TextFiles list perform the following
for txtFile in TextFiles:
# Split the names from the "." and use the first word for the name and call
this variable File
File = txtFile.split (".")[0]
# Allow the output to be overwritten if previous files exist
env.overwriteOutput = True
# Set the coordinate system as NAD83 UTM Zone 17N and name it spRef
spRef = "Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983
UTM Zone 11N.prj"
# Create an XY event layer using the txtFiles, the x column is EastingM, the y
column is NorthingM, the output name is based on
# file variable and the projection is based on the spRef variable
arcpy.MakeXYEventLayer_management(txtFile, "EastingM" , "NorthingM" , File,
spRef)
# Convert XY event layer to shapefile by using the File variable for the input
and newFolder as the output location
arcpy.FeatureClassToShapefile_conversion(File, newFolder)
# Set the extent to the following Xmax, Xmin, Ymax, Ymin values
arcpy.env.extent = arcpy.Extent (610000,4760000,660000,4780000)
#Count all features in the npfarm.shp file in the extent above and name it results
results = arcpy.GetCount_management("npfarm.shp")