Select to view content in your preferred language

creating and populating domains in python, short vs longs

3398
5
Jump to solution
10-27-2014 08:47 AM
BertKraan1
Occasional Contributor III

I want to use about ten domains each having between 10-100 coded values. The values may change over time as I receive feedback on the validity. Typing them by hand is not a feasible option

 

I created CSV's using Excel with the following format:

 

1;Snake

2;Fish

3;Mammal

4;Critter

and so on

 

Using

 

arcpy.CreateDomain_management(WorkSpace, "D_all", "all", "LONG", "CODED", "DEFAULT", "DEFAULT")

 

I can create a domain which I can populate using

 

arcpy.TableToDomain_management(all_csv, "Field1", "Field2", WorkSpace, "D_all", "all", "REPLACE")

 

So far, so good. But I don't seem to be able to use this domain in my featureclass properties/subtypes unless I use a 'SHORT' instead of a 'LONG'. Unfortunately when I create the domain using a 'SHORT' I get an error when using the TableToDomain function (error 000307)

 

does anyone has any idea on how to either populate the domain using a 'SHORT' as the coded value or how to get it working in my featureclass properties/subtypes?

 

regards,

 

Bert

 

By the way, how can I mark code as 'code' in this editor??

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

The easiest solution to this is use the Table to Table tool and convert your CSV file into a DBF file and explicitly set the field type to SHORT in the Field Map parameter. The DBF will then be read in correctly when you run the TableToDomain.

View solution in original post

5 Replies
DuncanHornby
MVP Notable Contributor

To mark code as code you need to click on the use advance editor then >> and choose the language under syntax highlighting.

0 Kudos
DuncanHornby
MVP Notable Contributor

The easiest solution to this is use the Table to Table tool and convert your CSV file into a DBF file and explicitly set the field type to SHORT in the Field Map parameter. The DBF will then be read in correctly when you run the TableToDomain.

BertKraan1
Occasional Contributor III

Duncan,

GREAT! Would not have found that myself for at least a year.

Bert

edit:

Having said that; 8 out of 9 csv's behave as predicted, one still gets converted using a long?? d4fvq?

So I threw everything away and rerun my script, now 2 out of 9 domains having a long in stead of a short??

Awkward.

0 Kudos
DuncanHornby
MVP Notable Contributor

What is the biggest number you are using? Data type short covers a range of -32,768 to 32,767 are you exceed this?

0 Kudos
BertKraan1
Occasional Contributor III

biggest numbet is 99.

At this stage of development my 'script' if it deserves that name has no loops or variables, just repeating lines of code. I deleted all faulty lines and copied-pasted-and-edited them again from working examples. In the end I had a script which works repeatedly without errors.

So it must have been syntax errors of some sort. Now It's working I'll rewrite it using a loop and variables.

0 Kudos