<?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 a Layer object for hosted feature layer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152765#M64009</link>
    <description>&lt;P&gt;Sorry, I had an error in my last post and wasn't sure how quickly I could correct it but here we are.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Add data from path, making sure to include the index#&lt;/LI&gt;&lt;LI&gt;Make layer from a selection by attributes&lt;/LI&gt;&lt;LI&gt;Remove original layer.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Not as clean as I imagine either of us would like, but it does work.&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;p = arcpy.mp.ArcGISProject("CURRENT")
mapA = p.activeMap
hostedFC = 'https://services1.arcgis.com/.../0' # The layer you're querying
                                                # Make sure to include the index number or else it'll grab you the group layer, and that won't work.
hostLay= mapA.addDataFromPath(hostedFC)         # Add data
lyrAlias = hostLay.name + "_Selection"          # Name the selection layer.

arcpy.management.MakeFeatureLayer(hostLay, lyrAlias, "FID = 299")

mapA.removeLayer(hostLay)&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;Hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: Don's answer is far more elegant.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Mar 2022 22:42:35 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2022-03-10T22:42:35Z</dc:date>
    <item>
      <title>Create a Layer object for hosted feature layer</title>
      <link>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152738#M64007</link>
      <description>&lt;P&gt;I'm trying to write a Python script that queries a hosted feature layer in AGOL, and then use returned records as the input for some arcpy geoprocessing commands to update a mosaic dataset. I am able to do the query in Pro if I manually the hosted feature layer to a map, and then just use the layer name as the input for arcpy.management.SelectLayerByAttribute.&lt;/P&gt;&lt;P&gt;However I'm having trouble figuring out how to create a "layer" object in Arcpy from a hosted feature layer. "Make Feature Layer" seems to work only for feature classes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd prefer not to run the script as a Notebook using ArcGIS Python API as there are some local file system tasks that I want to handle.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 21:14:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152738#M64007</guid>
      <dc:creator>MichaelWen_Timmons</dc:creator>
      <dc:date>2022-03-10T21:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Layer object for hosted feature layer</title>
      <link>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152765#M64009</link>
      <description>&lt;P&gt;Sorry, I had an error in my last post and wasn't sure how quickly I could correct it but here we are.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Add data from path, making sure to include the index#&lt;/LI&gt;&lt;LI&gt;Make layer from a selection by attributes&lt;/LI&gt;&lt;LI&gt;Remove original layer.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Not as clean as I imagine either of us would like, but it does work.&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;p = arcpy.mp.ArcGISProject("CURRENT")
mapA = p.activeMap
hostedFC = 'https://services1.arcgis.com/.../0' # The layer you're querying
                                                # Make sure to include the index number or else it'll grab you the group layer, and that won't work.
hostLay= mapA.addDataFromPath(hostedFC)         # Add data
lyrAlias = hostLay.name + "_Selection"          # Name the selection layer.

arcpy.management.MakeFeatureLayer(hostLay, lyrAlias, "FID = 299")

mapA.removeLayer(hostLay)&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;Hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: Don's answer is far more elegant.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 22:42:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152765#M64009</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-03-10T22:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Layer object for hosted feature layer</title>
      <link>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152766#M64010</link>
      <description>&lt;P&gt;You can create a layer from an AGOL hosted feature layer by referencing the hosted feature layer's URL. For example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;url = 'https://services2.arcgis.com/dJOijx2lWTlGQBDJ/arcgis/rest/services/CW_3863/FeatureServer/0'
arcpy.management.MakeFeatureLayer(url, 'NewLayer')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 22:33:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152766#M64010</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-03-10T22:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Layer object for hosted feature layer</title>
      <link>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152772#M64011</link>
      <description>&lt;P&gt;I got an "Input features: Dataset "&lt;A href="https://services.arcgis.com..../FeatureServer" target="_blank"&gt;https://services.arcgis.com..../FeatureServer&lt;/A&gt;" does not exist or is not supported" error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 22:51:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152772#M64011</guid>
      <dc:creator>MichaelWen_Timmons</dc:creator>
      <dc:date>2022-03-10T22:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Layer object for hosted feature layer</title>
      <link>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152773#M64012</link>
      <description>&lt;P&gt;Make sure to include the feature class's index number; right now you're pulling the group layer.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;"&lt;/SPAN&gt;&lt;A href="https://services.arcgis.com..../FeatureServer" target="_blank" rel="nofollow noopener noreferrer"&gt;https://services.arcgis.com..../FeatureServer/0&lt;/A&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 22:55:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-a-layer-object-for-hosted-feature-layer/m-p/1152773#M64012</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-03-10T22:55:20Z</dc:date>
    </item>
  </channel>
</rss>

