-5
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()

OUTPUT, Feature: 15 R34 030

908946.59 421204.23 908642.29 420764.59 908479.99 420878.46 908394.73 420761.41 908352.74 420703.76 908348.19 420697.53 908103.16 420865.53 908110.95 420869.92 908314.03 420984.18 908362.5 421011.53 908319.76 421217.07 908294.32 421329.6 908287.91 421361.69 908343.47 421365.32 908483.78 421374.47 908568.12 421379.98 908911.43 421403.04 908946.59 421204.23

Traceback (most recent call last): File "C:/Users/Ahmed A. Jasim/Desktop/b.py", line 51, in area=polylineArea(x, y) # this is your function call File "C:/Users/Ahmed A. Jasim/Desktop/b.py", line 9, in polylineArea area+=((x[j]+x[i])*(y[j]-y[i])) TypeError: 'float' object has no attribute 'getitem'

closed as unclear what you're asking by aldo_tapia, ahmadhanb, ArMoraer, whyzar, Vince Apr 10 '18 at 13:44

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Don't completely change the question. Ask a new one instead (after doing some research on arrays) – JGH Apr 10 '18 at 13:43
1

The function is arcpy.Point, with a capital P.

Note that you will also need to change arcpy.Polyline

  • JGH, thanks I did do your correction, and it works but I got this error now : Traceback (most recent call last): File "C:/Users/Ahmed A. Jasim/Desktop/b.py", line 51, in <module> area=polylineArea(x, y) # this is your function call File "C:/Users/Ahmed A. Jasim/Desktop/b.py", line 9, in polylineArea area+=((x[j]+x[i])*(y[j]-y[i])) TypeError: 'float' object has no attribute 'getitem' How can I fix it – Ahmed Jasim Apr 10 '18 at 13:26
  • @AhmedJasim For your second question, you are passing a float (one value) but then treat it as an array (multiple values). One of the 2 is wrong. – JGH Apr 10 '18 at 13:30
  • JGH , sorry I didn't understand your point much, could you please explain this point more simply? I appreciate your helping. – Ahmed Jasim Apr 10 '18 at 13:36
  • 2
    I think you should learn some Python basics before asking others to debug your bad code. – pLumo Apr 10 '18 at 13:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.