Hello! I'm currently working on a script that seeks to pull data from an image server and then preprocess this data by clipping it to a study area extent using the raster functions data management clip tool, feed that clipped data into a GeoAI algorithm, and then save then saves the output after the fact.
The issue I am having is that I cannot seem to convert the data that I added from path to a Raster object. It gets added to my map just fine, and I have been able to print the name of the data, just to be sure it actually gets added.
The reason for wanting to use the raster function's clip and other data management tools is because it is faster and doesn't save anything to file unless explicitly told to. I have run the process in pro and it seems to work well, but we're looking to automate the process and avoid using the GUI for this.
Here's a snippet of my code so far. Thank you all for your expert opinions!
Code:
import arcpy
arcpy.CheckOutExtension("Spatial")
from arcpy.sa import *
from arcpy.ia import *
import geopandas as gpd
env = input("Enter the workspace environment: ")
if env.startswith('"') or "\\" in env:
env = env.replace('"', '').replace('\\', '/')
try:
arcpy.env.workspace = env
arcpy.env.overwriteOutput = True
serverDataPath = input("Enter the server data path: ")
serverDataPath = serverDataPath.replace('\\', '/')
serverDataPath = r"{}".format(serverDataPath)
#Load Up the Pro Project
aprx = input("Enter the path to the ArcGIS Pro project (.aprx): ")
if aprx.startswith('"') or "\\" in aprx:
aprx = aprx.replace('"', '').replace('\\', '/')
aprx = arcpy.mp.ArcGISProject(aprx)
#Create a disposable Map
mapCheck = aprx.listMaps()
for m in mapCheck:
if m.name == "serverData":
aprx.deleteItem(m)
else:
map = aprx.createMap("serverData", "Map")
print("{} map created successfully".format(map.name))
#Add the server data path to the map
map.addDataFromPath(serverDataPath)
except Exception as e:
print("Error: {}".format(e))
raster = None
try:
items = map.listLayers()
for i in items:
if i.name != "Topographic":
raster = i
except Exception as e:
print("Error listing raster items: ", e)
#Convert to Raster object
rasterFile = Raster(raster)
Error:
TypeError Traceback (most recent call last) Cell In[24], line 1----> 1rasterFile = Raster(raster) File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Raster.py:82, in Raster.__new__(cls, in_raster, is_multidimensional) 81 def __new__(cls, in_raster, is_multidimensional=False ---> 82 return super().__new__(cls, in_raster, is_multidimensional) TypeError: expected a raster or layer name