This is a working version of snapping any point to nearest polyline within a buffer distance. But, this takes significantly longer as each time it copies the point to a different shape and snaps it. Is there a way to create a faster version of this tool?

    for id in ids: #ids contain the list of links within the buffer
        where_clause = """ "_ID_" = %d""" % id
        arcpy.SelectLayerByAttribute_management(base_f, "NEW_SELECTION", where_clause) #selects one/any link
        arcpy.CopyFeatures_management(other_pt_f, m1) #copies it to temp(m1)
        arcpy.Snap_edit(m1, [[base_f, "EDGE", "1 Miles"]]) #snaps the node to that link
        with arcpy.da.SearchCursor(m1, ["SHAPE@XY"]) as curs:
            for xy in curs:
    near_ids[key] = nearxy #gets the coordinates of the snapped point
  • Snap_edit takes a snap environment parameter where you can specify the distance. Any reason why you can't just use that? – mikewatt Sep 5 '19 at 17:51
  • I have used the environment which is "EDGE" and "1 Miles" – pnkjmndhl Sep 5 '19 at 18:07
  • I guess I'm asking how your current approach differs from setting that environment distance to the buffer distance you're interested in – mikewatt Sep 5 '19 at 18:43
  • If I use just that parameter, the node will be snapped to just 1 nearest link and the process would stop. However, here, the node would be snapped to all the links within the buffer. – pnkjmndhl Sep 5 '19 at 18:59
  • Couple of thoughts. You may already have this but you don't show how the data is created. Setting up a spatial index or an attribute index can speed up the querying. Also when you are copying features you can use in_memory or a feature set and that will limit the writes to the hard drive. – dslamb Sep 5 '19 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.