<?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: Draw a Line to the nearest Polygon. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172652#M13282</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another approach would be to convert the polygon to a polyline then use&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/generate-near-table.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/generate-near-table.htm"&gt;Generate Near Table—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with the nearest option. Include the proximity info, this gives you the coordinate of the near point.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 10 Apr 2017 07:03:24 GMT</pubDate>
    <dc:creator>NeilAyres</dc:creator>
    <dc:date>2017-04-10T07:03:24Z</dc:date>
    <item>
      <title>Draw a Line to the nearest Polygon.</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172649#M13279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've some set of points which I'm joining to make a line. Refer the Picture below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="345880" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/345880_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem I'm facing is there are no points(elevation points) on the polygon (River Bank). Is there any way of extending the line to the polygon?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Apr 2017 14:55:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172649#M13279</guid>
      <dc:creator>akshayloya</dc:creator>
      <dc:date>2017-04-09T14:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a Line to the nearest Polygon.</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172650#M13280</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/arcmap/latest/tools/editing-toolbox/extend-line.htm"&gt;Extend line&lt;/A&gt; comes to mind, but your polygon may have to be converted to a polyline.&amp;nbsp; There are other coding examples that turn up using a web search if you don't have the appropriate license&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Apr 2017 18:38:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172650#M13280</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-04-09T18:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a Line to the nearest Polygon.</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172651#M13281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My first thought was Extend line, as Dan already mentioned, but then I remembered that it operates within a single feature class, which would involve creating a new, intermediate data set that includes the boundaries of the polygons.&amp;nbsp; Even then, there are questions about how close the lines are to the boundary versus other lines, and what exactly would be extended to what.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another approach is to loop through all of the polygons, river banks in this example, select all of the lines that are within a given polygon, and extend those lines using one of a variety of techniques to match up with each containing polygon.&amp;nbsp; This sample code worked for a basic example I came up with:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; math

dist &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;100&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# distance, in units of projection, to extend the line on each end&lt;/SPAN&gt;

fc_line &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# path to feature class containing lines&lt;/SPAN&gt;
fc_line &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc_line&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"fc_line"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

