I am trying to take a FC, export individual FCs based on fields in the original FC, and have the new FCs dissolved.

I found a Python script that works and modified it for my use - see below.

# import system modules
import arcpy
from arcpy import env
import os

# Set environment settings
env.workspace = "H:/GISData/501/Jason/CFRPM7.gdb"

# Set local variables
inFeatures = "YR_2015/Network_2015"
fields = arcpy.ListFields

x = fields
# Execute Dissolve
(inFeatures, "H:/GISData/501/Jason/Network/node_dissolve.gdb/fc_ + str(x)", ["ROAD_NAME", "NUM_LANES", "POST_SPEED", "AREA_TYPE", "FAC_TYPE", "UA_NAME", "UA_TYPE", "FUNCLASS", "SIS", "NHS", "PAVED", "TRFC_CALM", "SCHL_ZONE", "COUNTY", "MPO", "FDOTDIST", "JURIS", "US_REP", "FL_REP", "FL_SEN", "CNTY_DIST"],"", "SINGLE_PART", "DISSOLVE_LINES")

The problem I'm running into is that I want the exported FCs to be named based on the field they represent. For example, I want the FC exported from the field "ROAD_NAME" from the YR_2015/Network_2015 FC to be named "ROAD_NAME" (.../node_dissolve.gdb/ROAD_NAME). This does not appear to be working, and instead exports the first listed FC, and as (.../node_dissolve.gdb/fc_).

I am new to Python.

  • Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour which emphasizes that there should be only one question asked per question. – PolyGeo Dec 4 '18 at 21:46
  • 1
    Your first question seems to be why Dissolve does not create one feature class per field in your list. The reason for that will be in its documentation and the solution will be to use a for loop on your field list and use that to run Dissolve once per field. – PolyGeo Dec 4 '18 at 21:46
  • Split by attributes then dissolve. Split by attributes will name the outputs by the attribute value. – BERA Dec 5 '18 at 20:13
  • To confirm, you want to dissolve first based on the field "ROAD_NAME", then repeat based on the field "NUM_LANES" and so on? As listed I believe the code would dissolve based on the full combination of all of the fields you listed -- e.g. only when they have "ROAD_NAME", "NUM_LANES", "POST_SPEED", etc in common. – smiller Dec 5 '18 at 21:42

You weren't doing anything with your fields or x variables.

You simply want to iterate over your fields of interest and process a dissolve for each one.

In my example, I create the variable "fields" three times. This is just to show you how to achieve different goals. Each one is preceded by a comment explaining what it does. Choose the one that's right for you, and comment out the others.

# import system modules
import arcpy

# Set environment settings
arcpy.env.workspace = "H:/GISData/501/Jason/CFRPM7.gdb"

# Set local variables
inFeatures = "YR_2015/Network_2015"
# This will dissolve on all fields, including OBJECTID, SHAPE, etc., which I don't think you want
fields = [i.name for i in arcpy.ListFields(inFeatures)]
# This will dissolve on all fields other than the system fields
fields = [i.name for i in arcpy.ListFields(inFeatures) if not i.required]
# Or, if you have a specific subset of fields that you wish to use, then put that here
            "UA_TYPE", "FUNCLASS", "SIS", "NHS", "PAVED", "TRFC_CALM", "SCHL_ZONE",
            "COUNTY", "MPO", "FDOTDIST", "JURIS", "US_REP", "FL_REP", "FL_SEN",

# Iterate over the fields and dissolve on each
for field in fields:
    # The second argument--the first "field"--determines the name given to the output
    #   feature class; the second occurrence of "field" tells the tool to dissolve on
    #   that field.
    arcpy.Dissolve_management(inFeatures, field, field, None, "SINGLE_PART", "DISSOLVE_LINES")

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.