<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Snap Points to Lines Based on Distance and Attributes Code help in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140783#M3663</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Wayne,&amp;nbsp; So would it work best to do a dissolve on RTENAME for the lines to create a shapefile with only one unique RTENAME, and then run the script?&amp;nbsp; I think I can go back and then resplit the lines at intersections.&amp;nbsp; However I may end up losing my address fields then, which would not work.&amp;nbsp; Thinking out loud though, I could just use this dummy dissolve line file to get the lines snapped, but keep the original file and join back to that.&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Clinton&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Feb 2013 15:13:18 GMT</pubDate>
    <dc:creator>ClintonCooper1</dc:creator>
    <dc:date>2013-02-05T15:13:18Z</dc:date>
    <item>
      <title>Snap Points to Lines Based on Distance and Attributes Code help</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140778#M3658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I found this piece of code through my searches and need a few pointers on how to get this to work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Private Sub MovePoint()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pMxDoc As IMxDocument&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set pMxDoc = ThisDocument&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Dim pFLayerA As IFeatureLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set pFLayerA = pMxDoc.FocusMap.Layer(0) 'my point layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pFClassA As IFeatureClass&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set pFClassA = pFLayerA.FeatureClass&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim FCursorA As IFeatureCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Dim FeatureA As IFeature&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; '''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim FCursorB As IFeatureCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Dim FeatureB As IFeature&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim ThePoint As IPoint&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Dim TheCurve As ICurve&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pFLayerB As IFeatureLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set pFLayerB = pMxDoc.FocusMap.Layer(1) 'my line layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pfClassB As IFeatureClass&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set pfClassB = pFLayerB.FeatureClass&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim SpFLayerB As IFeatureSelection&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set SpFLayerB = pMxDoc.FocusMap.Layer(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim K As String 'K is the Line ID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Dim Y As Integer 'Y is the position of the LN_ID field i.e the line "NOMBRE" field&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'Define a query to be use in the cursor to select only the line associated with the point&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Dim pfilter As IQueryFilter&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Dim strQuery As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pNearPoint As IPoint&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Dim DistOnCurve As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Dim NearDist As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Dim bRight As Boolean&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;''''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; 'Find position of the LN_ID field in the point layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Y = pFClassA.FindField("NOMBRE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'Open point cursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set FCursorA = pFClassA.Update(Nothing, True)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set FeatureA = FCursorA.NextFeature&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'Loop through all records in point layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Do Until FeatureA Is Nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set ThePoint = FeatureA.Shape&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; 'Set up the filter for the line cursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; K = FeatureA.Value(Y) 'Find the line id in the point layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; strQuery = "NOMBRE = '" &amp;amp; K &amp;amp; "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set pfilter = New QueryFilter&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; pfilter.WhereClause = strQuery&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; 'Open line cursor as select the line based of pfilter value&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set FCursorB = pfClassB.Search(pfilter, False)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set FeatureB = FCursorB.NextFeature&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set TheCurve = FeatureB.Shape&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set pNearPoint = New Point&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; 'Find nearest point on the line to the point&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; TheCurve.QueryPointAndDistance esriNoExtension, ThePoint, False, _&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; pNearPoint, DistOnCurve, NearDist, bRight&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; 'Update the old point to the new point&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set FeatureA.Shape = pNearPoint&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; FCursorA.UpdateFeature FeatureA&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; 'Move to the next record in the point feature&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Set FeatureA = FCursorA.NextFeature&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Loop&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pMxDoc.ActiveView.Refresh&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MsgBox "Done"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Sub &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am a newbie when it comes to running scripts.&amp;nbsp; I do understand that I need to have the point feature class at the top of my toc and the line feature class second right under it.&amp;nbsp; But I am not sure what I need to change within the script above to make it work in my mxd.&amp;nbsp; For example what lines of code do I change to find the fields that need to match?&amp;nbsp; Thanks in advance!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am running ARCGIS 10.1 SP1&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Feb 2013 15:54:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140778#M3658</guid>
      <dc:creator>ClintonCooper1</dc:creator>
      <dc:date>2013-02-04T15:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Snap Points to Lines Based on Distance and Attributes Code help</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140779#M3659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Since this is in VBA, will this script even work in 10.1?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I got it to loop for a few minutes, and the I got an error: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime Error "91":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Oject Variable or With Block Variabel Not Set&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I go to debug it, it takes me to line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Set TheCurve = FeatureB.Shape&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyone out there that can help with this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Feb 2013 17:57:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140779#M3659</guid>
      <dc:creator>ClintonCooper1</dc:creator>
      <dc:date>2013-02-04T17:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Snap Points to Lines Based on Distance and Attributes Code help</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140780#M3660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Since this is in VBA, will this script even work in 10.1?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I got it to loop for a few minutes, and the I got an error: &lt;BR /&gt;&lt;BR /&gt;Runtime Error "91":&lt;BR /&gt;Oject Variable or With Block Variabel Not Set&lt;BR /&gt;&lt;BR /&gt;When I go to debug it, it takes me to line:&lt;BR /&gt;&lt;BR /&gt;Set TheCurve = FeatureB.Shape&lt;BR /&gt;&lt;BR /&gt;Anyone out there that can help with this?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You should not be able to author this in 10.1 as far as I know, since VBA authoring should not be allowed.&amp;nbsp; So how are you creating and running this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In any case, are you sure that your Line ID values are never Null in the points and that every point has a Line ID value that matches an actual line?&amp;nbsp; If either of these conditions are not met the cursor will set FeatureB to Nothing and the line you mentioned will fail.&amp;nbsp; Here is your main loop with a test for the assignment of FeatureB and a MsgBox to help you figure out why the queryfilter gets no hit if FeatureB is Nothing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;'Loop through all records in point layer
