Hi All,
(This was previously posted to the ArcGIS Notebook community, but I'm re-trying here since I did not get any responses).
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.
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").
So my questions are:
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?
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?
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.
# 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)