1
for row1 in cursor1:

    if row1[0] != None:
        num3=row1[0].upper()
        custx=row1[4] 
        custy=row1[5]
        num2=row1[8]
        try:
            m=re.search(r"^[0-9]+(?=\s)",row1[0])
            num=m.group()
        except Exception as e:
            pass

        mycust=row1[9].replace(","," ") 
        mycust=mycust.replace("&"," ")
        custlist=mycust.split()
        custlist=[x.upper() for x in custlist]
        custlist=[i for i in custlist if len(i) > 1]

        try:

            t=re.search(r"[A-Za-z]+(\s[A-Za-z]+)?(\s[A-Za-z]+)?(\s[A-Za-z]+)?",row1[8])
            num1=t.group()    
        except Exception as e:
            pass

        if len([item for item in addrlist if item[0]==num3 and re.search(r"^[0-9]*\s",num3) and harversine.myhaversine(custx,custy,item[2],item[3])<2500]) == 1:
            t=[item for item in addrlist if item[0]==num3 and harversine.myhaversine(custx,custy,item[2],item[3])<2500]
            row1[1]=t[0][1] 
            row1[2]=t[0][2] 
            row1[3]=t[0][3] 
            row1[6]="Match1"
            row1[7]=int(harversine.myhaversine(custx,custy,t[0][2],t[0][3]))
            row1[10]=t[0][4]
            row1[11]=t[0][0]
            row1[13]=t[0][5]

        elif len([item for item in propadd if item[0]==num2 and re.search(r"^[0-9]*\s",num3) and myparclist(custlist,item[1])>0 and harversine.myhaversine(custx,custy,item[2],item[3])<3000]) == 1: #ensure the proper address starts with a number      
            q=[item for item in propadd if item[0]==num2 and myparclist(custlist,item[1])>0 and harversine.myhaversine(custx,custy,item[2],item[3])<3000]             
            row1[1]=q[0][1] 
            row1[2]=q[0][2] 
            row1[3]=q[0][3]
            row1[6]="Match2"
            row1[7]=int(harversine.myhaversine(custx,custy,q[0][2],q[0][3]))
            row1[10]=q[0][0]
            row1[11]=q[0][4]
            row1[13]=q[0][5]

        elif len([item for item in propadd if item[0]==num2 and harversine.myhaversine(custx,custy,item[2],item[3])<1500]) == 1:
            v=[item for item in propadd if item[0]==num2 and harversine.myhaversine(custx,custy,item[2],item[3])<1500]
            row1[1]=v[0][1] 
            row1[2]=v[0][2] 
            row1[3]=v[0][3] 
            row1[6]="Match3"
            row1[7]=int(harversine.myhaversine(custx,custy,v[0][2],v[0][3]))
            row1[10]=v[0][0]
            row1[11]=v[0][4]
            row1[13]=v[0][5]

        elif len([item for item in numlist if item[0]==num and myparclist(custlist,item[2])>0 and harversine.myhaversine(custx,custy,item[3],item[4])<600]) == 1:
            z=[item for item in numlist if item[0]==num and myparclist(custlist,item[2])>0 and harversine.myhaversine(custx,custy,item[3],item[4])<600]
            row1[1]=z[0][2] 
            row1[2]=z[0][3] 
            row1[3]=z[0][4] 
            row1[6]="Match4"
            row1[7]=int(harversine.myhaversine(custx,custy,z[0][3],z[0][4]))
            row1[10]=z[0][5]
            row1[11]=z[0][1]
            row1[13]=z[0][6]

        elif len([item for item in numlist if item[0]==num and harversine.myhaversine(custx,custy,item[3],item[4])<150]) == 1:                                             
            z1= [item for item in numlist if item[0]==num and harversine.myhaversine(custx,custy,item[3],item[4])<150]
            row1[1]=z1[0][2] 
            row1[2]=z1[0][3] 
            row1[3]=z1[0][4] 
            row1[6]="Match5"
            row1[7]=int(harversine.myhaversine(custx,custy,z1[0][3],z1[0][4]))
            row1[10]=z1[0][5]
            row1[11]=z1[0][1]
            row1[13]=z1[0][6]

        elif len([myitem for myitem in snamelist if myitem[0]==num1 and myparclist(custlist,myitem[2])>0 and harversine.myhaversine(custx,custy,myitem[3],myitem[4])<150]) == 1:
            j=[myitem for myitem in snamelist if myitem[0]==num1 and myparclist(custlist,myitem[2])>0 and harversine.myhaversine(custx,custy,myitem[3],myitem[4])<150]
            row1[1]=j[0][2] 
            row1[2]=j[0][3] 
            row1[3]=j[0][4] 
            row1[6]="Match6"
            row1[7]=int(harversine.myhaversine(custx,custy,j[0][3],j[0][4]))
            row1[10]=j[0][1]
            row1[11]=j[0][5]
            row1[13]=j[0][6]

        cursor1.updateRow(row1)  
del row1
del cursor1

closed as off-topic by Get Spatial, PolyGeo Oct 31 '15 at 7:33

  • This question does not appear to be about geographic information systems (GIS) within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • If you can take the time to do a little cleanup, you should submit bits of this to codereview.stackexchange.com. I've had to use and change a very similar script made by an previous coworker dealing with a PostGIS DB, and e.g. row1[13]=z1[0][6] just smells ; even with comments and a lot of care it's just so easy to make a mistake and not realize why for hours! – F.X. Oct 30 '15 at 23:22
  • 1
    Also, as @Matej said in his answer, consider using a real database instead of shapefiles. Just as an example, that very similar script I was talking about went from 15 minutes to less than a second by converting all Python for loops into indexed SQL joins, so it can be done! Good luck :) – F.X. Oct 30 '15 at 23:33
  • 2
    I'm voting to close this question as off-topic because the person who asked the question had to remove all parts of it and is unable to delete the question themselves. – Get Spatial Oct 31 '15 at 7:04
  • 1
    I'll talk to the other moderators about whether we can delete the question, because doing so will deny its answerer 60 reputation points which seems unfair. – PolyGeo Oct 31 '15 at 7:32
  • @ketar: A shame you weren't able to keep the code here, it didn't seem as if it was giving away much. At least on this point look at named tuples. And yes, I meant that for joins ; others might disagree with me, but if you are able to drop down to raw SQL instead of Python, the speedup can be immense with the proper indexes. – F.X. Oct 31 '15 at 10:02
6

From the posted code is unclear where the myparclist is coming from. I presume that you are running a searchCursor within the updateCursor.

You may avoid a searchCursor by joining the tables and only running the updateCursor. Or, if you have customer locations, you may want to perform a spatial join instead.

Few more ideas:

  • move the data into a filegeodatabase and add indices to the fields that are used by the searchCursor
  • you may try creating a dictionary upfront for parcel data and then retrieve them quickly within the updateCursor.
  • do some profiling to determine which parts are taking the longest.
  • Only moving the data into fgdb will most likely not make much of a difference. Why don't you simply join/spatially join the tables? – Matej Oct 31 '15 at 1:43

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