<s> import arcpy <EOL> import os <EOL> inPts = arcpy . GetParameterAsText ( <NUM_LIT:0> ) <EOL> outFeatures = arcpy . GetParameterAsText ( <NUM_LIT:1> ) <EOL> IDField = arcpy . GetParameterAsText ( <NUM_LIT:2> ) <EOL> sortField = arcpy . GetParameterAsText ( <NUM_LIT:3> ) <EOL> if sortField : <EOL> if IDField : <EOL> cursorSort = IDField + "<STR_LIT>" + sortField + "<STR_LIT>" <EOL> else : <EOL> cursorSort = sortField + "<STR_LIT>" <EOL> else : <EOL> cursorSort = IDField + "<STR_LIT>" <EOL> try : <EOL> array , iCur , sRow , sCur , feat = None , None , None , None , None <EOL> desc = arcpy . Describe ( inPts ) <EOL> shapeName = desc . shapeFieldName <EOL> iCur = arcpy . InsertCursor ( outFeatures ) <EOL> array = arcpy . Array ( ) <EOL> pt = arcpy . Point ( ) <EOL> ID = - <NUM_LIT:1> <EOL> fields = shapeName <EOL> if IDField : <EOL> fields += "<STR_LIT:;>" + IDField <EOL> if sortField : <EOL> fields += "<STR_LIT:;>" + sortField <EOL> for sRow in arcpy . gp . SearchCursor ( inPts , "<STR_LIT>" , None , fields , cursorSort ) : <EOL> f = sRow . getValue ( shapeName ) <EOL> if ( f is None ) : <EOL> arcpy . AddError ( '<STR_LIT>' + shapeName ) <EOL> continue <EOL> pt = f . getPart ( <NUM_LIT:0> ) <EOL> if IDField : currentValue = sRow . getValue ( IDField ) <EOL> else : currentValue = None <EOL> if ID == - <NUM_LIT:1> : ID = currentValue <EOL> if ID != currentValue : <EOL> if array . count >= <NUM_LIT:2> : <EOL> feat = iCur . newRow ( ) <EOL> if IDField : <EOL> if ID : <EOL> feat . setValue ( IDField , ID ) <EOL> feat . setValue ( shapeName , array ) <EOL> iCur . insertRow ( feat ) <EOL> else : <EOL> arcpy . AddIDMessage ( "<STR_LIT>" , <NUM_LIT> , str ( ID ) ) <EOL> array . removeAll ( ) <EOL> array . add ( pt ) <EOL> ID = currentValue <EOL> if array . count > <NUM_LIT:1> : <EOL> feat = iCur . newRow ( ) <EOL> if IDField : <EOL> if ID : <EOL> feat . setValue ( IDField , currentValue ) <EOL> feat . setValue ( shapeName , array ) <EOL> iCur . insertRow ( feat ) <EOL> else : <EOL> arcpy . AddIDMessage ( "<STR_LIT>" , <NUM_LIT> , str ( ID ) ) <EOL> array . removeAll ( ) <EOL> arcpy . SetParameterAsText ( <NUM_LIT:4> , outFeatures ) <EOL> except Exception as err : <EOL> import traceback <EOL> arcpy . AddError ( <EOL> traceback . format_exception_only ( type ( err ) , err ) [ <NUM_LIT:0> ] . rstrip ( ) ) <EOL> finally : <EOL> if array : <EOL> del array <EOL> if iCur : <EOL> del iCur <EOL> if sRow : <EOL> del sRow <EOL> if sCur : <EOL> del sCur <EOL> if feat : <EOL> del feat </s>
