<?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: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1366898#M69548</link>
    <description>&lt;P&gt;Hi Blake, in your post you say that you cannot truncate/append a&amp;nbsp; feature service hosted in standalone GIS Server.&amp;nbsp; Is the same true if the server is federated with portal?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been able to truncate web layers in a hosted feature service but I am having a heck of a time appending data back into the feature service.&amp;nbsp; &amp;nbsp;I am missing something to "connect the dots" so to speak.&amp;nbsp; &amp;nbsp;Seems like this would work just fine, but I have had some mixed results when trying to do this.&amp;nbsp; What is the best way to update a hosted feature service in Enterprise using Python API so that we dont overwrite all the pop up settings, etc that occurs when simply republishing the service?&lt;/P&gt;&lt;P&gt;Also seems if a feature service has multiple layers and layer(0) in the service is truncated, then Python API cant return the layer.item for any of the remining layers in the feature service.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help you can give would be greatly appreciated.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jan 2024 18:00:22 GMT</pubDate>
    <dc:creator>ChrisStiwinter1</dc:creator>
    <dc:date>2024-01-05T18:00:22Z</dc:date>
    <item>
      <title>Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343473#M69070</link>
      <description>&lt;P&gt;I am beginning to research the best way to take a suite of existing arcgis python tools and incorporating the python api so the tools can be enhanced to also work with feature services.&lt;/P&gt;&lt;P&gt;The tools are currently taking input fgdbs or egdbs, reading through them, some are editing features, many compare feature attributes to other 'rules' fgdbs... The tools are pretty complex, and I am trying to figure out which way to approach the task.&lt;/P&gt;&lt;P&gt;Ideally the existing tools would just be enhanced with the capabilities of the python api, but I suppose it could be the other way around that new tools are started with python api and they maybe then call the arcpy portions.&lt;/P&gt;&lt;P&gt;Thoughts, community?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 18:45:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343473#M69070</guid>
      <dc:creator>SeanT</dc:creator>
      <dc:date>2023-10-30T18:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343511#M69071</link>
      <description>&lt;P&gt;I'm not quite following because you mention wanting to use the API for Python to work with feature services, but you explained only how your scripts use file geodatabases. What do you plan to do with feature services?&lt;/P&gt;&lt;P&gt;You could take a look at this thread about modularizing Python Toolboxes for inspiration. I do something similar with our Python scheduled tasks, they import a custom library with commonly used functions.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-questions/python-tool-management-system/m-p/1327512#U1327512" target="_blank"&gt;Python Tool Management System - Esri Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 19:49:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343511#M69071</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-10-30T19:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343561#M69074</link>
      <description>&lt;P&gt;I have 50+ clients under the same umbrella, but they may all do things a bit different towards the same end with similar data and schema, some use fgdbs, some use SDE, some have migrated into feature services (apologies if my use of terminology isn't exact).&lt;/P&gt;&lt;P&gt;Ideally each tool that is currently written with arcpy can have the python api added to it to make it even more capable, but not sure that is possible. The existing tools may be 1000+ lines of code with some coming from separate modules.&lt;/P&gt;&lt;P&gt;The tools scan through the input which is usually an entire dataset of facility info organized in feature datasets. The input may also be compared to a separate input real property dataset, as well as another set of rules for specific data schema rules.&lt;/P&gt;&lt;P&gt;So like say a client's facility data is in a feature service, they want to run the tools against their feature service instead of a fgdb or sde, but they want all the same checks, comparisons, edits, outputs to occur that the arcpy tool is doing.&lt;/P&gt;&lt;P&gt;I am having trouble conceptualizing this, hence my question here.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 21:20:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343561#M69074</guid>
      <dc:creator>SeanT</dc:creator>
      <dc:date>2023-10-30T21:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343568#M69075</link>
      <description>&lt;P&gt;So to put it another way, you want to have one tool that can accept inputs of a gdb feature class or feature service and perform the same logic?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 21:32:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343568#M69075</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-10-30T21:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343570#M69076</link>
      <description>&lt;P&gt;yes! if possible.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 21:33:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343570#M69076</guid>
      <dc:creator>SeanT</dc:creator>
      <dc:date>2023-10-30T21:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343575#M69077</link>
      <description>&lt;P&gt;Can you clarify how the feature services are hosted/accessed? (Standalone ArcGIS Server, hosted in Portal data store, uploaded to ArcGIS Online?)&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 21:40:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343575#M69077</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-10-30T21:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343577#M69078</link>
      <description>&lt;P&gt;I'd have to find out.&lt;/P&gt;&lt;P&gt;How will the different storage methods affect the code?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 21:43:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343577#M69078</guid>
      <dc:creator>SeanT</dc:creator>
      <dc:date>2023-10-30T21:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343586#M69079</link>
      <description>&lt;P&gt;Some operations you can do on a feature class in a geodatabase might not be possible with a feature service. For example, you can't truncate/append, you would have to delete all rows, then insert all rows (for a traditional feature service hosted in standalone ArcGIS Server) and it would take considerably longer compared to a gdb fc. Also, you can't use something like &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/editor.htm" target="_self"&gt;arcpy.Editor&lt;/A&gt; or&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_self"&gt;calculate field&lt;/A&gt;; although you can do more with &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.geoanalytics.toc.html" target="_self"&gt;GeoAnalytics tools&lt;/A&gt; if you have access to that.&lt;/P&gt;&lt;P&gt;So, it depends on a lot of different things. I would guess that "pretty complex" scripts have more than just some arcpy cursors making a few data edits. You'd have to find matching capabilities in the&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/api-reference/" target="_self"&gt;ArcGIS API for Python&lt;/A&gt;&amp;nbsp;or the &lt;A href="https://developers.arcgis.com/rest/" target="_self"&gt;ArcGIS REST API&lt;/A&gt; directly.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 22:09:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343586#M69079</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-10-30T22:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343593#M69080</link>
      <description>&lt;P&gt;Thank you for the explanation... helps me put my concerns into a better perspective.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 22:36:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1343593#M69080</guid>
      <dc:creator>SeanT</dc:creator>
      <dc:date>2023-10-30T22:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1366898#M69548</link>
      <description>&lt;P&gt;Hi Blake, in your post you say that you cannot truncate/append a&amp;nbsp; feature service hosted in standalone GIS Server.&amp;nbsp; Is the same true if the server is federated with portal?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been able to truncate web layers in a hosted feature service but I am having a heck of a time appending data back into the feature service.&amp;nbsp; &amp;nbsp;I am missing something to "connect the dots" so to speak.&amp;nbsp; &amp;nbsp;Seems like this would work just fine, but I have had some mixed results when trying to do this.&amp;nbsp; What is the best way to update a hosted feature service in Enterprise using Python API so that we dont overwrite all the pop up settings, etc that occurs when simply republishing the service?&lt;/P&gt;&lt;P&gt;Also seems if a feature service has multiple layers and layer(0) in the service is truncated, then Python API cant return the layer.item for any of the remining layers in the feature service.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help you can give would be greatly appreciated.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 18:00:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1366898#M69548</guid>
      <dc:creator>ChrisStiwinter1</dc:creator>
      <dc:date>2024-01-05T18:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1366924#M69550</link>
      <description>&lt;P&gt;What method are you using when you say you "truncate web layers in a hosted feature service"? &amp;nbsp;It looks like you need to use &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.delete_features" target="_self"&gt;delete_features()&lt;/A&gt;, which could take a while depending on how many records you're working with. This will never match simplicity and performance of a database truncate though.&lt;/P&gt;&lt;P&gt;I see there is also an &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.append" target="_self"&gt;append()&lt;/A&gt; method for a FeatureLayer in the ArcGIS API for Python; I didn't know about this.&amp;nbsp;Although, a note on &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/append-feature-service-layer-.htm" target="_self"&gt;append from the REST API doc&lt;/A&gt;:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Feature service&lt;/SPAN&gt;&lt;SPAN class=""&gt;Append&lt;/SPAN&gt;&lt;SPAN&gt;capabilities must be enabled for the&lt;/SPAN&gt;&lt;SPAN class=""&gt;append&lt;/SPAN&gt;&lt;SPAN&gt;operation to be used by nonadministrative users. Organization administrators, or the service owner, can use the&lt;/SPAN&gt;&lt;SPAN class=""&gt;append&lt;/SPAN&gt;&lt;SPAN&gt;operation without having the&lt;/SPAN&gt;&lt;SPAN class=""&gt;Append&lt;/SPAN&gt;&lt;SPAN&gt;capability enabled on the feature service. The&lt;/SPAN&gt;&lt;SPAN class=""&gt;Append&lt;/SPAN&gt;&lt;SPAN&gt;capability needs to be added to the service capabilities only if the service owner or organization administrators need to allow nonadministrative users to append data to a feature service.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;I haven't used the ArcGIS API for Python or hosted feature layers in Portal much so I'm sorry I can't guide you much more. If you have a specific question about deleting features from multiple layers in a feature service, you should create a separate question for that.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 18:54:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1366924#M69550</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-01-05T18:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1366937#M69551</link>
      <description>&lt;P&gt;Thanks for reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;After signing into portal i get the itemID of the feature service using content.get().&amp;nbsp; Then assign this to a variable.&amp;nbsp; Use this variable to access the layers of the feature service, once I have the layer I want to truncate, i assign it to another variable then truncate using&amp;nbsp; layervariable.manager.truncate().&amp;nbsp; This works fine.&amp;nbsp; It is appending that is causing issues.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ill just keep working on it, i know i am missing something small.&amp;nbsp; I am the admin/owner of the feature service so should not have problem with append permissions, I think I need to supply more parameters to the append tool even though schema matches between layers, maybe I will need to provide field mappings..&lt;/P&gt;&lt;P&gt;Thanks again&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 19:17:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1366937#M69551</guid>
      <dc:creator>ChrisStiwinter1</dc:creator>
      <dc:date>2024-01-05T19:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1366961#M69553</link>
      <description>&lt;P&gt;Cool, thanks for letting me know about the truncate operation for FeatureLayer in the REST API!&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/rest/services-reference/online/truncate-feature-layer-.htm" target="_blank"&gt;Truncate (Feature Layer)—ArcGIS REST APIs | ArcGIS Developers&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 19:54:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1366961#M69553</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-01-05T19:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Best Practice for Enhancing Arcpy Tools with ArcGIS API for Python to Process Feature Services</title>
      <link>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1368385#M69600</link>
      <description>&lt;P&gt;Ok, So after working on this some more, I am now able to truncate and append into a hosted feature layer in Enterprise using data from disk.&amp;nbsp; My approach is to use Python Api to access the layers in the portal and truncate them.&amp;nbsp; Next, I use the append function in ArcPRO to update the hosted feature classes with a feature class from disk.&amp;nbsp; A little different then using the append function in Python API that is looking for source data as an item published to portal vs feature class on&amp;nbsp; disk.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Use Python API to query the portal for the itemid ~&amp;nbsp; gis.content.get(itemid) set to a variable.&lt;/P&gt;&lt;P&gt;Once you have item id you can access the feature layers ~ use above variable to access layers&amp;nbsp; i.e. variable.layers.&lt;/P&gt;&lt;P&gt;Once you have listing of layers in the feature service you can access them by assigning each layer to a variable . variable.layers[0] for first layer, variable.layers[1] for second layer, etc..&amp;nbsp; This will return the url endpoint of that layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;once you have the layer url you can use the truncate/append function to update the hosted layers in the service.&amp;nbsp; &amp;nbsp;variable.layers.manager.truncate(), then I append in ArcPRO using a feature class that is stored on disk not in portal, thus a little different than using API for existing portal item.&lt;/P&gt;&lt;P&gt;variable.manager.truncate()&lt;BR /&gt;arcpy.management.Append(&lt;BR /&gt;inputs=r'C:/CustomerNotification/CN.gdb/ALL',&lt;BR /&gt;target=variable.url,&lt;BR /&gt;schema_type="TEST",&lt;BR /&gt;field_mapping=None,&lt;BR /&gt;subtype="",&lt;BR /&gt;expression="",&lt;BR /&gt;match_fields=None,&lt;BR /&gt;update_geometry="UPDATE_GEOMETRY")&lt;/P&gt;&lt;P&gt;This will work to update hosted feature classes in Enterprise with data from local disk without having to overwrite the service.&amp;nbsp; Now, some caveats:&lt;/P&gt;&lt;P&gt;- When a feature service is a hosted service and the data is copied to the GIS Server, all the field names are changed to lowercase.&amp;nbsp; If your source for the append has the same schema but some field names are uppercase, the append will run without error but no features will be added...&amp;nbsp;&lt;/P&gt;&lt;P&gt;- This method will not cause the objectids to increase, as is the case with deleting features then using add_edits to add new features back in.&amp;nbsp;&lt;/P&gt;&lt;P&gt;- This method runs slower than using json and parsing the source data then use REST calls to delete and add/update features.&amp;nbsp; using REST to update via json strings seems to be the fastest, objectids will increase.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just my experience, hope this can help someone else out.&amp;nbsp; &amp;nbsp;the lowercase fieldname change when hosting the data was causing an issue for my script, once I realized that I was on my way to success.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 15:57:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/best-practice-for-enhancing-arcpy-tools-with/m-p/1368385#M69600</guid>
      <dc:creator>ChrisStiwinter1</dc:creator>
      <dc:date>2024-01-10T15:57:16Z</dc:date>
    </item>
  </channel>
</rss>

