Select to view content in your preferred language

Return GeoTIFF or KML to Web Tool

254
1
12-16-2024 11:25 AM
Labels (1)
KurtSmithBGA
Emerging Contributor

Hello,

I am new to ArcGIS python coding and Notebooks, and am trying to develop a custom web tool for our experience builder app. I've successfully created a Notebook (using Notebooks through our ArcGIS Online portal) with input and output parameters, but I'm having trouble with correctly passing my output back to the client/app. The notebook simply takes a single point as input and uses the coordinates to call an external API. The API returns public URLs for a number of different data formats (options are KMZ, GeoTIFF, and SHP), and I'm a bit lost on the best way to use one of these URLs to display the results in the client's map (e.g. in experience builder or even just a web map). I keep running into a "Failed to presist output value files for webtool job with id b4eaaa0aa27b4ce29bb30ff19f305bc9 to job output directory" error. More details below.

Would anyone be willing to give some direction on the best way to accomplish this?

My output parameter:

KurtSmithBGA_0-1734376171413.png

 

Here's an example of what I'm trying:

KurtSmithBGA_2-1734376485363.png

All cells seem to execute successfully, but I get this error in the result:

KurtSmithBGA_3-1734376796106.png

Developer tool view:

KurtSmithBGA_4-1734376922678.png

 

Any tips on what I'm doing wrong (or a better way to accomplish this) would be greatly appreciated!

-Kurt

0 Kudos
1 Reply
KurtSmithBGA
Emerging Contributor

I've made some progress and can hopefully narrow down my request for assistance. First, I realize now that KML is not raster, so no surprise that the kmz attempt did not work. 

I currently am able to get a shapefile URL from the external API, then convert that to a featureset and successfully return it to my app.

However, my current road block is figuring out how to (or if I can...) alter the symbology of the result layer. Surely that is possible somehow?

Here is what I'm currently trying, 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)

 

0 Kudos