-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeometryBasics
70 lines (44 loc) · 1.53 KB
/
GeometryBasics
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
__author__ = Meghan Kulkarni <[email protected]>
This file reads X & Y co-ordinates, creates polygon out of it and calculates area in sq miles
"""
import arcpy
arcpy.env.workspace = 'C:\\usr\\MeghanK\\Lab9'
in_file = 'C:\\usr\\MeghanK\\Lab9\\6317homework.txt'
fc = 'homework.shp'
arcpy.CreateFeatureclass_management(arcpy.env.workspace, fc, "Polyline")
cursor = arcpy.da.InsertCursor(fc, ["SHAPE@"])
fileinput = open(in_file)
point = arcpy.Point()
array1 = arcpy.Array()
array2 = arcpy.Array()
point1 = arcpy.Point()
point2 = arcpy.Point()
# Splitting line into 3 parts i.e., ID, X and Y co-ordinate
# Based on ID either add it to Polyline 1 or Polyline 2
for line in fileinput:
point.ID, point.X, point.Y = line.split()
if point.ID == 0:
point1 = point
array1.add(point1)
elif point.ID == 1:
point2 = point
array2.add(point2)
polyline1 = arcpy.Polyline(array1)
polyline2 = arcpy.Polyline(array2)
# Finally add them to cursor
cursor.insertRow([polyline1])
cursor.insertRow([polyline2])
fileinput.close()
del cursor
# 2230 WKID for NAD_1983_StatePlane_California_VI_FIPS_0406_Feet
arcpy.DefineProjection_management('C:\\usr\\MeghanK\\Lab9\\homework.shp', 2230)
g = arcpy.Geometry()
geomList = arcpy.Buffer_analysis("C:\\usr\\MeghanK\\Lab9\\homework.shp",
g, "0.5 miles", "#", "#", "ALL")
area = 0
for geom in geomList:
area += geom.area
# Conversion of Sq Feet to Sq Miles
area *= 0.000000035870
print("Buffered Area (in SQ MILES): {:,.4f}".format(area))