<?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: Add / Insert a Feature Set to an existing Feature Service (aka Hosted Feature Layer) in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/add-insert-a-feature-set-to-an-existing-feature/m-p/1537888#M10656</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/649712"&gt;@vmarquart_max-boegl&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have successfully used the below workflow.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Get the Feature Set&lt;/LI&gt;&lt;LI&gt;Get information from the original Feature Layer&lt;/LI&gt;&lt;LI&gt;Define the new Feature Layer&lt;/LI&gt;&lt;LI&gt;Add the new Feature Layer to the Feature Service&lt;/LI&gt;&lt;LI&gt;Add in the Feature Set records&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Code and workflow commented...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.features import FeatureLayerCollection

################################################################################
## USER INPUTS #################################################################

## the item id for the feature service that contains the layer to query
fs_item_id = "FS_ITEM_ID"

## the index of the layer to query (0 if only one layer or the first layer)
lyr_idx = 0

## the item id for the feature service to add the new feature layer to
add_lyr_item_id = "FS_ITEM_ID"

## the name of the new feature layer
lyr_name = "NEW_FEATURE_LAYER"

## the feature layer query
fl_query = "SQL_QUERY"

################################################################################
## ACCESS ARCGIS ONLINE ########################################################

agol = GIS("home")

################################################################################
## GET FEATURE SET INFORMATION #################################################

## get the feature service item that contains the layer to query
fs_item = agol.content.get(fs_item_id)

## get the layer of interest to query
fl = FeatureLayer.fromitem(fs_item, lyr_idx)

## get the feature set
fs = fl.query(fl_query)

################################################################################
## CREATE NEW FEATURE LAYER ####################################################

fl_properties = dict(fl.properties)

## get the feature service item to create new feature layer for
add_lyr_item = agol.content.get(add_lyr_item_id)

## create feature layer definition
fl_definition = {
    "type" : "Feature Layer",
    "name" : lyr_name,
    "geometryType": fl_properties["geometryType"],
    "drawingInfo" : fl_properties["drawingInfo"],
    "fields" : fl_properties["fields"],
    "indexes": fl_properties["indexes"],
    "objectIdField": fl_properties["objectIdField"],
    "uniqueIdField": fl_properties["uniqueIdField"],

}

## create FLC object
flc = FeatureLayerCollection.fromitem(add_lyr_item)

## update the JSON definition fof the feature service to include the layer
flc.manager.add_to_definition({"layers": [fl_definition]})

################################################################################
## ADD RECORDS #################################################################

## re-get the updated item object
add_lyr_item = agol.content.get(add_lyr_item_id)

## get the layer of interest
fl = [lyr for lyr in add_lyr_item.layers if lyr.properties.name == lyr_name][0]

## populate with data
fl.edit_features(adds=fs.features)

