Hello,
I've been trying to author a geoprocessing service that uses data stored in a folder of the ArcGIS Server machine.
Below is the code of the Python Toolbox I run before publishing.
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "PythonToolbox"
self.alias = "mypythontoolbox"
# List of tool classes associated with this toolbox
self.tools = [PyToolInterpolation]
class PyToolInterpolation(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "PyToolInterpolation"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
param0 = arcpy.Parameter(
displayName="Resultat",
name="result",
datatype="GPFeatureLayer",
parameterType="Derived",
direction="Output")
params = [param0]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
dem_dir = r"K:\8_Raster\MNT\MNT_2021\Assemblage"
dem_name = "MNT_2021_CD17_EPSG3857.tif"
dem = os.path.join(dem_dir, dem_name)
#dem = r"K:\8_Raster\MNT\MNT_2021\Assemblage\MNT_2021_CD17_EPSG3857.tif"
feat_dir = r"K:\8_Raster\MNT\MNT_2021\Assemblage\interpolation.gdb"
feat_name = "line"
feat = os.path.join(feat_dir, feat_name)
#feat = r"K:\8_Raster\MNT\MNT_2021\Assemblage\interpolation.gdb\line"
interp_line = r"memory\interpouttmp"
arcpy.sa.InterpolateShape(in_surface=dem,
in_feature_class=feat,
out_feature_class=interp_line,
vertices_only="VERTICES_ONLY")
arcpy.SetParameter(0, interp_line)
def postExecute(self, parameters):
"""This method takes place after outputs are processed and
added to the display."""
return
In ArcGIS Server Manager's Data Stores tab I registered the folder that contains data before publication.
So the publisher folder path is mapped with the server folder path where the data is duplicated.
This way data are not copied when publishing.
I don't understand why the Python script on server-side keeps using publisher pathes.
# Esri start of added imports
import sys, os, arcpy
# Esri end of added imports
# Esri start of added variables
g_ESRI_variable_1 = 'K:\\8_Raster\\MNT\\MNT_2021\\Assemblage'
g_ESRI_variable_2 = 'K:\\8_Raster\\MNT\\MNT_2021\\Assemblage\\interpolation.gdb'
g_ESRI_variable_3 = 'memory\\interpouttmp'
# Esri end of added variables
import os
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "PythonToolbox"
self.alias = "mypythontoolbox"
# List of tool classes associated with this toolbox
self.tools = [PyToolInterpolation]
class PyToolInterpolation(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "PyToolInterpolation"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
param0 = arcpy.Parameter(
displayName="Resultat",
name="result",
datatype="GPFeatureLayer",
parameterType="Derived",
direction="Output")
params = [param0]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
dem_dir = g_ESRI_variable_1
dem_name = "MNT_2021_CD17_EPSG3857.tif"
dem = os.path.join(dem_dir, dem_name)
#dem = r"K:\8_Raster\MNT\MNT_2021\Assemblage\MNT_2021_CD17_EPSG3857.tif"
feat_dir = g_ESRI_variable_2
feat_name = "line"
feat = os.path.join(feat_dir, feat_name)
#feat = r"K:\8_Raster\MNT\MNT_2021\Assemblage\interpolation.gdb\line"
interp_line = g_ESRI_variable_3
arcpy.sa.InterpolateShape(in_surface=dem,
in_feature_class=feat,
out_feature_class=interp_line,
vertices_only="VERTICES_ONLY")
arcpy.SetParameter(0, interp_line)
def postExecute(self, parameters):
"""This method takes place after outputs are processed and
added to the display."""
return
I think it should be using pathes like '/home/adminsig/datastore_rasters/MNT/MNT_2021/Assemblage/' and '/home/adminsig/datastore_rasters/MNT/MNT_2021/Assemblage/interpolation.gdb'
The geoprocessing task works if I update the server-side Python script with those pathes.
Is there a way to author this geoprocessing without doing this script modification ?
I have found that actually pathing my scripts to use a UNC\SMB script; then having that published to my DataStore alleviates this issue.
Thank you for your answer @DEWright_CA .
So I changed my code for
def execute(self, parameters, messages):
"""The source code of the tool."""
dem_dir = r"\\files\D\1_DATA\8_Raster\MNT\MNT_2021\Assemblage"
dem_name = "MNT_2021_CD17_EPSG3857.tif"
dem = os.path.join(dem_dir, dem_name)
#dem = r"\\files\D\1_DATA\8_Raster\MNT\MNT_2021\Assemblage\MNT_2021_CD17_EPSG3857.tif"
feat_dir = r"\\files\D\1_DATA\8_Raster\MNT\MNT_2021\Assemblage\interpolation.gdb"
feat_name = "line"
feat = os.path.join(feat_dir, feat_name)
#feat = r"\\files\D\1_DATA\8_Raster\MNT\MNT_2021\Assemblage\interpolation.gdb\line"
interp_line = r"memory\interpouttmp"
arcpy.sa.InterpolateShape(in_surface=dem,
in_feature_class=feat,
out_feature_class=interp_line,
vertices_only="VERTICES_ONLY")
arcpy.SetParameter(0, interp_line)
And I changed registered Datastore from
to
Is that what you suggested @DEWright_CA ?
I'm not sure because the issue remains. Publisher folder path is not converted to Server folder path in the published python script.