<?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: ArcPy or ArcObject code to find the closest point on a line. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558822#M43678</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;will do, the example I gave was for non-sequential points... caught it too late.&amp;nbsp; But if you want to experiment&amp;nbsp; for sequential points consider a polyline consisting of&amp;nbsp; points a,b,c,d and a source point X&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;you just find the closest point on the line from your source point... lets say 'c' wins and 'b' and 'd' are closer than 'a'&lt;/LI&gt;&lt;LI&gt;you now have two potential segments to examine b-c and c-d (this could be multiple, but lets keep it simple.&lt;/LI&gt;&lt;LI&gt;project X onto the candidate segments (the geometry stuff) to get the point on the segment and the distance to X from the segments (could be multiple)&lt;/LI&gt;&lt;LI&gt;the segment from above that has&amp;nbsp; shortest distance is the correct line segment and you have the intersection point and closest point onto the polyline&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I have simplified some checks, but you can incorporate extent checks to see which segments of the polyline contain space that X can project on to.&amp;nbsp; Remember, this is projection onto a segment and not a imaginary line extending from it.&amp;nbsp; So soon, it is an interesting comparison of numpy solution and Near tool&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 26 Nov 2015 01:23:56 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2015-11-26T01:23:56Z</dc:date>
    <item>
      <title>ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558814#M43670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Can you give me some hints (code snippet in Arcpy or ArcObject) on: &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for a given point to find the closest point location on a line feature. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;George &lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-email-small" href="mailto:geoshi@gmail.com"&gt;geoshi@gmail.com&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 05:39:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558814#M43670</guid>
      <dc:creator>George_GShi</dc:creator>
      <dc:date>2015-11-25T05:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558815#M43671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What license level is available? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 05:45:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558815#M43671</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-11-25T05:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558816#M43672</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/analysis-toolbox/near.htm" title="http://desktop.arcgis.com/en/desktop/latest/tools/analysis-toolbox/near.htm"&gt;Near—Help | ArcGIS for Desktop&lt;/A&gt;&amp;nbsp; Is a good place to start if you have the advanced level (which is why Darren asked).&amp;nbsp;&amp;nbsp; There are several samples of using python code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you don't have advanced, then it will take a bit more work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 06:39:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558816#M43672</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2015-11-25T06:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558817#M43673</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For a python approach, simply&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;get the coordinates of your origin ( a variety of ways)&lt;/LI&gt;&lt;LI&gt;get the coordinates of your polyline&lt;UL&gt;&lt;LI&gt;any license &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-data-access/featureclasstonumpyarray.htm" title="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-data-access/featureclasstonumpyarray.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;FeatureClassToNumPyArray—Help | ArcGIS for Desktop&lt;/A&gt; using the explode_to_points option&lt;/LI&gt;&lt;LI&gt;advanced license &lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/feature-vertices-to-points.htm" title="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/feature-vertices-to-points.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Feature Vertices To Points—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;convert both to numpy arrays ( a variety of ways, but FeatureClassToNumPyArray is best&lt;/LI&gt;&lt;LI&gt;use the code example below&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assume a start location at the origin, and projected coordinates (values have been translated to the origin to simplify the visuals and the math)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import numpy as np
