7

I maintain a complex parcel fabric that uses coded value domains for a few fields. These are short integer fields with values from 1 - 6. These values represent say 1:Integrated Registered Survey Plan, 2:Survey Plan, 3:Geo-Referenced Air Photography, 4:Government Provided, 5:Expert Knowledge, 6:Unknown.

So I have several data requests and they need to be provided in Shapefile's. When I export my parcel fabric the fields obviously make no sense since they are numeric values representing accuracy codes from domains.

Is there any way to convert this field from a coded numeric field to its domain value? I know I can do this with some python programming, but I wonder if ESRI already has a solution for this.

Also I am managing the Parcel Fabric in a File Geodatabase.

2

You could do it with Python, but if you are unfamiliar with Arcpy, it's a simple field calculation. Add a new text field and use this in field calculator.

CODE BLOCK:

def domain(field):
 if field == 1: return "Integrated Registered Survey Plan"
 elif field == 2: return "Survey Plan"
 elif field == 3: return "Geo-Referenced Air Photography"
 elif field == 4: return "Government Provided"
 elif field == 5: return "Expert Knowledge"
 else: return "Unknown"

EXPRESSION:

domain(<reference to field containing domain values>)

In hindsight, it's actually easier to use field calculator than messing with dictionaries and cursors. If you had a large amount of domain values to code, then it would be worthwhile to dump the data in a .txt file and create your dictionary from that.

I only tested this on a shapefile, but it should also work on a GDB. This script takes a feature layer, list of fields, and text file as input and creates new fields to populate their domain values with.

import arcpy

shpin = arcpy.GetParameterAsText(0) #Input shapefile.
#String of field(s) to loop over, split into list.
fields = arcpy.GetParameterAsText(1).split(";")
#The text file containing comma separated find/replace values. 
textfile = arcpy.GetParameterAsText(2)    

values = [str(row[i]) for row in arcpy.da.SearchCursor(shpin, fields) 
          for i,field in enumerate(fields)]
repfind = dict([line.rstrip().split(",") for line in open(textfile, "r")])  

replaced = [repfind.get(x,x) for x in values] #Use .get method to mimic find/replace.   
rep_list = zip(*[iter(replaced)]*len(fields)) #Convert to list of lists. 

#Add new fields, with name based on old field name with appended underscore.
[arcpy.AddField_management(shpin, "{0}_".format(field), "Text") for field in fields]
newfields = ["{0}_".format(field) for field in fields]

with arcpy.da.UpdateCursor(shpin, newfields) as rowout: 
    for x, row in enumerate(rowout):
        for y, field in enumerate(fields):                
            row[y] = rep_list[x][y]
        rowout.updateRow(row) 
  • Yea, I know I could do this. But I have about 4 domain fields. I know this could all be done by adding new fields and doing some arcpy calculations. But, I was mainly wondering if ESRI had some sort of environment variable or export tool that carries domains to the shapefile. – Cody Brown Jun 25 '13 at 16:35
  • I never use GDB, so I wouldn't know. I'll work on writing a script that does this as I'll have a use for this some point down the road. – Paul Jun 25 '13 at 16:41
  • 1
    GDB's are pretty important for me because Topology is absolutely crucial for maintaining a Cadastral parcel fabric. I'll probably be working out a script as well if there is no easy answer. I already have a quick little tool that clips all of my data within an AOI to a Shapefile. It wouldn't be a massive amount of work to include your idea within it. But I'm exploring other options first before I do all that work. – Cody Brown Jun 25 '13 at 16:48
7

I'm not sure which version of ArcGIS you are working with, or if you've come across this since posting, but in version 10.1 there is an environment setting under "Fields" called "Transfer Field Domain Descriptions". I've used it on occasion in the Feature Class to Feature Class tool to export to shapefile and it seems to do the trick (if you don't mind your output data having additional fields added for the descriptions).

In version 10.0 the same tool, Feature Class to Feature Class, apparently did it automatically (the last dot point under Usage). Not sure about earlier ArcGIS versions though.

  • Good solution, but note this only works when the output is a shapefile (which is the original question, but sometimes we want to do the same without going to shape). If the destination is in a gdb the extra columns are not created. :-/ – matt wilkie Apr 27 '16 at 18:34
  • +1, this works in v10.2.2 to output file geodatabase (keeping the description value in the various domain fields) – artwork21 May 24 '17 at 13:03
5
  1. Create lookup tables like @GeoKelvin discribed. Or use tool Domain To Table to create a lookup table.
  2. Join lookup table to feature class
  3. Export feature class to Shapefile

You can automate this with Modellbuilder.

  • I would use Domain To Table tool in step 1 and using ModelBuilder here to sutomate the three steps makes sense too. – PolyGeo Jun 27 '13 at 11:05
  • This is the most versatile answer so far, as it will work for a variety output formats, not just shapefiles. Also using "Feature Class to Feature Class" instead of exporting will allow include/exclude of specific fields. – matt wilkie Apr 27 '16 at 18:53
4

You could create CSV files for your domain codes that can be distributed with the shapefiles. Using your example values, create SourceCode.csv to look like this:

SourceCode,Source
1,Integrated Registered Survey Plan
2,Survey Plan
3,Geo-Referenced Air Photography
4,Government Provided
5,Expert Knowledge
6,Unknown

If you distribute the CSV files along with your shapefiles, the recipient will be able to join the tables and get the meaning. This will prevent you from maintaining a separate copy of your spatial data for distribution, or from calculating the values every time you have to distribute the data (both assuming you don't keep the new attribute in the production data).

  • 1
    Hmm, this seems like a reasonably easy solution. Covers all my bases. Makes a little more work for the recipient, but oh well. – Cody Brown Jun 25 '13 at 16:36
  • 3
    A better file name would be LookupSource.csv. The name is more descriptive, and all of the lookup tables will usually be grouped together (alphabetically) in a directory listing. – user3461 Jun 25 '13 at 18:12

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.