<?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 I cannot save queried features as file gdb on AGOL using python in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/i-cannot-save-queried-features-as-file-gdb-on-agol/m-p/1496350#M10230</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to save the query results as a file gdb using python (arcgis api for python) but keep getting this error:&lt;/P&gt;&lt;P&gt;"Failed to export to File Geodatabase: The Product License has not been initialized."&lt;/P&gt;&lt;P&gt;I googled about it but could not find any solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do appreciate any help.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from datetime import datetime
import os

try:
    # Connect to Portal
    org = '**unspecified**'
    username = os.environ.get('AGOL_SCRIPT_USER')
    password = os.environ.get('AGOL_SCRIPT_PASS')

    # Initialize GIS object with license check
    gis = GIS(org, username, password)

    # Check if the GIS object is valid
    if not gis:
        raise Exception("Failed to initialize ArcGIS Online connection")

    print("Connected to ArcGIS Online")

    # Define feature service and query parameters
    feature_layer_id = "**unspecified**"

    # Get the feature layer
    feature_layer_item = gis.content.get(feature_layer_id)
    feature_layer = FeatureLayer.fromitem(feature_layer_item)

    # Define query parameters
    where_clause = "requestorCode = 'R7'"
    out_fields = "*" 

    # Perform the query
    query_result = feature_layer.query(where=where_clause,
                                       out_fields=out_fields,
                                       return_geometry=True)

    # Check if there are features returned
    if not query_result.features:
        raise Exception("No features matching the query criteria")

    # FGDB name
    file_gdb_name = "test.gdb"

    # Define the save location for the File Geodatabase
    gdb_path = f"/arcgis/home/{file_gdb_name}"

    # Save the query result to a File Geodatabase
    query_result.save(gdb_path, f"{file_gdb_name.split('.')[0]}")

    print(f"Exported queried output to File Geodatabase: {gdb_path}")

except Exception as e:
    print(f"Failed to export to File Geodatabase: {str(e)}")&lt;/LI-CODE&gt;</description>
    <pubDate>Sun, 23 Jun 2024 18:18:02 GMT</pubDate>
    <dc:creator>mike_totti</dc:creator>
    <dc:date>2024-06-23T18:18:02Z</dc:date>
    <item>
      <title>I cannot save queried features as file gdb on AGOL using python</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/i-cannot-save-queried-features-as-file-gdb-on-agol/m-p/1496350#M10230</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to save the query results as a file gdb using python (arcgis api for python) but keep getting this error:&lt;/P&gt;&lt;P&gt;"Failed to export to File Geodatabase: The Product License has not been initialized."&lt;/P&gt;&lt;P&gt;I googled about it but could not find any solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do appreciate any help.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from datetime import datetime
import os

try:
    # Connect to Portal
    org = '**unspecified**'
    username = os.environ.get('AGOL_SCRIPT_USER')
    password = os.environ.get('AGOL_SCRIPT_PASS')

    # Initialize GIS object with license check
    gis = GIS(org, username, password)

    # Check if the GIS object is valid
    if not gis:
        raise Exception("Failed to initialize ArcGIS Online connection")

    print("Connected to ArcGIS Online")

    # Define feature service and query parameters
    feature_layer_id = "**unspecified**"

    # Get the feature layer
    feature_layer_item = gis.content.get(feature_layer_id)
    feature_layer = FeatureLayer.fromitem(feature_layer_item)

    # Define query parameters
    where_clause = "requestorCode = 'R7'"
    out_fields = "*" 

    # Perform the query
    query_result = feature_layer.query(where=where_clause,
                                       out_fields=out_fields,
                                       return_geometry=True)

    # Check if there are features returned
    if not query_result.features:
        raise Exception("No features matching the query criteria")

    # FGDB name
    file_gdb_name = "test.gdb"

    # Define the save location for the File Geodatabase
    gdb_path = f"/arcgis/home/{file_gdb_name}"

    # Save the query result to a File Geodatabase
    query_result.save(gdb_path, f"{file_gdb_name.split('.')[0]}")

    print(f"Exported queried output to File Geodatabase: {gdb_path}")

except Exception as e:
    print(f"Failed to export to File Geodatabase: {str(e)}")&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 23 Jun 2024 18:18:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/i-cannot-save-queried-features-as-file-gdb-on-agol/m-p/1496350#M10230</guid>
      <dc:creator>mike_totti</dc:creator>
      <dc:date>2024-06-23T18:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: I cannot save queried features as file gdb on AGOL using python</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/i-cannot-save-queried-features-as-file-gdb-on-agol/m-p/1496375#M10231</link>
      <description>&lt;P&gt;I could be wrong but I believe this method requires an ArcPy license.&amp;nbsp; A few things to check:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Do you have access to ArcPy (this would be via ArcGIS Pro)?&lt;/LI&gt;&lt;LI&gt;Is the Python interpreter you're using to run this the same one that's currently activated for ArcGIS Pro?&lt;/LI&gt;&lt;LI&gt;If you're using an AGOL/Enterprise-based license for Pro, are you logged in?&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 24 Jun 2024 00:31:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/i-cannot-save-queried-features-as-file-gdb-on-agol/m-p/1496375#M10231</guid>
      <dc:creator>MobiusSnake</dc:creator>
      <dc:date>2024-06-24T00:31:55Z</dc:date>
    </item>
  </channel>
</rss>

