<?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 Feature Service with Feature Layer and Table from Shapefile and CSV in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-feature-service-with-feature-layer-and/m-p/1169319#M7349</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Have you considered using the manager class of the FeatureLayerCollection object? You could add a table to the definition created when publishing your shapefile, then append your CSV data.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html?highlight=add%20definition#arcgis.features.managers.FeatureLayerCollectionManager.add_to_definition" target="_blank"&gt;arcgis.features.managers module — arcgis 2.0.0 documentation&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Apr 2022 14:27:47 GMT</pubDate>
    <dc:creator>HamishMorton</dc:creator>
    <dc:date>2022-04-29T14:27:47Z</dc:date>
    <item>
      <title>Create Feature Service with Feature Layer and Table from Shapefile and CSV</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-feature-service-with-feature-layer-and/m-p/1169312#M7348</link>
      <description>&lt;P&gt;I have a point shapefile with one field, a unique id called reg_no. I have a csv file with a reg_no column and other fields. I want to create a Feature Service in AGOL with the point geometry as a Feature Layer and the csv file as a Table. The goal is to do this purely with the ArcGIS API for Python. I do not want to use ArcMap/Pro or arcpy. I can add the shapefile and csv separately to AGOL and create separate Feature Services, but cannot get them in the same Feature Service. Once in the same Feature Service I will create a relationship between the Feature Layer and the Table so when you click on a point in a webmap you can access the Table data by selecting Show Related Records option in the popup.&lt;/P&gt;&lt;P&gt;I have tried adding the shapefile and the csv file to a zipped folder, adding to AGOL and publishing, as shown below, but this simply adds the shapefile as a point layer in the Feature Service. When looking at the contents I can see the shapefile item has been added from the zipped folder but nothing happens the csv file.&lt;/P&gt;&lt;PRE&gt;from arcgis import GIS

agol = GIS("home")
niah_zip = r"C:\Users\*****\Documents\Training\Data\NIAH.zip"
niah_agol = agol.content.add({}, niah_zip)
niah_fs = niah_agol.publish()&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Apr 2022 14:09:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-feature-service-with-feature-layer-and/m-p/1169312#M7348</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2022-04-29T14:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create Feature Service with Feature Layer and Table from Shapefile and CSV</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-feature-service-with-feature-layer-and/m-p/1169319#M7349</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Have you considered using the manager class of the FeatureLayerCollection object? You could add a table to the definition created when publishing your shapefile, then append your CSV data.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html?highlight=add%20definition#arcgis.features.managers.FeatureLayerCollectionManager.add_to_definition" target="_blank"&gt;arcgis.features.managers module — arcgis 2.0.0 documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 14:27:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-feature-service-with-feature-layer-and/m-p/1169319#M7349</guid>
      <dc:creator>HamishMorton</dc:creator>
      <dc:date>2022-04-29T14:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create Feature Service with Feature Layer and Table from Shapefile and CSV</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-feature-service-with-feature-layer-and/m-p/1169365#M7352</link>
      <description>&lt;P&gt;Thanks for the reply&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/238758"&gt;@HamishMorton&lt;/a&gt;, I did consider it, I was hoping there was a way to zip up shapefiles and CSVs and tell AGOL how to publish. Or even publish separately; the shapefile and the CSV as a table in two different feature services and combine easily. But it looks like you're correct, the best way is probably to add the structure/schema to the definition and then append in, and delete any items not required after that. Cheers.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 15:41:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-feature-service-with-feature-layer-and/m-p/1169365#M7352</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2022-04-29T15:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create Feature Service with Feature Layer and Table from Shapefile and CSV</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-feature-service-with-feature-layer-and/m-p/1181101#M7464</link>
      <description>&lt;P&gt;Just to confirm that this workflow does work. First you get the table definition as a dictionary&lt;/P&gt;&lt;LI-CODE lang="python"&gt;hts = agol.content.get("***item_id***")
table = Table(hts.tables[0].url, agol)

table_def = dict(table.properties)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then add that to the Feature Layer Collection&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fs = agol.content.get("***item_id***")

flc = FeatureLayerCollection(fs.url, agol)

flc.manager.add_to_definition({"tables" : [table_def]})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use the Content Manager analyze function on the original CSV uploaded&lt;/P&gt;&lt;LI-CODE lang="python"&gt;csv = agol.content.analyze(
    item ="***item_id***",
    file_type = "csv",
    geocoding_service = None,
    location_type = None
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And append in data...&lt;/P&gt;&lt;LI-CODE lang="python"&gt;print(tbl.append(
    item_id = "***item_id***",
    upload_format = "csv",
    source_info = csv,
    upsert = False
))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 14:59:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-feature-service-with-feature-layer-and/m-p/1181101#M7464</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2022-06-08T14:59:40Z</dc:date>
    </item>
  </channel>
</rss>