Do Until FeatureA Is Nothing

&amp;nbsp; Set ThePoint = FeatureA.Shape

&amp;nbsp; 'Set up the filter for the line cursor
&amp;nbsp; K = FeatureA.Value(Y) 'Find the line id in the point layer
&amp;nbsp; strQuery = "NOMBRE = '" &amp;amp; K &amp;amp; "'"
&amp;nbsp; Set pfilter = New QueryFilter
&amp;nbsp; pfilter.WhereClause = strQuery

&amp;nbsp; 'Open line cursor as select the line based of pfilter value
&amp;nbsp; Set FCursorB = pfClassB.Search(pfilter, False)
&amp;nbsp; Set FeatureB = FCursorB.NextFeature

&amp;nbsp; 'Verify that a feature was found
&amp;nbsp; If Not FeatureB Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set TheCurve = FeatureB.Shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pNearPoint = New Point

&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Find nearest point on the line to the point
&amp;nbsp;&amp;nbsp;&amp;nbsp; TheCurve.QueryPointAndDistance esriNoExtension, ThePoint, False, _
&amp;nbsp;&amp;nbsp;&amp;nbsp; pNearPoint, DistOnCurve, NearDist, bRight

&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Update the old point to the new point
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set FeatureA.Shape = pNearPoint
&amp;nbsp;&amp;nbsp;&amp;nbsp; FCursorA.UpdateFeature FeatureA
&amp;nbsp; Else
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox("No Line Feature Found.&amp;nbsp; Where Clause was: " &amp;amp; strQuery
&amp;nbsp; End If

&amp;nbsp; 'Move to the next record in the point feature
&amp;nbsp; Set FeatureA = FCursorA.NextFeature

Loop
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:45:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140780#M3660</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T07:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Snap Points to Lines Based on Distance and Attributes Code help</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140781#M3661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the help.&amp;nbsp; I enabled VBA by doing a sperate download for vba and then getting an authorization file from ESRI to run it.&amp;nbsp; I have made sure that all line_ids match the point_ids and that there are no nulls.&amp;nbsp; I took a smaller section of my data and it did make it through.&amp;nbsp; However I got an unexpected issue.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It did move and snap my points to endpoints, but it moved them not to the closet line endpoint that it matched, but it moved them all to one endpoint of one line.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So my question then is this, can I modify this code to move and snap the points to the nearest line with that same attribute?&amp;nbsp; If so, what would that new code&amp;nbsp; be?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code I used, and I have attached my trial data&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Sub MovePoint()

Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

'''''''''''''''''''''''''''''''''''''''''''''''
Dim pFLayerA As IFeatureLayer
Set pFLayerA = pMxDoc.FocusMap.Layer(0) 'my point layer

Dim pFClassA As IFeatureClass
Set pFClassA = pFLayerA.FeatureClass

Dim FCursorA As IFeatureCursor
Dim FeatureA As IFeature
'''''''''''''''''''''''''''''''''''''''''''''''''

Dim FCursorB As IFeatureCursor
Dim FeatureB As IFeature

Dim ThePoint As IPoint
Dim TheCurve As ICurve

Dim pFLayerB As IFeatureLayer
Set pFLayerB = pMxDoc.FocusMap.Layer(1) 'my line layer

Dim pfClassB As IFeatureClass
Set pfClassB = pFLayerB.FeatureClass

Dim SpFLayerB As IFeatureSelection
Set SpFLayerB = pMxDoc.FocusMap.Layer(1)

'''''''''''''''''''''''''''''''''''''''''''''''''''

Dim K As String&amp;nbsp; 'K is the Line ID
Dim Y As Integer&amp;nbsp; 'Y is the position of the LN_ID field i.e the line id field

'Define a query to be use in the cursor to select only the line associated with the point
Dim pfilter As IQueryFilter
Dim strQuery As String


Dim pNearPoint As IPoint
Dim DistOnCurve As Double
Dim NearDist As Double
Dim bRight As Boolean

''''''''''''''''''''''''''''''''''''''''''''''''''''
'Find position of the LN_ID field in the point layer
Y = pFClassA.FindField("RTENAME")

'Open point cursor
Set FCursorA = pFClassA.Update(Nothing, True)
Set FeatureA = FCursorA.NextFeature

'Loop through all records in point layer
Do Until FeatureA Is Nothing

&amp;nbsp;&amp;nbsp;&amp;nbsp; Set ThePoint = FeatureA.Shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Set up the filter for the line cursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; K = FeatureA.Value(Y) 'Find the line id in the point layer
&amp;nbsp;&amp;nbsp;&amp;nbsp; strQuery = "RTENAME = '" &amp;amp; K &amp;amp; "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pfilter = New QueryFilter
&amp;nbsp;&amp;nbsp;&amp;nbsp; pfilter.WhereClause = strQuery
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Open line cursor as select the line based of pfilter value
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set FCursorB = pfClassB.Search(pfilter, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set FeatureB = FCursorB.NextFeature
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set TheCurve = FeatureB.Shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pNearPoint = New Point
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Find nearest point on the line to the point
&amp;nbsp;&amp;nbsp;&amp;nbsp; TheCurve.QueryPointAndDistance esriNoExtension, ThePoint, False, _
&amp;nbsp;&amp;nbsp;&amp;nbsp; pNearPoint, DistOnCurve, NearDist, bRight
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Update the old point to the new point
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set FeatureA.Shape = pNearPoint
&amp;nbsp;&amp;nbsp;&amp;nbsp; FCursorA.UpdateFeature FeatureA
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Move to the next record in the point feature
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set FeatureA = FCursorA.NextFeature

Loop

pMxDoc.ActiveView.Refresh

MsgBox "Done"


End Sub
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:45:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140781#M3661</guid>
      <dc:creator>ClintonCooper1</dc:creator>
      <dc:date>2021-12-11T07:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Snap Points to Lines Based on Distance and Attributes Code help</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140782#M3662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Clinton, I haven't confirmed this - you'll need to follow up testing.... but think I may have traced the most logical source of your error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Again, test to confirm, but I suspect there is something wrong with your 'pfilter' parameter in the cursor.&amp;nbsp; What clued me in is that pfilter is being used twice - in the outer loop for setting the search cursor on points, and again in the inner loop to set another search cursor on the lines (i.e., to limit or 'reselect' line candidates to snap points to --- the point of failure, as you said, is that points are not being snapped to the proper line candidates).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I'd check then is Y -- field vals are 'looked up' by index, or position in the table...the weakest point this operation fails is that the expected field is in a different position in the line feature class.....so no actual selection is being made and the 1st line in the fc is being used for snapping.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, the culprit I believe is this line...using the field position in pFClassA really has no bearing on the position in pFClassB:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Y = pFClassA.FindField("RTENAME")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm probably not going to test this, but will post a corrected code sub in a minute...if you (or someone else that may be reading this) is making these corrections before I post again, I would set up different pfilter params to feed into the search cursors (or you could reorganize your table, but rather you should fix the code to prevent this loophole).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&amp;nbsp; Actually, I was curious and ran your code after reconsidering how the pfilter above was formed, and since you have the same field and looking up the same val in both tables, then the pfilter doesn't need 'refreshing', so to speak.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Seems to run for me, except it snaps to to the line, not necessarily to one of the endpoints or for that matter, the proper street -- so I take it, you are really asking for refinement of the snapping?&amp;nbsp; I noticed you have duplicate values in both tables - this will not work well, since the 1st feature in the street query selection will be used in snapping [regardless of spatial position].)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 13:20:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140782#M3662</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-02-05T13:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Snap Points to Lines Based on Distance and Attributes Code help</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140783#M3663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Wayne,&amp;nbsp; So would it work best to do a dissolve on RTENAME for the lines to create a shapefile with only one unique RTENAME, and then run the script?&amp;nbsp; I think I can go back and then resplit the lines at intersections.&amp;nbsp; However I may end up losing my address fields then, which would not work.&amp;nbsp; Thinking out loud though, I could just use this dummy dissolve line file to get the lines snapped, but keep the original file and join back to that.&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Clinton&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 15:13:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140783#M3663</guid>
      <dc:creator>ClintonCooper1</dc:creator>
      <dc:date>2013-02-05T15:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Snap Points to Lines Based on Distance and Attributes Code help</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140784#M3664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No I don't think this is your only option, certainly not the best option I wouldn't think... my thoughts are that maybe tighten how the queries are being made if you can more accurately pinpoint how the points and lines are being targeted for snapping.&amp;nbsp; As it stands, it runs a little wild, if you'll pardon the figure of speech.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Earlier, I think I described it as 1 loop for selecting the street 'candidates' nested inside the other loop selecting (or iterating over) the points.&amp;nbsp; What I referred to as the 'inner loop' to select the street candidate isn't really a loop per se, but more of a 'set' to gain access to the 1st feature in a selection...which is a problem, since again these are multiple features in no particular order satisfying the query, correct?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure where to go from here, let me think - could be if you cannot make your field values better 'correlated' in a way that the queries are more precise, you may be better off with some sort of 'bulk snap'...I'll look into that if I have time.&amp;nbsp; Meanwhile someone else may have a better suggestion.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, extremely curious about the method, QueryPointAndDistance.&amp;nbsp; I think that is on ICurve... yes, "Dim TheCurve As ICurve".&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So it may help to better understand all the parameters entered for that method from this line (below) in your code - maybe some 'adjustments' will give you better results:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;TheCurve.QueryPointAndDistance esriNoExtension, ThePoint, False, _ &amp;nbsp;&amp;nbsp;&amp;nbsp; pNearPoint, DistOnCurve, NearDist, bRight&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This 'exercise' actually helps me with some later VB.NET - and so forth add-ins, etc., understanding ArcObjects better.&amp;nbsp; If I come across any tools or changes in applying the method above, I'll post it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 15:39:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/snap-points-to-lines-based-on-distance-and/m-p/140784#M3664</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-02-05T15:39:26Z</dc:date>
    </item>
  </channel>
</rss>