fc_poly &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# path to feature class containing polygon&lt;/SPAN&gt;
fc_poly &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc_poly&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"fc_poly"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc_poly&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"SHAPE@"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; scur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; poly&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; scur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; boundary &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; poly&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;boundary&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByLocation_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc_line&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"WITHIN"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; poly&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;UpdateCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc_line&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"SHAPE@"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; ucur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; line&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; ucur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&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; arr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; line&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getPart&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&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; SR &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; line&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;spatialReference
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; p2 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arr&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&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; angle &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; math&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;atan2&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;p2&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Y &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; p1&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Y&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; p2&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;X &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; p1&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;X&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&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; p &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Point&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;p1&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;X &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; dist &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt; math&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;cos&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;angle&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p1&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Y &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; dist &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt; math&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sin&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;angle&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&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; arr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;insert&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; p&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pn1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; pn &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arr&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&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; angle &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; math&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;atan2&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pn&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Y &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; pn1&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Y&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; pn&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;X &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; pn1&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;X&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&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; p &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Point&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pn&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;X &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; dist &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt; math&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;cos&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;angle&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pn&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Y &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; dist &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt; math&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sin&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;angle&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&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; arr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;p&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Polyline&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; SR&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&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; line &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; line&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;cut&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;boundary&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&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; ucur&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;updateRow&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;line&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since I don't know the exact structure of your feature classes, I am not sure whether my code would work without some modification.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As Dan mentions, there are numerous ways to extend the line.&amp;nbsp; One simple approach is to go from the end points of the line to the closest points on the polygon.&amp;nbsp; I am not a fan of that approach because it could create an unnatural kink/turn in the line depending on the angle the line is relative to the polygon.&amp;nbsp; A much fancier approach is to use NumPy and SciPy to do form fitting of the lines and then extrapolate using robust math equations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code above splits the difference, in a way, in that it linearly extrapolates the ends from the last two points on each end.&amp;nbsp; Instead of trying to match up the new line exactly, I actually extend the line farther than the polygon and use the &lt;SPAN style="font-family: courier new,courier,monospace;"&gt;cut()&lt;/SPAN&gt; method of an ArcPy Geometry object to trim the line back to the boundary of the polygon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, the code above assumes the data is stored within a projection because I am using simple Cartesian math to measure angles and extend lines instead of using geodesic math.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:55:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172651#M13281</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T08:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a Line to the nearest Polygon.</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172652#M13282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another approach would be to convert the polygon to a polyline then use&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/generate-near-table.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/generate-near-table.htm"&gt;Generate Near Table—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with the nearest option. Include the proximity info, this gives you the coordinate of the near point.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Apr 2017 07:03:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172652#M13282</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2017-04-10T07:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a Line to the nearest Polygon.</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172653#M13283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Getting the following error when I'm building the tool:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/345991_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code for your reference :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy,math&lt;BR /&gt;fc_line = r'd:/PTWork/GIS_RIVER/RiverBank.shp'&lt;BR /&gt;fc_line = arcpy.MakeFeatureLayer_management(fc_line, "fc_line")&lt;/P&gt;&lt;P&gt;fc_poly = r'd:/PTWork/GIS_RIVER/RB_23.shp'&lt;BR /&gt;fc_poly = arcpy.MakeFeatureLayer_management(fc_poly, "fc_poly")&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(fc_poly, "SHAPE@") as scur:&lt;BR /&gt; for poly, in scur:&lt;BR /&gt; boundary = poly.boundary()&lt;BR /&gt; arcpy.SelectLayerByLocation_management(fc_line, "WITHIN", poly)&lt;BR /&gt; lst_value =[]&lt;BR /&gt; with arcpy.da.UpdateCursor(fc_line, "SHAPE@") as ucur:&lt;BR /&gt; for line, in ucur:&lt;BR /&gt; arr, = line.getPart()&lt;BR /&gt; SR = line.spatialReference&lt;BR /&gt; p1, p2 = arr[:2]&lt;BR /&gt; angle = math.atan2(p2.Y - p1.Y, p2.X - p1.X)&lt;BR /&gt; p = arcpy.Point(p1.X - dist * math.cos(angle),&lt;BR /&gt; p1.Y - dist * math.sin(angle))&lt;BR /&gt; arr.insert(0, p)&lt;BR /&gt; &lt;BR /&gt; pn1, pn = arr[-2:]&lt;BR /&gt; angle = math.atan2(pn.Y - pn1.Y, pn.X - pn1.X)&lt;BR /&gt; p = arcpy.Point(pn.X + dist * math.cos(angle),&lt;BR /&gt; pn.Y + dist * math.sin(angle))&lt;BR /&gt; arr.append(p)&lt;BR /&gt; &lt;BR /&gt; line = arcpy.Polyline(arr, SR)&lt;BR /&gt; line = line.cut(boundary)[1]&lt;BR /&gt; ucur.updateRow([line])&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Apr 2017 16:26:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172653#M13283</guid>
      <dc:creator>akshayloya</dc:creator>
      <dc:date>2017-04-10T16:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a Line to the nearest Polygon.</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172654#M13284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;&lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;How to Format your code&lt;/A&gt;... &lt;/STRONG&gt;That link will provide you with instructions, otherwise what you have posted is of little use to decipher potential errors.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Apr 2017 16:37:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172654#M13284</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-04-10T16:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a Line to the nearest Polygon.</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172655#M13285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Refer this code instead:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import math&lt;BR /&gt;import os&lt;BR /&gt;import numpy as np&lt;BR /&gt;from numpy import trapz&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;fc = r'D:/PTWork/GIS_RIVER/23_elevation.shp'&lt;BR /&gt;fld_memo = 'TxtMemo'&lt;BR /&gt;fc_river = r'D:/PTWork/GIS_RIVER/RB_23.shp'&lt;BR /&gt;fc_out = r'D:/PTWork/GIS_RIVER/RiverBank1.shp'&lt;BR /&gt;fld_id = 'LineID'&lt;BR /&gt;id_format = 'CS-{}'&lt;BR /&gt;tolerance = 350&lt;BR /&gt;dist = 100 # distance, in units of projection, to extend the line on each end&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;flds = ('OID@', 'SHAPE@', fld_memo)&lt;BR /&gt;lst_data = [[r[0], r[1], float(r[2])] for r in arcpy.da.SearchCursor(fc, flds)]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# create output featureclass&lt;BR /&gt;sr = arcpy.Describe(fc).spatialReference&lt;BR /&gt;ws, fc_name = os.path.split(fc_out)&lt;BR /&gt;arcpy.CreateFeatureclass_management(ws, fc_name, "POLYLINE", None, None, "ENABLED", sr)&lt;BR /&gt;arcpy.AddField_management(fc_out, fld_id, "TEXT", None, None, 25)&lt;/P&gt;&lt;P&gt;# insert cursor&lt;BR /&gt;flds = ('SHAPE@', fld_id)&lt;BR /&gt;cnt_id = 0&lt;BR /&gt;with arcpy.da.InsertCursor(fc_out, flds) as curs:&lt;BR /&gt; lst_lines = []&lt;BR /&gt; lst_pnts = []&lt;BR /&gt; for i in range(1, len(lst_data)):&lt;BR /&gt; print("i:{}".format(i))&lt;BR /&gt; lst_cur = lst_data&lt;I&gt;&lt;BR /&gt; lst_prev = lst_data[i-1]&lt;BR /&gt; pntg_cur = lst_cur[1]&lt;BR /&gt; pntg_prev = lst_prev[1]&lt;BR /&gt; dist = pntg_prev.distanceTo(pntg_cur)&lt;/I&gt;&lt;/P&gt;&lt;P&gt;if dist &amp;lt;= tolerance:&lt;BR /&gt; # add to existing list&lt;BR /&gt; pnt = pntg_cur.firstPoint&lt;BR /&gt; z = lst_cur[2]&lt;BR /&gt; pnt.Z = z&lt;BR /&gt; lst_pnts.append(pnt)&lt;BR /&gt; else:&lt;BR /&gt; print(" - create and store line and add point to new list...")&lt;BR /&gt; # create and store line and add point to new list&lt;BR /&gt; if len(lst_pnts) &amp;gt; 1:&lt;BR /&gt; polyline = arcpy.Polyline(arcpy.Array(lst_pnts), sr, True, False)&lt;BR /&gt; lst_lines.append(polyline)&lt;BR /&gt; cnt_id += 1&lt;BR /&gt; line_id = id_format.format(cnt_id)&lt;BR /&gt; fc_line = arcpy.MakeFeatureLayer_management(polyline, "fc_line")&lt;BR /&gt; fc_poly = arcpy.MakeFeatureLayer_management(fc_river, "fc_poly")&lt;BR /&gt; with arcpy.da.SearchCursor(fc_poly, "SHAPE@") as scur:&lt;BR /&gt; for poly, in scur:&lt;BR /&gt; boundary = poly.boundary()&lt;BR /&gt; arcpy.SelectLayerByLocation_management(fc_line, "WITHIN", poly)&lt;BR /&gt; with arcpy.da.SearchCursor(fc_line, "SHAPE@") as ucur:&lt;BR /&gt; for line, in ucur:&lt;BR /&gt; arr, = line.getPart()&lt;BR /&gt; SR = line.spatialReference&lt;BR /&gt; p1, p2 = arr[:2]&lt;BR /&gt; angle = math.atan2(p2.Y - p1.Y, p2.X - p1.X)&lt;BR /&gt; p = arcpy.Point(p1.X - dist * math.cos(angle),&lt;BR /&gt; p1.Y - dist * math.sin(angle))&lt;BR /&gt; arr.insert(0, p)&lt;BR /&gt; &lt;BR /&gt; pn1, pn = arr[-2:]&lt;BR /&gt; angle = math.atan2(pn.Y - pn1.Y, pn.X - pn1.X)&lt;BR /&gt; p = arcpy.Point(pn.X + dist * math.cos(angle),&lt;BR /&gt; pn.Y + dist * math.sin(angle))&lt;BR /&gt; arr.append(p)&lt;BR /&gt; &lt;BR /&gt; line = arcpy.Polyline(arr, SR)&lt;BR /&gt; line = line.cut(boundary)[1]&lt;BR /&gt; &lt;BR /&gt; curs.insertRow((line, line_id))&lt;BR /&gt; else:&lt;BR /&gt; # not enough points to create line&lt;BR /&gt; pass&lt;BR /&gt; pnt = pntg_cur.firstPoint&lt;BR /&gt; z = lst_cur[2]&lt;BR /&gt; pnt.Z = z&lt;BR /&gt; lst_pnts = [pnt]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Apr 2017 16:53:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172655#M13285</guid>
      <dc:creator>akshayloya</dc:creator>
      <dc:date>2017-04-10T16:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a Line to the nearest Polygon.</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172656#M13286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Apr 2017 16:58:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172656#M13286</guid>
      <dc:creator>akshayloya</dc:creator>
      <dc:date>2017-04-10T16:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a Line to the nearest Polygon.</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172657#M13287</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;still lacking proper formatting ie indentation&lt;/P&gt;&lt;P&gt;in any event, p1, p2 = a[:2] means it is expecting 2 points... it will fail if it doesn't get 2&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Apr 2017 17:02:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172657#M13287</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-04-10T17:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a Line to the nearest Polygon.</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172658#M13288</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;Refer this code instead:&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;import arcpy&lt;BR /&gt;import math&lt;BR /&gt;import os&lt;BR /&gt;import numpy as np&lt;BR /&gt;from numpy import trapz&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;fc = r'D:/PTWork/GIS_RIVER/23_elevation.shp'&lt;BR /&gt;fld_memo = 'TxtMemo'&lt;BR /&gt;fc_river = r'D:/PTWork/GIS_RIVER/RB_23.shp'&lt;BR /&gt;fc_out = r'D:/PTWork/GIS_RIVER/RiverBank1.shp'&lt;BR /&gt;fld_id = 'LineID'&lt;BR /&gt;id_format = 'CS-{}'&lt;BR /&gt;tolerance = 350&lt;BR /&gt;dist = 100 # distance, in units of projection, to extend the line on each end&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&lt;BR /&gt;flds = ('OID@', 'SHAPE@', fld_memo)&lt;BR /&gt;lst_data = [[r[0], r[1], float(r[2])] for r in arcpy.da.SearchCursor(fc, flds)]&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&lt;BR /&gt;# create output featureclass&lt;BR /&gt;sr = arcpy.Describe(fc).spatialReference&lt;BR /&gt;ws, fc_name = os.path.split(fc_out)&lt;BR /&gt;arcpy.CreateFeatureclass_management(ws, fc_name, "POLYLINE", None, None, "ENABLED", sr)&lt;BR /&gt;arcpy.AddField_management(fc_out, fld_id, "TEXT", None, None, 25)&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;# insert cursor&lt;BR /&gt;flds = ('SHAPE@', fld_id)&lt;BR /&gt;cnt_id = 0&lt;BR /&gt;with arcpy.da.InsertCursor(fc_out, flds) as curs:&lt;BR /&gt;lst_lines = []&lt;BR /&gt;lst_pnts = []&lt;BR /&gt;for i in range(1, len(lst_data)):&lt;BR /&gt;print("i:{}".format(i))&lt;BR /&gt;lst_cur = lst_data&lt;I&gt;&lt;BR /&gt;lst_prev = lst_data[i-1]&lt;BR /&gt;pntg_cur = lst_cur[1]&lt;BR /&gt;pntg_prev = lst_prev[1]&lt;BR /&gt;dist = pntg_prev.distanceTo(pntg_cur)&lt;/I&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;if dist &amp;lt;= tolerance:&lt;BR /&gt;# add to existing list&lt;BR /&gt;pnt = pntg_cur.firstPoint&lt;BR /&gt;z = lst_cur[2]&lt;BR /&gt;pnt.Z = z&lt;BR /&gt;lst_pnts.append(pnt)&lt;BR /&gt;else:&lt;BR /&gt;print(" - create and store line and add point to new list...")&lt;BR /&gt;# create and store line and add point to new list&lt;BR /&gt;if len(lst_pnts) &amp;gt; 1:&lt;BR /&gt;polyline = arcpy.Polyline(arcpy.Array(lst_pnts), sr, True, False)&lt;BR /&gt;lst_lines.append(polyline)&lt;BR /&gt;cnt_id += 1&lt;BR /&gt;line_id = id_format.format(cnt_id)&lt;BR /&gt;fc_line = arcpy.MakeFeatureLayer_management(polyline, "fc_line")&lt;BR /&gt;fc_poly = arcpy.MakeFeatureLayer_management(fc_river, "fc_poly")&lt;BR /&gt;with arcpy.da.SearchCursor(fc_poly, "SHAPE@") as scur:&lt;BR /&gt;for poly, in scur:&lt;BR /&gt;boundary = poly.boundary()&lt;BR /&gt;arcpy.SelectLayerByLocation_management(fc_line, "WITHIN", poly)&lt;BR /&gt;with arcpy.da.SearchCursor(fc_line, "SHAPE@") as ucur:&lt;BR /&gt;for line, in ucur:&lt;BR /&gt;arr, = line.getPart()&lt;BR /&gt;SR = line.spatialReference&lt;BR /&gt;p1, p2 = arr[:2]&lt;BR /&gt;angle = math.atan2(p2.Y - p1.Y, p2.X - p1.X)&lt;BR /&gt;p = arcpy.Point(p1.X - dist * math.cos(angle),&lt;BR /&gt;p1.Y - dist * math.sin(angle))&lt;BR /&gt;arr.insert(0, p)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pn1, pn = arr[-2:]&lt;BR /&gt;angle = math.atan2(pn.Y - pn1.Y, pn.X - pn1.X)&lt;BR /&gt;p = arcpy.Point(pn.X + dist * math.cos(angle),&lt;BR /&gt;pn.Y + dist * math.sin(angle))&lt;BR /&gt;arr.append(p)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;line = arcpy.Polyline(arr, SR)&lt;BR /&gt;line = line.cut(boundary)[1]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;curs.insertRow((line, line_id))&lt;BR /&gt;else:&lt;BR /&gt;# not enough points to create line&lt;BR /&gt;pass&lt;BR /&gt;pnt = pntg_cur.firstPoint&lt;BR /&gt;z = lst_cur[2]&lt;BR /&gt;pnt.Z = z&lt;BR /&gt;lst_pnts = [pnt]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Apr 2017 17:13:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-line-to-the-nearest-polygon/m-p/172658#M13288</guid>
      <dc:creator>akshayloya</dc:creator>
      <dc:date>2017-04-10T17:13:46Z</dc:date>
    </item>
  </channel>
</rss>

