I'm trying to select the minimum value from a field to select and export that one feature to a temp shp so I can copy the field data from the point to a line. So far I have this:
import arcpy
from arcpy import env
# Set up the environment
env.workspace = r"C:\Users\BrettM\Desktop\OD_Python_Testing"
env.overwriteOutput = True
# Get Min
fcPoints = r"\OD_Shapefiles\One_Road_Points.shp"
temp = r"\OD_Shapefiles\intersectTempPoint.shp"
arcpy.Statistics_analysis(fcPoints, r"C:\Users\BrettM\Desktop\OD_Python_Testing\table",[["NEAR_DIST", "MIN"]])
nearIntersect = r"C:\Users\BrettM\Desktop\OD_Python_Testing\table"
minDistCursor = arcpy.da.SearchCursor("table", ["MIN_NEAR_DIST"])
for row in minDistCursor:
intersectDist = row[0]
print intersectDist
arcpy.MakeFeatureLayer_management(fcPoints, "fcPoints_Lyr")
print "one"
arcpy.SelectLayerByAttribute_management("fcPoints_Lyr", "NEW_SELECTION", ' "NEAR_DIST" = intersectDist ')
print "two"
arcpy.CopyFeatures_management(fcPoints_Lyr, "\OD_Scratch\\temp")
print "three"
del row
del minDistCursor
All those print statements are just to see where I get in the script. I get to print one. I can't figure out how to get the where clause to work for the selectlayerbyattribute. I keep getting an invalid expression error. I may have the copyfeatures wrong as well but I haven't gotten to that part yet.
The overall goal is to cycle through a line file, select points that intersect that line and copy the data from the point that is nearest to a centerline to the line. I'm using near to get the distance from the centerline for all the points and will work on adding the rest once I get this part to work.
There may be a much easier way to go about this but I'm very new to Python so I'm learning on the fly.