当我尝试运行此代码时:
import arcpy, os
arcpy.env.overwriteOutput = True
def polylineArea(x, y): # this is your function definition
count=len(xlist)
area=0
j=count-1
for i in range (0, count):
area+=((x[j]+x[i])*(y[j]-y[i]))
j=i
return area*.5
infile=open("C:/KateFiles/Courses/SIE510/ParcelStuff/parcel15.txt", "r")
outputname = "C:/KateFiles/Courses/SIE510/ParcelStuff/P_12/ParcelPolys2.shp"
sr=arcpy.SpatialReference(102683)
arcpy.CreateFeatureclass_management(os.path.dirname(outputname),os.path.basename(outputname),"POLYLINE", spatial_reference=sr)
arcpy.AddField_management(outputname, "ParcelID", "LONG", field_precision=8)
arcpy.AddField_management(outputname, "Map", "TEXT", field_length=4)
arcpy.AddField_management(outputname, "Lot", "TEXT", field_length=4)
arcpy.AddField_management(outputname, "point", "Float", field_precision=10, field_scale=2)
cursor1 = arcpy.da.InsertCursor(outputname,("ParcelID","SHAPE@", "Map","Lot", "point"))
header1 = infile.readline()
print header1 # print this out so you can see what this contains
header2 =header1.split()# split the header parts by white space
parcelID=header2[1]#assign parcel ID
Mapno=header2[2]# assign the Mapno
Lotno=header2[3]# assign the Lotno
xlist=[]
ylist=[]
#poly =[] # A list that will hold each of the Polygon objects
#point=arcpy.point
parray=arcpy.Array()
# Loop over lines and extract variables of interest
for line in infile:
segments=line.split()
x=float(segments[0]) # gets x
y=float(segments[1]) # gets y
print x, y
pt=arcpy.point(x, y)
parray.add(pt)
xlist.append(x)
ylist.append(y)
area=polylineArea(x, y) # this is your function call
print area
point=arcpy.polyline(parray)
row=(parcelID, poly, Mapno, Lotno, point) # these match the fields in your insert cursor specification
cursor1.insertRow(row)
infile.close()
我收到了这个错误:
Traceback (most recent call last):
File "C:/Users/Ahmed A. Jasim/Desktop/Q3_Lb8.py", line 45, in <module>
pt=arcpy.point(xlist, ylist)
AttributeError: 'module' object has no attribute 'point'
答案 0 :(得分:0)
ArcPy模块区分大小写,因此您需要capitalize those objects,例如
pt=arcpy.Point(x, y)
point=arcpy.Polyline(parray)