fiendniu

How to make this extraction process faster

Discussion created by fiendniu on Mar 8, 2012
Latest reply on Mar 8, 2012 by csny490
I have a point shapefile wihch has 527k data points.
1st step: I am trying to create a 4 meters buffer at each points to find its neighbours and corresponding information (such as X, Y, direction) within the buffer.
2nd step: To identify the points which fall in the overlapping area of two or more buffer, and assign them to their real buffer by comparing distances to each buffer's center
3rd step:  Using all points (including the focal point) within the buffer to calculate average position (avg_X and avg_Y) and avg_Direction.
4th step: change the buffer point's x, y and direction to the avg_X, avg_Y, and avg_Direction.

Following code is for the 1st step


import arcpy, math
arcpy.env.workspace = r'C:\TempArcGISCalculate\TempFile\TestforReadingFile'
arcpy.env.overwriteOutput=True
ptfc = 'Section01_SplitedTrips.shp'
arcpy.MakeFeatureLayer_management(ptfc,'section01pts')
arcpy.Buffer_analysis(ptfc,'in_memory/Section01Buffer','4 meters')

arcpy.MakeFeatureLayer_management('in_memory/Section01Buffer','S1buffer')
#Cut out points inside each buffer
rows = arcpy.SearchCursor('in_memory/Section01Buffer')
row = rows.next()
count = 1

try:
    while row:
        selPoly =arcpy.SelectLayerByAttribute_management('S1buffer',"NEW_SELECTION","\"FID\"="+str(row.FID))

        selPts = arcpy.SelectLayerByLocation_management('section01pts',"WITHIN",selPoly, 0, "NEW_SELECTION")

        curs = arcpy.SearchCursor(selPts)
        for cur in curs:
            print count, cur.getValue('LON_X')," ", cur.getValue('LAT_Y')," ", cur.getValue('InitialBea')," ", cur.getValue('Trace')," ", row.getValue('LON_X'), " ", row.getValue('LAT_Y'), " ", row.getValue('Trace')

        del cur,curs
        row =rows.next()
        count = count + 1

   del row, rows    
except Exception, e:
    #If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "line %i" % tb.tb_lineno
    print e.message        


    

Q1: Is it possible to make this process faster? it is ok for dataset which has row less than 1000, but takes longer as more date involved
Q2: When I add " print arcpy.AddMessage("Elapsed time: " + str(time.clock() - beginTime))" before "del row, rows", It always tells below. This command used to be ok for my previous script.
Traceback (most recent call last):
  File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\TempArcGISCalculate\PythonScript\SelectbyLocation.py", line 31, in <module>
    arcpy.AddMessage("Elapsed time: " + str(time.clock() - beginTime))
NameError: name 'time' is not defined

Outcomes