1

I've got some ArcPy code below which adds all the CSVs in a folder, adds them to the map (AddXYTableToPoint) and buffers the points.

I'm running in a Python notebook in ArcGIS Pro I only want to add the 'final' output, in this case the buffered points to the map.

Currently, the points are added along with the buffered points to the map.

path_list = []
    x_coords = "Latitude"
    y_coords = "Longitude"

for csv_file in csv_file_list:
    in_table = os.path.join(in_folder,csv_file)
    name = csv_file.strip(".csv")
    out_fc = name
    path_list.append(out_fc)
    arcpy.management.XYTableToPoint(in_table,out_fc,x_coords,y_coords)
    buffer_out = name + str('_buffer')
    arcpy.analysis.Buffer(out_fc,buffer_out,"500 Meters")
4
  • 1
    Are you running this code from the Python Window, a Python Script Tool or somewhere else?
    – PolyGeo
    Commented May 18, 2023 at 7:40
  • 1
    You can either disable automatic addition of analysis products to the map canvas or remove the previous product after the fact.
    – Vince
    Commented May 18, 2023 at 12:55
  • @PolyGeo I'm running in a Python notebook in ArcGIS Pro I want to add the 'final' output, in this case the buffered points.
    – Daniel Sim
    Commented May 18, 2023 at 22:11
  • Please use the edit button beneath your question to revise it with any requested clarifications.
    – PolyGeo
    Commented May 18, 2023 at 23:52

1 Answer 1

0

To stop adding features automatically, set arcpy.env.addOutputsToMap to False. You then have to turn it back on to add the features. One way to code your solution is:

# Stop auto add outputs
arcpy.env.addOutputsToMap = False

for csv_file in csv_file_list:
    in_table = os.path.join(in_folder,csv_file)
    name = csv_file.strip(".csv")
    out_fc = name
    path_list.append(out_fc)
    arcpy.management.XYTableToPoint(in_table,out_fc,x_coords,y_coords)
    buffer_out = name + str('_buffer')
    # turn on add outputs for duration of with
    with arcpy.EnvManager(addOutputsToMap = True):
        arcpy.analysis.Buffer(out_fc,buffer_out,"500 Meters")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.