2

I have a shapefile of thousands of polygon features, that i would like to break up into smaller pieces (i.e. break a square into 8 equal pieces). I have read all over these boards for the right solution and haven't found one yet unfortunately. I've tried parcel editor but that only allows you to manually edit one feature at a time, and I've tried fishnet but that doesn't run through each individual feature it just processes across the entire extent of the shapefile. I have the full license for ArcGIS so all options are game. Ultimately I would like to be able to split this initial shapefile of features into a specified amount of equal width slots that each would be their own feature in the resulting shapefile.

Any thoughts?

5
  • if you just need squares from the original polygon you can use Create Fishnet
    – MDHald
    Aug 25, 2015 at 18:26
  • Well my shapefile of polygons are discontinuous so there will be blank space between the different polygons.
    – Alec
    Aug 25, 2015 at 18:49
  • I'm not sure I understand the problem you are having with the fishnet grid. Is there any reason you can't just create a fishnet and clip and/or spatial join it to your polygons?
    – BruceDoh
    Aug 25, 2015 at 19:07
  • @BruceDoh I think the problem with using a fishnet is that because the features to be cut are discontinuous, you may not get equal pieces in all features.
    – mkennedy
    Aug 25, 2015 at 20:03
  • Alec, is the width of a slot dependent on the size of the feature? That is, if a feature is 8 units wide, the new features would be 1 unit wide, while in a feature 16 units wide, the new features would be 2 units wide?
    – mkennedy
    Aug 25, 2015 at 20:04

1 Answer 1

6

Attach script

import arcpy, traceback, os, sys, math
from math import radians,sin,cos
from arcpy import env
env.overwriteOutput = True
inFC=arcpy.GetParameterAsText(0)
outFolder=arcpy.GetParameterAsText(1)
rectangle=r'in_memory\rectangle'
tempf=r'd:\scratch\many.shp'
def showPyMessage():
    arcpy.AddMessage(str(time.ctime()) + " - " + message)
def ShapeMake(pGon,angle):
    ar=arcpy.Array()
    a=radians(angle)
    part=pGon.getPart(0)
    for p in part:
        x,y=p.X,p.Y
        xN=cos(a)*x+sin(a)*y
        yN=-sin(a)*x+cos(a)*y
        pN=arcpy.Point(xN,yN)
        ar.add(pN)
    pgonRotated=arcpy.Polygon(ar)
    return pgonRotated

try:
    arcpy.MinimumBoundingGeometry_management(inFC,rectangle,
                                             "RECTANGLE_BY_WIDTH", "NONE", "", "MBG_FIELDS")
    m,n=0,0
    with arcpy.da.SearchCursor(rectangle, ("SHAPE@","MBG_Orientation")) as rows:
        for row in rows:
            shp,angle = row
            onside=ShapeMake(shp,-angle)
            extent=onside.extent
            origPoint='%s %s' %(extent.XMin,extent.YMin)
            yPoint='%s %s' %(extent.XMin,extent.YMax)
            endPoint='%s %s' %(extent.XMax,extent.YMax)
            if extent.width>extent.height:nRows,nCols=1,8
            else:nRows,nCols=8,1
            arcpy.CreateFishnet_management(tempf, origPoint,yPoint,
                                           "0", "0", nRows, nCols,endPoint,
                                           "NO_LABELS", "", "POLYGON")
            arcpy.AddField_management(tempf, "Rotation", "DOUBLE")
            arcpy.AddField_management(tempf, "Label", "Text", 25)
            m+=1
            with arcpy.da.UpdateCursor(tempf, ["SHAPE@","Rotation","Label"]) as rows:
                for row in rows:
                    shp = row[0]
                    rollBack=ShapeMake(shp,angle)
                    row[0]=rollBack
                    row[1]=angle
                    m+=1
                    row[2]=str(m).zfill(8)
                    rows.updateRow(row)
            n+=1
            arcpy.CopyFeatures_management(tempf, '%s%sfnet_%s'%(outFolder,os.sep,str(n).zfill(4)))
except:
    message = "\n*** PYTHON ERRORS *** "; showPyMessage()
    message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
    message = "Python Error Info: " +  str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"; showPyMessage()

to tool:

enter image description here

Input feature layer:

enter image description here

Merge all shapefiles from Output Folder into single feature class shown below:

enter image description here

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.