<?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: Extend line (not within) up to polygon feature? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/extend-line-not-within-up-to-polygon-feature/m-p/1186583#M64833</link>
    <description>&lt;P&gt;Thank you, I will try it.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Jun 2022 04:25:18 GMT</pubDate>
    <dc:creator>JohannesBierer</dc:creator>
    <dc:date>2022-06-27T04:25:18Z</dc:date>
    <item>
      <title>Extend line (not within) up to polygon feature?</title>
      <link>https://community.esri.com/t5/python-questions/extend-line-not-within-up-to-polygon-feature/m-p/1185381#M64807</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I've found a script of JoshuaBixby from here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-questions/extend-line-up-to-polygon-feature/td-p/705806/page/2" target="_blank"&gt;https://community.esri.com/t5/python-questions/extend-line-up-to-polygon-feature/td-p/705806/page/2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;it work well to extend lines within a polygon up to the border of the polygon feature. But it couldn't work with lines which are somehow between the polygons (see attached image - in black original line).&lt;/P&gt;&lt;P&gt;Could you think of a solution for this?&lt;/P&gt;&lt;P&gt;I tested "Have their center in" in line 21 instead of "within" but it doesn't work ...&lt;/P&gt;&lt;P&gt;I use notebook in ArcGIS Pro 2.9&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: utf-8 -*-
import arcpy
import math

arcpy.env.workspace = FGDB
arcpy.env.overwriteOutput = True

dist = 100 

fc_line = "line feature class"
fc_line_1 = "Sperren_C_1"
arcpy.CopyFeatures_management(fc_line, fc_line_1)
fc_line_FL = arcpy.MakeFeatureLayer_management(fc_line_1, "fc_line")

fc_poly = "Polygon Feature Class"
fc_poly_FL = arcpy.MakeFeatureLayer_management(fc_poly, "fc_poly")

with arcpy.da.SearchCursor(fc_poly_FL, "SHAPE@") as scur:
    for poly, in scur:
        boundary = poly.boundary()
        arcpy.SelectLayerByLocation_management(fc_line_FL, "WITHIN", poly)
        with arcpy.da.UpdateCursor(fc_line_FL, "SHAPE@") as ucur:
            for line, in ucur:
                arr, = line.getPart()
                SR = line.spatialReference

                p1, p2 = arr[0], arr[1]
                angle = math.atan2(p2.Y - p1.Y, p2.X - p1.X)
                p = arcpy.Point(p1.X - dist * math.cos(angle),
                                p1.Y - dist * math.sin(angle))
                arr.insert(0, p)

                pn1, pn = arr[len(arr)-2], arr[len(arr)-1]
                angle = math.atan2(pn.Y - pn1.Y, pn.X - pn1.X)
                p = arcpy.Point(pn.X + dist * math.cos(angle),
                                pn.Y + dist * math.sin(angle))
                arr.append(p)

                line = arcpy.Polyline(arr, SR, True, False)
                line = line.cut(boundary)[1]

                arr, = line.getPart()
                p1, pn = arr[0], arr[len(arr)-1]
                p1.Z, pn.Z = 0, 0
                arr.insert(0, p1)
                arr.append(pn)
                line = arcpy.Polyline(arr, SR, True, False)

                ucur.updateRow([line])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 08:12:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extend-line-not-within-up-to-polygon-feature/m-p/1185381#M64807</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2022-06-23T08:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extend line (not within) up to polygon feature?</title>
      <link>https://community.esri.com/t5/python-questions/extend-line-not-within-up-to-polygon-feature/m-p/1185979#M64821</link>
      <description>&lt;P&gt;Maybe you can store the length of the line (either original line length or after the extension) and then check it after it is cut by the boundary to see if there is a difference and go from there?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 13:06:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extend-line-not-within-up-to-polygon-feature/m-p/1185979#M64821</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-06-24T13:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extend line (not within) up to polygon feature?</title>
      <link>https://community.esri.com/t5/python-questions/extend-line-not-within-up-to-polygon-feature/m-p/1186583#M64833</link>
      <description>&lt;P&gt;Thank you, I will try it.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2022 04:25:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extend-line-not-within-up-to-polygon-feature/m-p/1186583#M64833</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2022-06-27T04:25:18Z</dc:date>
    </item>
  </channel>
</rss>

