<?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: Create polylines from sets of coordinates and convert to feature class in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-polylines-from-sets-of-coordinates-and/m-p/1299892#M8797</link>
    <description>&lt;P&gt;Thank you so much! I had no idea the XY to lines tool existed but it is exactly what I was looking for.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Jun 2023 18:38:49 GMT</pubDate>
    <dc:creator>wavey</dc:creator>
    <dc:date>2023-06-15T18:38:49Z</dc:date>
    <item>
      <title>Create polylines from sets of coordinates and convert to feature class</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-polylines-from-sets-of-coordinates-and/m-p/1298982#M8778</link>
      <description>&lt;P&gt;I have a csv with data that contains 4 sets of coordinates per line. start_x, start_y, end_x, and end_y which correspond to the start and end of individual line segments. The goal is to take these coordinates, load them into a dataframe, create polylines, and then save them as a feature class in the database.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm able to get the points loaded into a pandas dataframe, use the Polyline function from arcgis.geometry to create polyline objects, and store them in the pandas dataframe. Before storing them back in the dataframe I check to make sure that the resulting polyline objects are valid with .is_valid and they all return true. However when I try to convert to a spatially enabled dataframe I get an error saying: Invalid geometry type for method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not entirely sure where to go from here. Any suggestions about a better way to accomplish this or how to deal with converting to SEDF and then feature class would be greatly appreciated.&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 the csv file as a df
df = pd.read_csv('sample_vals.csv')

# Define the function which takes x, y, and wkid inputs and converts them into an arcgis geometry polyline object
def coordToPolyline(coord_list, input_wkid):

    line_dict = {"paths": coord_list, "spatialReference": {"wkid": input_wkid}}
    
    output_polyline = Polyline(line_dict)
    
    return output_polyline


# Create the SHAPE column in the pandas dataframe
df['SHAPE'] = ''
print(df)

# Run through the pandas dataframe and calculate the lines
for i in range(0, len(df)):

    # Grab the start_x, start_y, end_x, and end_y and put into a list to use for Polyline
    initial_x = df.iloc[i]['start_x']
    initial_y = df.iloc[i]['start_y']
    end_x = df.iloc[i]['end_x']
    end_y = df.iloc[i]['end_y']
    
    # Populate the list
    iter_coord_list = []
    iter_coord_list.append([initial_x, initial_y])
    iter_coord_list.append([end_x, end_y])
    
    # Call the function and pass the coord list and wkid=2276
    iter_polyline_obj = coordToPolyline(iter_coord_list, 2276)
    
    # Verify that the polyline object created is valid
    if iter_polyline_obj.is_valid():
        # If Polyline object is valid then add it to the pandas dataframe in the SHAPE column at index i
        df.at[i, 'SHAPE'] = iter_polyline_obj
        print(iter_polyline_obj.is_valid())
        
    else:
        print('One or more of the calculated Polyline objects is not valid.')


# Try to go to an sdf
sdf = GeoAccessor.from_df(df, geometry_column='SHAPE')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 23:58:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-polylines-from-sets-of-coordinates-and/m-p/1298982#M8778</guid>
      <dc:creator>wavey</dc:creator>
      <dc:date>2023-06-13T23:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create polylines from sets of coordinates and convert to feature class</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-polylines-from-sets-of-coordinates-and/m-p/1299038#M8779</link>
      <description>&lt;P&gt;Hi wavey,&lt;/P&gt;&lt;P&gt;Why not simply use tool &lt;A href="https://pro.arcgis.com/fr/pro-app/latest/tool-reference/data-management/xy-to-line.htm" target="_self"&gt;XY to lines&lt;/A&gt; ?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis
input_table = r'C:\temp\sample_vals.csv'
out_lines = r'C:\temp\Default.gdb\sample_vals'
# XY To Line
arcpy.XYToLine_management(input_table, out_lines, "start_x", "start_y", "end_x", "end_y", "PLANAR","","NAD_1983_StatePlane_Texas_North_Central_FIPS_4202_Feet" )&lt;/LI-CODE&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Fred&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 08:11:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-polylines-from-sets-of-coordinates-and/m-p/1299038#M8779</guid>
      <dc:creator>FrédéricPRALLY</dc:creator>
      <dc:date>2023-06-14T08:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create polylines from sets of coordinates and convert to feature class</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-polylines-from-sets-of-coordinates-and/m-p/1299892#M8797</link>
      <description>&lt;P&gt;Thank you so much! I had no idea the XY to lines tool existed but it is exactly what I was looking for.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 18:38:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-polylines-from-sets-of-coordinates-and/m-p/1299892#M8797</guid>
      <dc:creator>wavey</dc:creator>
      <dc:date>2023-06-15T18:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: Create polylines from sets of coordinates and convert to feature class</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-polylines-from-sets-of-coordinates-and/m-p/1312791#M8903</link>
      <description>&lt;P&gt;Sorry but that solution still doesn't solve the question.&amp;nbsp; How is one suppose to do this with spatial dataframes (pandas or esri)??&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 19:52:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-polylines-from-sets-of-coordinates-and/m-p/1312791#M8903</guid>
      <dc:creator>sofoo</dc:creator>
      <dc:date>2023-07-27T19:52:54Z</dc:date>
    </item>
  </channel>
</rss>

