Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am iterating over a shapefile and creating a new shape from each row. I will be creating several thousand individual shapes and do not want to inundate my TOC with that many layers (I bet ArcMap would crash if I did). Using the code below, each shape is added after being created. How could I remove the shape from the TOC after being created? I tried deleting the tempPoly variable but that did not do the trick.

polys = arcpy.SearchCursor(shapefile) #recall the cursor
for poly in polys: 
    print('starting at '+str(poly.FID))
    whereClause = '"FID" = ' + str(poly.FID     ) # Create a clause to select only the current record
    tempPoly=arcpy.FeatureClassToFeatureClass_conversion(shapefile,tempFilesPath,"tempPoly"+str(poly.FID),whereClause)                

I am not working in a dataframe and am in the data view not the layout view.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You have three options here:

  1. Un-check the Add results of geoprocessing operations to display check box (Geoprocessing menu>Geoprocessing Options)

  2. By code, use the arcpy RemoveLayer() method.

  3. Also by code, use the arcpy Delete (Data Management) Geoprocessing function to remove the layer by name.

share|improve this answer

Are these polygons features (it appears they are)? Is there a unique field of type "Text" (something other than FID)?

If so, you could also just use the Split_Analysis tool, and use the featureclass as both the input features and split features, the "Text" field as the split field, and then define your target workspace.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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