<?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 i need to place line between two feature class in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1253793#M66748</link>
    <description>&lt;P&gt;I have many FC1(pole) and FC2(sub) in my map, I need the Arcpy code for when I select a group of one FC1 and many FC2,&amp;nbsp; and place the FC3 line from FC1 to FC2s at a time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="YuvarajuDhananjay_1-1675259632425.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61828i185BF6260E2CED23/image-size/medium?v=v2&amp;amp;px=400" role="button" title="YuvarajuDhananjay_1-1675259632425.png" alt="YuvarajuDhananjay_1-1675259632425.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Feb 2023 13:55:17 GMT</pubDate>
    <dc:creator>YuvarajuDhananjay</dc:creator>
    <dc:date>2023-02-01T13:55:17Z</dc:date>
    <item>
      <title>i need to place line between two feature class</title>
      <link>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1253793#M66748</link>
      <description>&lt;P&gt;I have many FC1(pole) and FC2(sub) in my map, I need the Arcpy code for when I select a group of one FC1 and many FC2,&amp;nbsp; and place the FC3 line from FC1 to FC2s at a time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="YuvarajuDhananjay_1-1675259632425.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61828i185BF6260E2CED23/image-size/medium?v=v2&amp;amp;px=400" role="button" title="YuvarajuDhananjay_1-1675259632425.png" alt="YuvarajuDhananjay_1-1675259632425.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 13:55:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1253793#M66748</guid>
      <dc:creator>YuvarajuDhananjay</dc:creator>
      <dc:date>2023-02-01T13:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: i need to place line between two feature class</title>
      <link>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1253892#M66752</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;pole_fc = "TestPoints2"
sub_fc = "TestPoints"
line_fc = "TestLines"
common_field = "IntegerField"


# read the pole shapes
pole_dict = {
    id: shape
    for id, shape in arcpy.da.SearchCursor(pole_fc, [common_field, "SHAPE@"])
    )

# start inserting into the line fc
with arcpy.da.InsertCursor(line_fc, ["SHAPE@"]) as i_cursor:
    # loop over the sub fc
    with arcpy.da.SearchCursor(sub_fc, [common_field, "SHAPE@"]) as s_cursor:
        for id, shape in s_cursor:
            # get the corresponding pole, skip if not found
            try:
                pole = pole_dict[id]
            except KeyError:
                continue
            # construct and insert the new line
            line_shape = arcpy.Polyline(arcpy.Array([pole.firstPoint, shape.firstPoint]), pole.spatialReference)
            i_cursor.insertRow([line_shape])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1675267544426.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61860i9CBE4C9301544E0F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1675267544426.png" alt="JohannesLindner_0-1675267544426.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 16:05:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1253892#M66752</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-02-01T16:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: i need to place line between two feature class</title>
      <link>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1253957#M66753</link>
      <description>&lt;P&gt;Similar to JohannesLindner's solution but skips the need for a common field and a join. Instead relies on valid selection. There are many ways to get this kind of output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# Set the name of the point feature layers
points_layer1 = "facilities"
points_layer2 = "pts"
lines_layer = "lines"

# preconditions: select one feature from points_layer1 and one or more from points_layer2
assert arcpy.management.GetCount(points_layer1)[0] == "1", "select exactly 1 point from points_layer1"
assert int(arcpy.management.GetCount(points_layer1)[0]) &amp;gt; 0, "select &amp;gt; 0 point(s) from points_layer2"

# Get the coordinates of the 1 selected feature in points_layer1
with arcpy.da.SearchCursor(points_layer1, ["SHAPE@XY"]) as cursor:
    for row in cursor:
        end_x, end_y  = row[0]
        end_point = arcpy.PointGeometry(arcpy.Point(float(end_x), float(end_y)))

# Create a new feature class to store the lines if needed
if not arcpy.Exists(lines_layer):
    arcpy.management.CreateFeatureclass(arcpy.env.workspace, "lines", "POLYLINE")

# Create an array to store the line geometry
line_array = arcpy.Array()

with arcpy.da.SearchCursor(points_layer2, ["SHAPE@XY"]) as cursor:
    for row in cursor:
        start_x, start_y  = row[0]
        start_point = arcpy.PointGeometry(arcpy.Point(float(start_x), float(start_y)))
        
        # Append the start and end points to the line array
        line_array.append(start_point.centroid)
        line_array.append(end_point.centroid)

        # Create a polyline object from the line array
        line = arcpy.Polyline(line_array)
        line_array.removeAll()
        
        # use the insert cursor to insert the line into the lines feature class
        with arcpy.da.InsertCursor(lines_layer, ["SHAPE@"]) as icursor:
            icursor.insertRow([line])
            
# re-add the lines layer to the map to help refresh the display, symbology is preserved
arcpy.management.MakeFeatureLayer(lines_layer,"lines")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DannyMcVey_0-1675271817825.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61870i38E36EC4F3DBB1E4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DannyMcVey_0-1675271817825.png" alt="DannyMcVey_0-1675271817825.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 17:41:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1253957#M66753</guid>
      <dc:creator>DannyMcVey</dc:creator>
      <dc:date>2023-02-02T17:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: i need to place line between two feature class</title>
      <link>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1254215#M66763</link>
      <description>&lt;P&gt;Danny, the code is running without errors but the lines are placed somewhere not to the pts! and m using &lt;SPAN&gt;WGS 1984 Web Mercator(auxiliary sphere) coordinate system&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="YuvarajuDhananjay_0-1675320925445.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61915iEC42DA9F20D6C523/image-size/medium?v=v2&amp;amp;px=400" role="button" title="YuvarajuDhananjay_0-1675320925445.png" alt="YuvarajuDhananjay_0-1675320925445.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;To fix this issue, i replaced&amp;nbsp;&lt;/SPAN&gt;float(start_x), float(start_x)&lt;SPAN&gt; with &lt;/SPAN&gt;float(start_x), float(start_y)&lt;SPAN&gt;. this time, lines are placed on the pts, but one long line is placed on the downside!!!, and I need one more correction in the code please,&amp;nbsp; the lines layer will be already present in the map, code has to use the same line layer for all the pts. no need to create a line feature every time. ( the line has to start from pole_fc to Subsfc)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="YuvarajuDhananjay_2-1675321768686.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61917i1223FF81736478B3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="YuvarajuDhananjay_2-1675321768686.png" alt="YuvarajuDhananjay_2-1675321768686.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 07:25:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1254215#M66763</guid>
      <dc:creator>YuvarajuDhananjay</dc:creator>
      <dc:date>2023-02-02T07:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: i need to place line between two feature class</title>
      <link>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1254447#M66772</link>
      <description>&lt;P&gt;Ah thanks for finding that typo. I'm not seeing the "one long line is placed on the downside" on my end. Could it be left over from before you fixed the typo?&lt;/P&gt;&lt;P&gt;As far as the lines layer being already present in the map, that should be taken care of by:&lt;/P&gt;&lt;PRE&gt;if not arcpy.Exists(lines_layer):&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="2023-02-02_9-49-59.gif" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61969iE91521A77A232F2F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2023-02-02_9-49-59.gif" alt="2023-02-02_9-49-59.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that helps! Have a good one.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 17:51:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/i-need-to-place-line-between-two-feature-class/m-p/1254447#M66772</guid>
      <dc:creator>DannyMcVey</dc:creator>
      <dc:date>2023-02-02T17:51:47Z</dc:date>
    </item>
  </channel>
</rss>

