Solved! Go to Solution.
I have a point Feature Class I am trying to sort. It contains both a "POINT_X" and a "POINT_Y" field. I wish to start from lower left and sort WE_SN. I have a standard license and am therefore limited to a single sort field (excluding shape) while using sort_mgmt(). I therefore am looking to calculate new sort field using "POINT_X" and "POINT_Y". Any suggestions?
Thanks in advance.
def Output(FirstPoint): FPX = round(float(FirstPoint.X), 4) FPY = round(float(FirstPoint.Y), 4) return "{%(FX)012.4f}{%(FY)012.4f}" % {'FX': FPX, 'FY': FPY}
I have a point Feature Class I am trying to sort. It contains both a "POINT_X" and a "POINT_Y" field. I wish to start from lower left and sort WE_SN. I have a standard license and am therefore limited to a single sort field (excluding shape) while using sort_mgmt(). I therefore am looking to calculate new sort field using "POINT_X" and "POINT_Y". Any suggestions?
Thanks in advance.
def Output(FirstPoint): FPX = round(float(FirstPoint.X), 4) FPY = round(float(FirstPoint.Y), 4) return "{%(FX)012.4f}{%(FY)012.4f}" % {'FX': FPX, 'FY': FPY}
def Output(FirstPoint): FPX = round(float(FirstPoint.X), 4) FPY = round(float(FirstPoint.Y), 4) return "{%(FX)012.4f}{%(FY)012.4f}" % {'FX': FPX, 'FY': FPY} def get_LCP(fc): return os.path.join(results + '\\Simplified_' + fc) def main(): points = results + '\\pts' # Process: Find all stream crossings (points) #arcpy.Intersect_analysis(lines,'G:\Xcel\Route Tool\Southwest\Results.gdb\pts',"ONLY_FID","#","POINT") in_features = "'" + lines + "'" + " #" arcpy.Intersect_analysis(in_features,\ out_feature_class="G:/Xcel/Route Tool/Southwest/Scratch.gdb/lines_clip_Intersect",\ join_attributes="ONLY_FID",cluster_tolerance="#",output_type="POINT") # Adds x and y field to points pts_geometry = arcpy.AddXY_management("G:/Xcel/Route Tool/Southwest/Scratch.gdb/lines_clip_Intersect") # Dissolves duplicate points arcpy.Dissolve_management(pts_geometry,"pts_dissolve","POINT_X;POINT_Y","#","SINGLE_PART","DISSOLVE_LINES") arcpy.AddField_management("pts_dissolve","Sort","TEXT") arcpy.CalculateField_management("pts_dissolve","Sort", Output(Shape.FirstPoint),"PYTHON_9.3")
arcpy.AddField_management("pts_dissolve","Sort","TEXT", 50) Expression = "Output(!Shape.FirstPoint!)" codeblock = """def Output(FirstPoint): FPX = round(float(FirstPoint.X), 4) FPY = round(float(FirstPoint.Y), 4) return "{%(FX)012.4f}{%(FY)012.4f}" % {'FX': FPX, 'FY': FPY}""" arcpy.CalculateField_management("pts_dissolve","Sort", Expression,"PYTHON_9.3",codeblock)
Thanks Richard!
I got this to work using the first process you described. I would be curoius to see a function used to calculate that euclidean field?
Here is what worked for me.arcpy.AddField_management("pts_dissolve","Sort","TEXT", 50) Expression = "Output(!Shape.FirstPoint!)" codeblock = """def Output(FirstPoint): FPX = round(float(FirstPoint.X), 4) FPY = round(float(FirstPoint.Y), 4) return "{%(FX)012.4f}{%(FY)012.4f}" % {'FX': FPX, 'FY': FPY}""" arcpy.CalculateField_management("pts_dissolve","Sort", Expression,"PYTHON_9.3",codeblock)
arcpy.AddField_management("pts_dissolve","Sort","TEXT", 50) Expression = "Output(!Shape.FirstPoint!, 6708902.3000, 2298340.4500)" codeblock = """def Output(FirstPoint, MinX, MinY): XDif = round(float(FirstPoint.X), 4) - round(float(MinX), 4) YDif = round(float(FirstPoint.Y), 4) - round(float(MinY), 4) Length = hypot(XDif, YDif) FPX = round(float(FirstPoint.X), 4) FPY = round(float(FirstPoint.Y), 4) return "{%(LEN)012.4f}{%(FX)012.4f}{%(FY)012.4f}" % {'LEN':Length, 'FX': FPX, 'FY': FPY}""" arcpy.CalculateField_management("pts_dissolve","Sort", Expression,"PYTHON_9.3",codeblock)
Expression1 = "Output(!Shape.FirstPoint!, {0},{1})" .format(minX, minY) Expression2 = "Output(!Shape.FirstPoint!, {0},{1})" .format(maxX, minY) codeblock1 = """def Output(FirstPoint, MinX, MinY): XDif = round(float(FirstPoint.X), 4) - round(float(MinX), 4) YDif = round(float(FirstPoint.Y), 4) - round(float(MinY), 4) Length = math.hypot(XDif, YDif) FPX = round(float(FirstPoint.X), 4) FPY = round(float(FirstPoint.Y), 4) return "{%(LEN)012.4f}{%(FX)012.4f}{%(FY)012.4f}" % {'LEN':Length, 'FX': FPX, 'FY': FPY}""" codeblock2 = """def Output(FirstPoint, MaxX, MinY): XDif = round(float(FirstPoint.X), 4) - round(float(MaxX), 4) YDif = round(float(FirstPoint.Y), 4) - round(float(MinY), 4) Length = math.hypot(XDif, YDif) FPX = round(float(FirstPoint.X), 4) FPY = round(float(FirstPoint.Y), 4) return "{%(LEN)012.4f}{%(FX)012.4f}{%(FY)012.4f}" % {'LEN':Length, 'FX': FPX, 'FY': FPY}""" if bearing > 180 and bearing < 270: arcpy.CalculateField_management("pts_dissolve","Sort", Expression,"PYTHON_9.3",codeblock) elif bearing > 0 and bearing < 90: arcpy.CalculateField_management("pts_dissolve","Sort", Expression,"PYTHON_9.3",codeblock) elif bearing > 90 and bearing < 180: arcpy.CalculateField_management("pts_dissolve","Sort", Expression2,"PYTHON_9.3",codeblock2) else: arcpy.CalculateField_management("pts_dissolve","Sort", Expression2,"PYTHON_9.3",codeblock2)