1) I have a polygon shapefile with 1000 multi-part polygons in it. Each Row of the table is a multipart polygon.

2) I need 1000 shapefiles with 1 multi-part polygon in each.

3) Each output shapefile with 1 multi-part polygon needs to be named with a name from the attribute table (1) unique to each input polygon.

Open to ArcGIS, ArcPy, Model Builder, OGR, QGIS solutions.

# import libraries
import arcpy, os

# path to file
polyFC = r'C:\junk\raa\RAA_20140522.shp'
# field name to use for file names
fieldName = "FID"

# set overwrite environment
arcpy.env.overwriteOutput = True

# loop through features
for row in arcpy.da.SearchCursor(polyFC, ["SHAPE@", fieldName]):
    # make new filename based on field value
    newName = os.path.join(os.path.dirname(polyFC), str(row[1]) + ".shp")
    # copy features to new file
    arcpy.CopyFeatures_management(row[0], newName)
| improve this answer | |
  • Some work but some give this error. Error opening feature class. Number of shapes does not match the number of table records. It appears the dbf and the .shp have lost the 1-1 match. Only on a few output shapes. – If you do not know- just GIS Sep 23 '14 at 19:32
  • Close enough so I accepted. – If you do not know- just GIS Sep 23 '14 at 19:50
  • Agreed, my answer is certainly not perfect. For example, it will fail if polyFC is a GDB feature class, resulting in an output called something like, "C:/junk/geodatabase.gdb/feature.shp". There are also differences between valid filenames and valid field values (converted to filenames) that may cause issues. I'm sure there are other catches, as well. – phloem Sep 23 '14 at 19:55

I would suggest using arcpy. Here is the general proposed code flow:

  1. Make feature layer of layer of interest
  2. Use search cursor on feature layer to get attribute of ID field and attribute of field for new shp name
  3. Use select by attribute method for each ID attribute for each row (i.e. unique feature)
  4. Create new feature class on selected feature layer using feature class to feature class method and reference value from name field for new shp name
| improve this answer | |

I went the model builder route.

This seemed to work.

enter image description here

The input shapefile is A I then iterated through Features while setting the %Value% As the attribute.

Then used FC to FC tool with the output name as %Value%.shp

Phoelm ArcPy (alternate comment and answer) worked on 90% of the files but see the comment for a strange error on a few of them.

| improve this answer | |

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