+ Reply to Thread
Results 1 to 8 of 8

Thread: How do I test if a domain exists?

  1. #1
    Paul Dziemiela
    Join Date
    Mar 2010
    Posts
    13
    Points
    0
    Answers Provided
    0


    0

    Default How do I test if a domain exists?

    Hi folks,

    Simple question, I cannot figure out how to gracefully check if a domain exists in a file geodatabase using Python with ArcGIS 9.3.1 SP2. I can try to create the domain afresh and then catch the error but seems like something I should be able to test for.

    Thanks,

    Paul

  2. #2
    Dale Honeycutt

    Join Date
    Nov 2009
    Posts
    326
    Points
    204
    Answers Provided
    25


    0

    Default Re: How do I test if a domain exists?

    Describe the workspace - the returned describe object has a list of domains.

    See http://webhelp.esri.com/arcgisdeskto...ace_properties

  3. #3
    Paul Dziemiela
    Join Date
    Mar 2010
    Posts
    13
    Points
    0
    Answers Provided
    0


    0

    Default Re: How do I test if a domain exists?

    Thanks!

    I can wrap that up into an exists function.

    Cheers,

    Paul

  4. #4
    Adam Cox
    Join Date
    Dec 2012
    Posts
    52
    Points
    36
    Answers Provided
    3


    0

    Default Re: How do I test if a domain exists?

    Long after the fact, but this thread very nearly answers my question...

    I want to make a conditional statement happen if a domain doesn't yet exist. In other words, if the domain "GOES_TO" does not exist, I don't want it be (unsuccessfully) created in the next step.

    desc = arcpy.Describe(gdb_path)
    domains = desc.domains

    for domain in domains:
    if domain == "GOES_TO":
    isitthere = "yes"
    else:
    isitthere = "no"

    if isitthere == "no":

    #create the new domain, etc.

    This code doesn't work because as the list goes through each domain, all of them but one are not called "GOES_TO", which means that isitthere will always equal "no". But at least you can see what I'm trying to do... I feel like there's something obvious that I'm missing...

  5. #5
    Dale Honeycutt

    Join Date
    Nov 2009
    Posts
    326
    Points
    204
    Answers Provided
    25


    0

    Default Re: How do I test if a domain exists?

    Code:
    isthere = False
    for domain in domains:
      if domain == "GOES_TO":
        isthere = True
        break
    
    if not isthere:
      # do something

  6. #6
    Adam Cox
    Join Date
    Dec 2012
    Posts
    52
    Points
    36
    Answers Provided
    3


    0

    Default Re: How do I test if a domain exists?

    yes, that is what I was missing. I appreciate the quick answer. Thanks!

  7. #7
    Dale Honeycutt

    Join Date
    Nov 2009
    Posts
    326
    Points
    204
    Answers Provided
    25


    0

    Default Re: How do I test if a domain exists?

    FYI:
    In 10.1, there is a new data access Python module that has a ListDomains function that returns Domain objects. Domain objects have all the properties of the domain, not just the name. ListDomains is far superior to describing a workspace object.

  8. #8
    Adam Cox
    Join Date
    Dec 2012
    Posts
    52
    Points
    36
    Answers Provided
    3


    0

    Default Re: How do I test if a domain exists?

    Yeah, I found that out in another thread. I'm using 10.0 though, so I'll have to wait for an upgrade to use ListDomain.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts