1

I'm am encountering an issue in ArcMap 10.2 regarding the Split Geoprocessing tool. I have a shapefile of roads (polylines) and another shapefile of districts (polygons). The roads shapefile is a result of running the MultipartToSinglepart tool so I can be absolutely sure there are no multi-part features.

I input the roads into the Split tool to be split on the districts. The problem is the output shapefile from the tool has not only split the lines based on the district boundaries, but has also divided my single-part roads into a multi-part feature. The divisions of these parts occur wherever the road intersected another road. As far as I can tell, multi-part features should not be created by the Split tool in this way. Does anyone know how to prevent the Split tool from creating multi-part features.

Tool is ran with these parameters, where m2s=roads: enter image description here

An example of what I'm seeing is here: enter image description here

  • That is weird. If you select the one district I assume we can see in the background and run clip do you get the same result? – Michael Stimson Jul 19 '17 at 23:16
  • No, that seems to work okay. – danielm Jul 20 '17 at 14:15
  • Do you have any python ability? I have a script that clips iteratively, emulating the split tool. It is a 9.0 geoprocessor but I could rewrite it to arcpy 10.2 quite easily, it's only 21 lines (including blank lines). – Michael Stimson Jul 20 '17 at 20:43
  • Thanks, but I've already written that myself. I still haven't figured out what's up with the Split tool. I guess I'll just chalk it up to being another ESRI-ism for now. – danielm Jul 20 '17 at 21:21
  • Fair enough, that's probably why I wrote it in the first place. Would you like to answer your own question with your code to show future users a workaround please. – Michael Stimson Jul 20 '17 at 21:41
1

As you've already worked out the clip function creates the output as expected. This is an arcpy update of an existing script that may help overcome this problem:

import os, sys, arcpy

InData  = sys.argv[1]
Clip    = sys.argv[2]
ClipFld = sys.argv[3] # the field in 'clip' to use for naming
OutWS   = sys.argv[4] # the folder or geodatabase to put the outputs

InBase  = os.path.basename(InData) # get the base name

Desc    = arcpy.Describe(OutWS)    # get some info about the out workspace
if Desc.workspaceType == 'FileSystem':
    OutShape = True
elif Desc.workspaceType == 'LocalDatabase':
    OutShape = False
else:
    arcpy.AddError("Output workspace is the wrong type")
    sys.exit(-2)

Field   = arcpy.ListFields(Clip,ClipFld)[0] # get as a Field object
# we will only accept string or integer types
if Field.type == 'String':
    IsTextField = True
elif Field.type in ['Integer','SmallInteger']:
    IsTextField = False
else:
    arcpy.AddError("Field {} is the wrong type".format(ClipFld))
    sys.exit(-1)

with arcpy.da.SearchCursor(Clip,ClipFld) as SCur:
    for SRow in SCur:
        if IsTextField:
            dQ = "{} = '{}'".format(ClipFld,SRow[0]) # quoted for strings
        else:
            dQ = "{} = {}".format(ClipFld,SRow[0])   # not quoted for numbers

        # define the output name in the format InFCName_RowValue(.shp)
        if OutShape:
            OutFCname = "{}_{}.shp".format(InBase,SRow[0])
        else:
            OutFCname = "{}_{}".format(InBase,SRow[0])

        OutFCPath = os.path.join(OutWS,OutFCname) # full path to output feature class

        if not arcpy.Exists(OutFCPath):
            # only create if it doesn't already exist.. there may be duplicates
            # in which case the output would exist on the subsequent iterations..
            arcpy.MakeFeatureLayer_management(Clip,"TempLayer",dQ)
            arcpy.AddMessage("Clipping with value {}".format(SRow[0]))
            arcpy.Clip_analysis(InData,"TempLayer",OutFCPath)
            arcpy.Delete_management("TempLayer") # delete the temporary layer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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