Hi,
How to add table/raster/feature class which are outputted by the tool directly to file geodatabase? Appreciate for any hints 🙂
arcpy.management.MakeFeatureLayer('Min_max_points', 'Min_max_points')
arcpy.AddMessage("Min&Max table added to Contents")
All these datasets are outputted to file gedatabase
but nothing is added to Contents pane
Make Feature Layer (Data Management)—ArcGIS Pro | Documentation
The layer that is created by the tool is temporary and will not persist after the session ends unless the layer is saved to disk or the map document is saved.
You don't indicate whether you are using
when you run the script
Hi Dan, thanks for prompt reply.
I am running the tool directly from the Toolbox with ArcPro open
When I am running the code snippet directly from Python window
I am getting the result and the dataset (which was saved to file geodatabase on previous tool executions) is added to the Contents window
Any thought about why is it not working when it is executed directly from Toolbox/Geoprocessing?
try copy features if you have the add to display environment property set properly
Hello again, not sure here, could you please explain again? Thank you!
makefeaturelayer is temporary, it goes away unless it is saved. I just want to see whether copying it to a gdb adds the results to the display
Thanks, I tested and copy is behaving exactly the same way when executing command from python window in ArcPro, the dataset is saved to geodatabase and added to Contents pane
arcpy.CopyFeatures_management("Min_max_points", "Min_max_points_copy3")
When adding following code to the end of my script:
# Test for copyig features
arcpy.CopyFeatures_management("Min_max_points", "Min_max_points_copy3")
arcpy.AddMessage("Copy dataset")
the dataset is saved in geodatabase but nothing is added to the Contents pane.
Both commands:
arcpy.management.MakeFeatureLayer('Min_max_points', 'Min_max_points_copy3')
arcpy.CopyFeatures_management("Min_max_points", "Min_max_points_copy3")
are behaving exactly the same way - saving output dataset to geodatabase but not adding dataset to Contents pane when the code is executed from the Tool/geoprocessing.
If you have any more ideas please let me know 🙂
Hmmm no, it works for me and I am not sure what it is about your setup.
I work only with locally stored data and I have full administrative permissions. Here is my Project, Options, Geoprocessing parameters, which you indicate is the same, but you never know
Actually I did not have the "Display disabled parameters" thick ON but anyway I tried with this feature ON and it did not helped. Here are my parameters
So I started from scratch, creating new ArcPro project, creating new geodatabase, addin rasters to geodatabase and even adding the script to the toolbox again and configuring parameters. I tried running geoprocessing from my local PC as well remote Citrix server to see if any ArcPro installation or server/pc could have anything related to the issue. No success, no dataset are outputted to Contents pane.
I couldn't find anything related under Environments as well
Here are my tool parameters
Here is tool code
# Import arcpy
import arcpy
# Set geoprocessing environment
# Set variables
Well_Location_SDE = arcpy.GetParameterAsText(0)
SQL_Expression = arcpy.GetParameterAsText(1)
Well_Location_FGDB = arcpy.GetParameterAsText(2)
Radius_Buffer = arcpy.GetParameterAsText(3)
Input_Raster = arcpy.GetParameterAsText(4)
Output_Raster = arcpy.GetParameterAsText(5)
Output_Excel = arcpy.GetParameterAsText(6)
Output_RasterToPoint = arcpy.GetParameterAsText(7)
#arcpy.env.workspace = Output_FGDB
#arcpy.env.overwriteOutput = True
arcpy.AddMessage("Variables set")
# Applying SQL expression
# Remeber to not mix input and outup here that is why we use "memory\\selected_well" and after that "memory\\well_buffer"
#output_var = arcpy.analysis.Select(in_features, out_feature_class, SQL_Expression)
Well_Location_SQL = arcpy.analysis.Select(Well_Location_SDE,"memory\\selected_well", SQL_Expression)
arcpy.AddMessage("SQL expression applied")
# Truncating FGDB
arcpy.management.TruncateTable(Well_Location_FGDB)
arcpy.AddMessage("FGDB truncated")
# Appending from SDE to FGDB
arcpy.management.Append(Well_Location_SQL, Well_Location_FGDB, "TEST")
arcpy.AddMessage("Append from SDE to FGDB completed")
# Make buffer
#arcpy.analysis.Buffer(in_features, out_feature_class, Radius_Buffer)
arcpy.analysis.Buffer(Well_Location_FGDB, "memory\\well_buffer", Radius_Buffer)
arcpy.AddMessage("Buffer completed")
# Use describe to get path to FGDB for creating table for Min & Max results
desc=arcpy.Describe(Input_Raster)
arcpy.env.workspace = desc.path
arcpy.AddMessage("The path to FGDB is:")
arcpy.AddMessage(desc.path)
# Create table for output Min & Max
arcpy.CreateTable_management(desc.path, "Stats_GEO")
arcpy.AddField_management("Stats_GEO", "LOCATION_NAME", "TEXT", field_length=100)
arcpy.AddField_management("Stats_GEO", "MIN", "DOUBLE")
arcpy.AddField_management("Stats_GEO", "MAX", "DOUBLE")
arcpy.AddMessage("Creating Table with Min & Max values...")
with arcpy.da.SearchCursor("memory\\well_buffer", ["OBJECTID", "LOCATION_NAME"]) as cursor:
for row in cursor:
arcpy.SelectLayerByAttribute_management("memory\\well_buffer", "NEW_SELECTION", "OBJECTID = " + str(row[0]))
Clipped_Raster = arcpy.management.Clip(Input_Raster, "", Output_Raster + "_" + str(row[0]), "memory\\well_buffer", "", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
# Get Raster Properties for bathy raster MINIMUM value
mini = arcpy.management.GetRasterProperties(Output_Raster + "_" + str(row[0]), "MINIMUM", "Band_1")
# Get Raster Properties for bathy raster MAXIMUM value
maxi = arcpy.management.GetRasterProperties(Output_Raster + "_" + str(row[0]), "MAXIMUM", "Band_1")
with arcpy.da.InsertCursor("Stats_GEO", ["LOCATION_NAME", "MIN", "MAX"]) as cursor2:
row2 = [row[1],mini.getOutput(0), maxi.getOutput(0)]
cursor2.insertRow(row2)
print()
arcpy.AddMessage("Created table for output Min & Max")
# Save the table to excel
arcpy.AddMessage("Saving Stats_GEO table")
arcpy.TableToExcel_conversion("Stats_GEO", Output_Excel)
# Convert results into numbers
maxi_float = float(maxi[0])
mini_float = float(mini[0])
# Print MIN & MAX
arcpy.AddMessage("The maxi_float is: ")
arcpy.AddMessage(maxi_float)
arcpy.AddMessage("The min_float is: ")
arcpy.AddMessage(mini_float)
# Convert raster to point
arcpy.AddMessage("Converting clipped raster to points and saving to Output_RasterToPoint table")
arcpy.conversion.RasterToPoint(Clipped_Raster, "Output_RasterToPoint")
# Calculate number ranges to avoid rounding problems.
maxi_upper = maxi_float+0.001
maxi_lower = maxi_float-0.001
mini_upper = mini_float+0.001
mini_lower = mini_float-0.001
maxi_upper = maxi_float+0.0001
maxi_lower = maxi_float-0.0001
mini_upper = mini_float+0.001
mini_lower = mini_float-0.001
# Look for a match:
with arcpy.da.SearchCursor("Output_RasterToPoint", ["OBJECTID","grid_code"]) as cursor:
count=0
for row in cursor:
#Find the max value and print the coordinates
if row[1] < maxi_upper and row[1] > maxi_lower:
print("Exact match has been retrieved: ObjID " + str(row[0]))
max_OBJID = row[0]
count = count+1
#Find the min value and print the coordinates
elif row[1] < mini_upper and row[1] > mini_lower:
print("Exact match has been retrieved: ObjID " + str(row[0]))
min_OBJID = row[0]
count = count+1
else:
count=count
print("Exact matches found: " + str(count))
# Make an sql expression to just export the min and max points
sql_exp_select = """{0} = {1} Or {0} = {2}""".format(arcpy.AddFieldDelimiters("Output_RasterToPoint", "OBJECTID"), max_OBJID,min_OBJID)
#Export the points specified in the sql query above.
arcpy.analysis.Select("Output_RasterToPoint","Min_max_points", sql_exp_select)
arcpy.AddMessage("Adding Min&Max table to Contents")
arcpy.management.MakeFeatureLayer('Min_max_points', 'Min_max_points')
arcpy.AddMessage("Min&Max table added to Contents")
# Test for copyig features
#arcpy.CopyFeatures_management("Min_max_points", "Min_max_points_copy3")
#arcpy.AddMessage("Copy dataset")
Not sure what more I can test. If any ideas please let me know. Thanks again!
I would call tech support... as soon as you mention "remote server" that might rule out a simple local install issue