&amp;gt;&amp;gt;&amp;gt; origin = np.array([0,0],dtype="float64")
&amp;gt;&amp;gt;&amp;gt; dests = np.array([[1,2],[-3,3],[-4,-4],[1,1],[5,-5]],dtype="float64")
&amp;gt;&amp;gt;&amp;gt; deltas = dests - origin
&amp;gt;&amp;gt;&amp;gt; distances = np.hypot(deltas[:,0], deltas[:,1])
&amp;gt;&amp;gt;&amp;gt; min_dist = np.min(distances)
&amp;gt;&amp;gt;&amp;gt; wh = np.where(distances == min_dist)
&amp;gt;&amp;gt;&amp;gt; closest = dests[wh[0]]
&amp;gt;&amp;gt;&amp;gt; closest
array([[ 1.,&amp;nbsp; 1.]])
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;line (02) that is the origin&lt;/P&gt;&lt;P&gt;line (03 ) the destinations of the points constituting the polyline&lt;/P&gt;&lt;P&gt;line (04) get the coordinate differences)&lt;/P&gt;&lt;P&gt;line (05) calculate the distances, note the np.hypot uses dy,dx as inputs&lt;/P&gt;&lt;P&gt;line (06) find the minimum distance&lt;/P&gt;&lt;P&gt;line(07) find where the min distance is&lt;/P&gt;&lt;P&gt;line(08) use the position of the min distance to slice the original destinations.&amp;nbsp; ( note wh returns a tuple and you want the first element)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the closest point...obviously is 1,1&lt;/P&gt;&lt;P&gt;see other purely arcpy options.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:07:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558817#M43673</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T00:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558818#M43674</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ArcEditor (or "standard" ).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 21:20:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558818#M43674</guid>
      <dc:creator>George_GShi</dc:creator>
      <dc:date>2015-11-25T21:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558819#M43675</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure, but I believe this will only get you the closest vertex, not the closest location on a line (which doesn't necessarily mean a vertex). You need to do some trig in between each vertex. But, I could be missing some of the numpy magic going on here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 21:51:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558819#M43675</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-11-25T21:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558820#M43676</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I left that part out ... but I will post about it soon.&amp;nbsp; In the interim, George found your solution with the wrong license level worked for him. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 21:56:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558820#M43676</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-11-25T21:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558821#M43677</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I don't believe I answered the question, but maybe thinking about license-levels did the trick...? Anyhow, I'd be interested to see what this looks like through numpy. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 22:06:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558821#M43677</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-11-25T22:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558822#M43678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;will do, the example I gave was for non-sequential points... caught it too late.&amp;nbsp; But if you want to experiment&amp;nbsp; for sequential points consider a polyline consisting of&amp;nbsp; points a,b,c,d and a source point X&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;you just find the closest point on the line from your source point... lets say 'c' wins and 'b' and 'd' are closer than 'a'&lt;/LI&gt;&lt;LI&gt;you now have two potential segments to examine b-c and c-d (this could be multiple, but lets keep it simple.&lt;/LI&gt;&lt;LI&gt;project X onto the candidate segments (the geometry stuff) to get the point on the segment and the distance to X from the segments (could be multiple)&lt;/LI&gt;&lt;LI&gt;the segment from above that has&amp;nbsp; shortest distance is the correct line segment and you have the intersection point and closest point onto the polyline&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I have simplified some checks, but you can incorporate extent checks to see which segments of the polyline contain space that X can project on to.&amp;nbsp; Remember, this is projection onto a segment and not a imaginary line extending from it.&amp;nbsp; So soon, it is an interesting comparison of numpy solution and Near tool&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Nov 2015 01:23:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558822#M43678</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-11-26T01:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558823#M43679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all for all your response. Special thanks to Dan for your detailed solutions.&lt;/P&gt;&lt;P&gt;Again, I need to create a function with its:&lt;/P&gt;&lt;P&gt;Input: a line and a point&lt;/P&gt;&lt;P&gt;Output: the point location and distance &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your comments remind me of two cases I need to handle: &lt;/P&gt;&lt;P&gt;1)&amp;nbsp; to find the closest vertex of the line to the given point location. &lt;/P&gt;&lt;P&gt;2) to find a point location “on” (or intersecting) the line close to the given point&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Nov 2015 21:41:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558823#M43679</guid>
      <dc:creator>George_GShi</dc:creator>
      <dc:date>2015-11-27T21:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558824#M43680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The first case, I have given the necessary code if you explode the featureclass to points.&lt;/P&gt;&lt;P&gt;The second case, depends upon the license level that you have.&amp;nbsp; I guess Darren's answer twigged your memory, so I presume that you can get all you need from the Near tool since it allows you to create from-to coordinates in the table, which you can use in the XY to Line tool to produce the necessary vectors.&amp;nbsp; If you want to see the points on the line, just add the near result table as an event theme with the destination points as your XY coordinates.&amp;nbsp; In that way, you can have everything.&lt;/P&gt;&lt;P&gt;I have variants which use pure arcpy and arctoolboxes, and two variants that use a combination of arcpy and numpy.&amp;nbsp; One of these is reported in an earlier blog post of mine and I will post the other variant in one of my upcoming blogs.&amp;nbsp; &lt;/P&gt;&lt;P&gt;In the interim, I presume that you have the necessary license to complete the tasks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Nov 2015 23:12:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558824#M43680</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-11-27T23:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558825#M43681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Although its fun to see Dan come up with a numpy solution...&lt;/P&gt;&lt;P&gt;Would it fit your needs to use the queryPointAndDistance geometry method?&lt;IMG alt="queryPointAndDistance.jpg" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/155880_queryPointAndDistance.jpg" style="width: 620px; height: 384px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Dec 2015 13:55:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558825#M43681</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2015-12-14T13:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558826#M43682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was trying to use your code, since I want to find the minimum distance to the actual vertice points in a polyline with the onMouseDownMap function of an addin tool.&amp;nbsp; Here is the code I tried:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;class SplitLineToolClass(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for SplitLine_addin.SplitLinetool (Tool)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.cursor = 3 # Crosshairs
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onMouseDownMap(self, x, y, button, shift):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Pass if not a Left Mouse Button Click
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if button != 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return
&amp;nbsp;&amp;nbsp;&amp;nbsp; addressLines = pythonaddins.GetSelectedTOCLayerOrDataFrame()
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Code that verifies a polyline layer is selected in the TOC
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc=arcpy.Describe(addressLines)
&amp;nbsp;&amp;nbsp;&amp;nbsp; sr = arcpy.SpatialReference(desc.spatialReference.factoryCode)
&amp;nbsp;&amp;nbsp;&amp;nbsp; origin = np.array([x,y],dtype="float64")
&amp;nbsp;&amp;nbsp;&amp;nbsp; dests = arcpy.da.FeatureClassToNumPyArray(addressLines, ["SHAPE@X","SHAPE@Y"], "", sr, explode_to_points=True)
&amp;nbsp;&amp;nbsp;&amp;nbsp; deltas = dests - origin 
&amp;nbsp;&amp;nbsp;&amp;nbsp; distances = np.hypot(deltas[:,0], deltas[:,1]) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; min_dist = np.min(distances)
&amp;nbsp;&amp;nbsp;&amp;nbsp; wh = np.where(distances == min_dist) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; closest = dests[wh[0]]
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Closest Vertice = {0}".format(closest))&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, my adaptation of your code is throwing an error on the line that subtracts the two arrays (deltas = dests - origin on line 18 of the code above).&amp;nbsp; Here is the error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File ..., line ..., in onMouseDownMap&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; deltas = dests - origin&lt;/P&gt;&lt;P&gt;TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'numpy.ndarray'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I added print lines for the origin and dest arrays, it showed that the Origin array created by line 16 is a list with a space a number a double space and a number, while the Dest array was a list of tuples containing two numbers separated by a comma and a space.&amp;nbsp; What is the best way to get the two arrays compatible for line 18?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is how the arrays printed:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Origin Point = [ 6305489.12520918&amp;nbsp; 2169986.76545799]&lt;/P&gt;&lt;P&gt;Destination Points = [(6305087.957613736, 2169963.2243613005)&lt;/P&gt;&lt;P&gt;(6305515.50958015, 2169962.629874304)&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;(6305742.797839478, 2169860.239002958)]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I tried the "SHAPE@XY" field instead the result seemed worse:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Destination Point = [([6305087.957613736, 2169963.2243613005],)&lt;/P&gt;&lt;P&gt;([6305515.50958015, 2169962.629874304],)&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;([6305742.797839478, 2169860.239002958],)]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:07:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558826#M43682</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-12T00:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558827#M43683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Richard, it is in your array forms... don't know how x,y got passed into an array object... here is some code using your numbers.&amp;nbsp; ps, no need to cast your array to a float dtype, since numpy figures it out from the inputs and only needs guidance when there might be some confusion&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; orig = np.array([ 6305489.12520918,2169986.76545799])
&amp;gt;&amp;gt;&amp;gt; orig
array([ 6305489.13,&amp;nbsp; 2169986.77])
&amp;gt;&amp;gt;&amp;gt; dest = np.array([[6305087.957613736, 2169963.2243613005],[6305515.50958015, 2169962.629874304]])
&amp;gt;&amp;gt;&amp;gt; diff = dest-orig
&amp;gt;&amp;gt;&amp;gt; diff
array([[-401.17,&amp;nbsp; -23.54],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&amp;nbsp; 26.38,&amp;nbsp; -24.14]])&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where the array represents the dx, dy pairs for each destination from the points.&amp;nbsp; einsum is faster... I posted something on my blog using it when I was comparing numpy to scipy, pdist (or cdist)... you should be able to calculate the distance of millions of points quicly.&lt;/P&gt;&lt;P&gt;Not the arrays are lists of lists, in the case of destination, I noticed that your tuples were open ended with the extra comma after the braces... you can list(a tuple) if your acquisition is not standard.&amp;nbsp; &lt;A href="https://community.esri.com/group/1732" target="_blank"&gt;NumPy Repository&lt;/A&gt;​ houses other documents etc that I have been working on for some time, for those interested in numpy and its dressed up brethern, scipy and pandas which use numpy arrays natively.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:07:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558827#M43683</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T00:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558828#M43684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The X,Y got passed into an array object by the FeatureClassToNumpyArray, which is the method you recommended for people to use in your original post to convert a polyline to an array of points.&amp;nbsp;&amp;nbsp; That method is used in line 17 with the explode_to_points option set to True.&amp;nbsp; The first output list used the ["SHAPE@X", "SHAPE@Y"] fields and the second list which had the extra comma used the ["SHAPE@XY"] field.&amp;nbsp; The arrays are the unprocessed native output of that method with the explode_to_point=True option and those field settings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found the answer on how to make the output of FeatureClassToNumpyArray method with the explode_to_point=True option work with the rest of the code.&amp;nbsp; I changed line 17 to :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dests = np.array(list(list(x) for x in arcpy.da.FeatureClassToNumPyArray(addressLines, ["SHAPE@X","SHAPE@Y"], "", sr, True)),dtype="float64")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now the code works and the Origin and Dest arrays print as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Origin Point = [ 6305489.12520918&amp;nbsp; 2169986.76545799]&lt;/P&gt;&lt;P&gt;Destination Points = [[ 6305087.95761374&amp;nbsp; 2169963.2243613 ]&lt;/P&gt;&lt;P&gt;[ 6305515.50958015&amp;nbsp; 2169962.6298743 ]&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;[ 6305742.79783948&amp;nbsp; 2169860.23900296]]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The numpy array rounds the orignal numbers from 9 decimal places to 8 decimal places (i.e., 6305087.957613736 became 6305087.95761374), but since that is way below my XY resolution and tolerance that should not be a problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the full working code is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="keyword"&gt;class SplitLineToolClass(object):&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="comment"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for SplitLine_addin.SplitLinetool (Tool)"""&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(&lt;SPAN class="special"&gt;self&lt;/SPAN&gt;):&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="special"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = &lt;SPAN class="special"&gt;False&lt;/SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="special"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.cursor = &lt;SPAN class="number"&gt;3&lt;/SPAN&gt; &lt;SPAN class="comment"&gt;# Crosshairs&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN class="special"&gt;&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def onMouseDownMap(&lt;SPAN class="special"&gt;self&lt;/SPAN&gt;, x, y, button, shift):&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="comment"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Pass if not a Left Mouse Button Click&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if button != &lt;SPAN class="number"&gt;1&lt;/SPAN&gt;:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; &lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addressLines = pythonaddins.GetSelectedTOCLayerOrDataFrame()&amp;nbsp; 
&lt;SPAN class="comment"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Code that verifies a polyline layer is selected in the TOC&amp;nbsp; &lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc=arcpy.Describe(addressLines)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sr = arcpy.SpatialReference(desc.spatialReference.factoryCode)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; origin = np.array([x,y],dtype=&lt;SPAN class="string"&gt;"float64")&amp;nbsp; &lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dests = np.array(list(list(x) for x in arcpy.da.FeatureClassToNumPyArray(addressLines, ["SHAPE@X","SHAPE@Y"], "", sr, True)),dtype="float64")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; deltas = dests - origin&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distances = np.hypot(deltas[:,&lt;SPAN class="number"&gt;0], deltas[:,&lt;SPAN class="number"&gt;1&lt;/SPAN&gt;])&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; min_dist = np.min(distances)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wh = np.where(distances == min_dist)&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; closest = dests[wh[&lt;SPAN class="number"&gt;0]]&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(&lt;SPAN class="string"&gt;"Closest Vertice = {0}"&lt;/SPAN&gt;.format(closest))&amp;nbsp; &lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:07:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558828#M43684</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-12T00:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558829#M43685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PS.... if you need closest point on a line code... I have it somewhere,&amp;nbsp; It replicates the Near tool functionality, if that is what you are looking for.&amp;nbsp; I can't remember if it is a pure python implementation of a numpy/arcpy blending.&amp;nbsp; In any event, if this is what you are looing for and I will try to dredge it up when I get on an Arc* machine.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 04:19:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558829#M43685</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-28T04:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558830#M43686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes I don't suspect 10^-8 or so meters is going to make much of a difference &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt; float128 is around the corner and then there is always the Decimal module if you really want to kill speed but are working at the atomic level&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 04:24:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558830#M43686</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-28T04:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558831#M43687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the offer, but I actually am using the code I posted to compare the nearest edge point returned by either the distanceTo&amp;nbsp; or the queryPointAndDistance method of the polyline.&amp;nbsp; I need at minimum two of the items the queryPointAndDistance method returns and may need the other two latter.&amp;nbsp; I need the side offset (sideDist) to see if the line edge is inside my split tolerance, and I need the distance along the line where the point fell as a percent (perc) to actually split the line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pt = arcpy.PointGeometry(arcpy.Point(x,y), sr)&lt;/P&gt;&lt;P&gt;ptOnLine, perc, sideDist, rightSide = pLine.queryPointAndDistance(pt, True)&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output I am after is to see if the vertice is within a maximum distance specified by the user of the real nearest point on the line edge from where the user clicked to determine if I will split at the closest edge or the closest vertice.&amp;nbsp; After getting the queryPointAndDistance percent along the line of either the point on the line vertice returned by your code or point on the line edge returned by either the distanceTo or queryPointAndDistance method I then use that percent to split the line using:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fromLine = pLine.segmentAlongLine(0, perc, True)&lt;/P&gt;&lt;P&gt;toLine = pLine.segmentAlongLine(perc, 100, True)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also use the percent to split address ranges.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So in my example, the full data showed that if a user chose a maximum vertice/edge difference of 10 feet (my units), then the edge should split and not the vertice, since the vertice is more than 11 feet from the closest point on the line edge based on where the user clicked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Origin Point = [ 6305489.12520918&amp;nbsp; 2169986.76545799]&lt;/P&gt;&lt;P&gt;Destination Points = [[ 6305087.95761374&amp;nbsp; 2169963.2243613 ]&lt;/P&gt;&lt;P&gt;[ 6305515.50958015&amp;nbsp; 2169962.6298743 ]&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;[ 6305742.79783948&amp;nbsp; 2169860.23900296]]&lt;/P&gt;&lt;P&gt;Closest Vertice = [[ 6305515.50958015&amp;nbsp; 2169962.6298743 ]]&lt;/P&gt;&lt;P&gt;Vertice Distance 35.7583756816 is within Max Distance 50.0&lt;/P&gt;&lt;P&gt;Difference between nearest vertice and nearest edge is 11.6595012766&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 05:05:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558831#M43687</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2016-03-28T05:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy or ArcObject code to find the closest point on a line.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558832#M43688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/3116"&gt;Dan Patterson&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would be interested in seeing what you've come up with to replace the Near tool. I only have a standard license. I have been messing with arcpy geometry and distanceTo but I haven't gotten very far.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, I have an input of address points and street centerlines, and basically need to find the nearest two polylines from a particular address point and pull their individual IDs or (even better) their street names into the address points feature class as cross streets.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Apr 2016 15:14:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-or-arcobject-code-to-find-the-closest-point/m-p/558832#M43688</guid>
      <dc:creator>JeremyMullins4</dc:creator>
      <dc:date>2016-04-14T15:14:58Z</dc:date>
    </item>
  </channel>
</rss>