################################################################################
print("\nSCRIPT COMPLETE")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Depending on the size of the Feature Set, you might want to break the edit_features into chunks of 2000 records at at time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Sep 2024 17:37:54 GMT</pubDate>
    <dc:creator>Clubdebambos</dc:creator>
    <dc:date>2024-09-12T17:37:54Z</dc:date>
    <item>
      <title>Add / Insert a Feature Set to an existing Feature Service (aka Hosted Feature Layer)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/add-insert-a-feature-set-to-an-existing-feature/m-p/1527226#M10467</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The following code adds a spatially enabled dataframe to a feature service:&lt;/SPAN&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;feature_service_item = sedf.spatial.insert_layer(feature_service = feature_service_item,service_name=new_sublayer_name)&amp;lt;div&amp;gt;&amp;lt;div&amp;gt;&amp;lt;span&amp;gt;However, there happens some type casting under the hood, which I do not want at the moment (e.g. Int32 will be converted to esriFieldTypeString).&amp;lt;div&amp;gt; &amp;lt;div&amp;gt;&amp;lt;div&amp;gt;&amp;lt;div&amp;gt;&amp;lt;span&amp;gt;Is there a possibility to insert a FeatureSet as a new FeatureLayer inside a Feature Service? Like my abovementioned example for a sedf but just for fsets?&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;However, there happens some type casting under the hood, which I do not want at the moment (e.g. Int32 will be converted to esriFieldTypeString).&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Is there a possibility to insert a FeatureSet as a new FeatureLayer inside a Feature Service? Like my abovementioned example for a sedf but just for fsets?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 26 Aug 2024 15:24:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/add-insert-a-feature-set-to-an-existing-feature/m-p/1527226#M10467</guid>
      <dc:creator>vmarquart_max-boegl</dc:creator>
      <dc:date>2024-08-26T15:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Add / Insert a Feature Set to an existing Feature Service (aka Hosted Feature Layer)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/add-insert-a-feature-set-to-an-existing-feature/m-p/1537888#M10656</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/649712"&gt;@vmarquart_max-boegl&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have successfully used the below workflow.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Get the Feature Set&lt;/LI&gt;&lt;LI&gt;Get information from the original Feature Layer&lt;/LI&gt;&lt;LI&gt;Define the new Feature Layer&lt;/LI&gt;&lt;LI&gt;Add the new Feature Layer to the Feature Service&lt;/LI&gt;&lt;LI&gt;Add in the Feature Set records&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Code and workflow commented...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.features import FeatureLayerCollection

################################################################################
## USER INPUTS #################################################################

## the item id for the feature service that contains the layer to query
fs_item_id = "FS_ITEM_ID"

## the index of the layer to query (0 if only one layer or the first layer)
lyr_idx = 0

## the item id for the feature service to add the new feature layer to
add_lyr_item_id = "FS_ITEM_ID"

## the name of the new feature layer
lyr_name = "NEW_FEATURE_LAYER"

## the feature layer query
fl_query = "SQL_QUERY"

################################################################################
## ACCESS ARCGIS ONLINE ########################################################

agol = GIS("home")

################################################################################
## GET FEATURE SET INFORMATION #################################################

## get the feature service item that contains the layer to query
fs_item = agol.content.get(fs_item_id)

## get the layer of interest to query
fl = FeatureLayer.fromitem(fs_item, lyr_idx)

## get the feature set
fs = fl.query(fl_query)

################################################################################
## CREATE NEW FEATURE LAYER ####################################################

fl_properties = dict(fl.properties)

## get the feature service item to create new feature layer for
add_lyr_item = agol.content.get(add_lyr_item_id)

## create feature layer definition
fl_definition = {
    "type" : "Feature Layer",
    "name" : lyr_name,
    "geometryType": fl_properties["geometryType"],
    "drawingInfo" : fl_properties["drawingInfo"],
    "fields" : fl_properties["fields"],
    "indexes": fl_properties["indexes"],
    "objectIdField": fl_properties["objectIdField"],
    "uniqueIdField": fl_properties["uniqueIdField"],

}

## create FLC object
flc = FeatureLayerCollection.fromitem(add_lyr_item)

## update the JSON definition fof the feature service to include the layer
flc.manager.add_to_definition({"layers": [fl_definition]})

################################################################################
## ADD RECORDS #################################################################

## re-get the updated item object
add_lyr_item = agol.content.get(add_lyr_item_id)

## get the layer of interest
fl = [lyr for lyr in add_lyr_item.layers if lyr.properties.name == lyr_name][0]

## populate with data
fl.edit_features(adds=fs.features)

################################################################################
print("\nSCRIPT COMPLETE")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Depending on the size of the Feature Set, you might want to break the edit_features into chunks of 2000 records at at time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2024 17:37:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/add-insert-a-feature-set-to-an-existing-feature/m-p/1537888#M10656</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2024-09-12T17:37:54Z</dc:date>
    </item>
  </channel>
</rss>

