<?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: problems with distanceTo from a point geometry to a new polyline in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324864#M25261</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great observation! I had not been setting the SR env variable. Now I will!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Dec 2012 23:27:00 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2012-12-18T23:27:00Z</dc:date>
    <item>
      <title>problems with distanceTo from a point geometry to a new polyline</title>
      <link>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324861#M25258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to call distanceTo from a PointGeometry to a Polyine and am running into trouble whenever the polyline is one I just cooked up. Any pointer on what I'm doing incorrectly would be welcome.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
#get the first point feature and the first line feature
poi = arcpy.da.SearchCursor("POIs","SHAPE@").next()[0]
line = arcpy.da.SearchCursor("Streets","SHAPE@").next()[0]

print poi.distanceTo(line)&amp;nbsp; #returns 0.017893575694200557

#get first part of line
part = line.getPart(0)

#get the first two points on that part
p0 = part[0]
p1 = part[1]

#make a new polyline out of those two points
seg = arcpy.Polyline(arcpy.Array([p0,p1]))


print seg.length #returns 0.0017140186696764268, so the segment is there as a polyline

#try to get the distance from the poi to the segment
poi.distanceTo(seg)

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is what comes back:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 809, in distanceTo
&amp;nbsp;&amp;nbsp;&amp;nbsp; return convertArcObjectToPythonObject(self._arc_object.DistanceTo(*gp_fixargs((other,))))
ValueError: &amp;lt;geoprocessing describe geometry object object at 0x16068EE0&amp;gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 20:45:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324861#M25258</guid>
      <dc:creator>HarryBowman</dc:creator>
      <dc:date>2012-12-10T20:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: problems with distanceTo from a point geometry to a new polyline</title>
      <link>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324862#M25259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm having the same issue... The .distanceTo method fails when comparing a geometry object to a "constructed" polyline geometry object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It works great when you run it on one of the points that your "constructed" polyline is created from, but not for a Polyline geometry object that you "construct" from point A and point B.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Same error: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;interactive input&amp;gt;", line 1, in &amp;lt;module&amp;gt;
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 779, in distanceTo
&amp;nbsp;&amp;nbsp;&amp;nbsp; return convertArcObjectToPythonObject(self._arc_object.DistanceTo(*gp_fixargs((other,))))
ValueError: &amp;lt;geoprocessing describe geometry object object at 0x0D04CCC0&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:24:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324862#M25259</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T15:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: problems with distanceTo from a point geometry to a new polyline</title>
      <link>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324863#M25260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I have figured this out - distanceTo requires both geometries to have the same projection / spatial reference. The newly created geometry has an unknown projection/spatial reference, so the call fails. The spatial reference needs to be set at creation time for the new geometry.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Dec 2012 21:06:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324863#M25260</guid>
      <dc:creator>HarryBowman</dc:creator>
      <dc:date>2012-12-18T21:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: problems with distanceTo from a point geometry to a new polyline</title>
      <link>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324864#M25261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great observation! I had not been setting the SR env variable. Now I will!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Dec 2012 23:27:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324864#M25261</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-12-18T23:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: problems with distanceTo from a point geometry to a new polyline</title>
      <link>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324865#M25262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There must be something else I'm doing wrong. Even though I can create a geometry with a spatial reference and use it for distanceTo, it still shows as having None spatial reference for the purpose of projectAs.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Dec 2012 14:27:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324865#M25262</guid>
      <dc:creator>HarryBowman</dc:creator>
      <dc:date>2012-12-19T14:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: problems with distanceTo from a point geometry to a new polyline</title>
      <link>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324866#M25263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;polylineGeometry.distanceTo(justPoint) will work&lt;/P&gt;&lt;P&gt;pointGeometry.distanceTo(polylineGeometry) will not.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jul 2014 22:31:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-with-distanceto-from-a-point-geometry-to/m-p/324866#M25263</guid>
      <dc:creator>FelixPertziger</dc:creator>
      <dc:date>2014-07-14T22:31:47Z</dc:date>
    </item>
  </channel>
</rss>

