<?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 Correctly returning results from custom web tool in ArcGIS Online Developers Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-developers-questions/correctly-returning-results-from-custom-web-tool/m-p/1571246#M1542</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;(This was previously posted to the ArcGIS Notebook community, but I'm re-trying here since I did not get any responses).&lt;/P&gt;&lt;P&gt;I'm new to python for ArcGIS and am working on creating my first custom web tool (by publishing a Notebook as a custom web tool). The basic process of the web tool is to get a polygon from an external URL (available as a zipped shapefile, a geotif, and a png) and then return that polygon as an output parameter form the tool.&lt;/P&gt;&lt;P&gt;I currently am able to successfully use the shapefile URL, then convert that to a featureset and successfully return it. However, my current road block is figuring out how to alter the symbology of the result layer without having to publish it as a service first. The polygon is very complex, so the default border that AGOL applies tends to mis-represent the polygon. I tried using the TIF and PNG formats to return a raster representation instead, but I couldn't make this work (the tool would end with an error stating that it "failed to presist output values files for web tool").&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my questions are:&lt;/P&gt;&lt;P&gt;1) Is it possible to define the symbology of my feature set (possible as a feature collection) before I return it as an output parameter from the web tool?&lt;/P&gt;&lt;P&gt;2) Since the polygon is quite complex (picture a cellular coverage map), would I be better off trying to return this as a raster output instead?&lt;/P&gt;&lt;P&gt;Here is what I'm currently trying for the FeatureSet/FeatureCollection route, but it doesn't look like I'm successfully returning the feature collection to the app.&lt;/P&gt;&lt;PRE&gt;# Convert shapefile to featureSet
if "ENB_JOBID" in os.environ:
    import requests
    import zipfile
    import os
    from arcgis.gis import GIS
    from arcgis.features import FeatureSet, FeatureCollection, GeoAccessor, GeoSeriesAccessor
   
    # Download the ZIP file
    zip_path = "shapefile.zip"
    response = requests.get(shp_url)
    with open(zip_path, "wb") as f:
        f.write(response.content)
    
    # Extract the ZIP file
    output_dir = os.path.join(os.environ["ENB_JOBID"], "zip")
    os.makedirs(output_dir, exist_ok=True)
    with zipfile.ZipFile(zip_path, "r") as zip_ref:
        zip_ref.extractall(output_dir)
    
    # Locate the .shp file
    shapefile_path = None
    for root, dirs, files in os.walk(output_dir):
        for file in files:
            if file.endswith(".shp"):
                shapefile_path = os.path.join(root, file)
                break
    if shapefile_path:
        print("SHP Path: ", shapefile_path)
    else:
        raise FileNotFoundError("Shapefile (.shp) not found in the extracted ZIP.")
    
    # Load the shapefile into a spatially enabled DataFrame
    sdf = GeoAccessor.from_featureclass(shapefile_path)
    
    #convert to featureset
    output_fs = FeatureSet.from_dataframe(sdf)
    if output_fs:
        print("Output featureSet created.")

# Define DrawingInfo (symbology settings)
drawing_props = {
        "renderer": {
          "type": "simple",
          "symbol": {
            "type": "esriSFS",
            "style": "esriSFSSolid",
            "color": [
              252,
              193,
              184,
              255
            ],
            "outline": {
              "type": "esriSLS",
              "style": "esriSLSSolid",
              "color": [
                110,
                110,
                110,
                255
              ],
              "width": 0.0
            }
          }
        },
    "transparency": 50
}

# Create a FeatureCollection with DrawingInfo
output_fc=sdf.spatial.to_feature_collection(drawing_info=drawing_props)
print("FC: ", output_fc)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Dec 2024 02:36:20 GMT</pubDate>
    <dc:creator>KurtSmithBGA</dc:creator>
    <dc:date>2024-12-26T02:36:20Z</dc:date>
    <item>
      <title>Correctly returning results from custom web tool</title>
      <link>https://community.esri.com/t5/arcgis-online-developers-questions/correctly-returning-results-from-custom-web-tool/m-p/1571246#M1542</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;(This was previously posted to the ArcGIS Notebook community, but I'm re-trying here since I did not get any responses).&lt;/P&gt;&lt;P&gt;I'm new to python for ArcGIS and am working on creating my first custom web tool (by publishing a Notebook as a custom web tool). The basic process of the web tool is to get a polygon from an external URL (available as a zipped shapefile, a geotif, and a png) and then return that polygon as an output parameter form the tool.&lt;/P&gt;&lt;P&gt;I currently am able to successfully use the shapefile URL, then convert that to a featureset and successfully return it. However, my current road block is figuring out how to alter the symbology of the result layer without having to publish it as a service first. The polygon is very complex, so the default border that AGOL applies tends to mis-represent the polygon. I tried using the TIF and PNG formats to return a raster representation instead, but I couldn't make this work (the tool would end with an error stating that it "failed to presist output values files for web tool").&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my questions are:&lt;/P&gt;&lt;P&gt;1) Is it possible to define the symbology of my feature set (possible as a feature collection) before I return it as an output parameter from the web tool?&lt;/P&gt;&lt;P&gt;2) Since the polygon is quite complex (picture a cellular coverage map), would I be better off trying to return this as a raster output instead?&lt;/P&gt;&lt;P&gt;Here is what I'm currently trying for the FeatureSet/FeatureCollection route, but it doesn't look like I'm successfully returning the feature collection to the app.&lt;/P&gt;&lt;PRE&gt;# Convert shapefile to featureSet
if "ENB_JOBID" in os.environ:
    import requests
    import zipfile
    import os
    from arcgis.gis import GIS
    from arcgis.features import FeatureSet, FeatureCollection, GeoAccessor, GeoSeriesAccessor
   
    # Download the ZIP file
    zip_path = "shapefile.zip"
    response = requests.get(shp_url)
    with open(zip_path, "wb") as f:
        f.write(response.content)
    
    # Extract the ZIP file
    output_dir = os.path.join(os.environ["ENB_JOBID"], "zip")
    os.makedirs(output_dir, exist_ok=True)
    with zipfile.ZipFile(zip_path, "r") as zip_ref:
        zip_ref.extractall(output_dir)
    
    # Locate the .shp file
    shapefile_path = None
    for root, dirs, files in os.walk(output_dir):
        for file in files:
            if file.endswith(".shp"):
                shapefile_path = os.path.join(root, file)
                break
    if shapefile_path:
        print("SHP Path: ", shapefile_path)
    else:
        raise FileNotFoundError("Shapefile (.shp) not found in the extracted ZIP.")
    
    # Load the shapefile into a spatially enabled DataFrame
    sdf = GeoAccessor.from_featureclass(shapefile_path)
    
    #convert to featureset
    output_fs = FeatureSet.from_dataframe(sdf)
    if output_fs:
        print("Output featureSet created.")

# Define DrawingInfo (symbology settings)
drawing_props = {
        "renderer": {
          "type": "simple",
          "symbol": {
            "type": "esriSFS",
            "style": "esriSFSSolid",
            "color": [
              252,
              193,
              184,
              255
            ],
            "outline": {
              "type": "esriSLS",
              "style": "esriSLSSolid",
              "color": [
                110,
                110,
                110,
                255
              ],
              "width": 0.0
            }
          }
        },
    "transparency": 50
}

# Create a FeatureCollection with DrawingInfo
output_fc=sdf.spatial.to_feature_collection(drawing_info=drawing_props)
print("FC: ", output_fc)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2024 02:36:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-developers-questions/correctly-returning-results-from-custom-web-tool/m-p/1571246#M1542</guid>
      <dc:creator>KurtSmithBGA</dc:creator>
      <dc:date>2024-12-26T02:36:20Z</dc:date>
    </item>
  </channel>
</rss>

