Skip to main content

I would like to extract the coded domnain definition from a geodabase.

There is already an article about it here. However, when dowloading the ETL extract-domains-from-geodatabase-gdb-py34.fmw, I couldn't run it with my 2021 FME version.

FME_BEGIN_TCL script returned error on execution. Error message was: '                FME 2021.2.6.0 (20220727 - Build 21821 - WIN64)
                        FME Database Edition (floating)
                               Permanent License.
                         Machine host name is: 237146PT
          Operating System: Microsoft Windows 10 64-bit  (Build 19045)
                 Copyright (c) 1994 - 2021, Safe Software Inc.
                               Safe Software Inc.
GEODATABASE_FILE reader: An unknown exception occurred
Program Terminating
Translation FAILED.
child process exited abnormally'. TCL script was: 'lappend sysString $FME_MacroValues(FME_HOME_UNIX)/fme;
lappend sysString {Generate};
lappend sysString {GEODATABASE_FILE};
lappend sysString {NULL};
lappend sysString $FME_MacroValues(SRC_GDB);
lappend sysString $env(TEMP)/temp.fme;
lappend sysString {--RESOLVE_DOMAINS};
lappend sysString {YES};
lappend sysString {2>@1};
eval exec $sysString;
;'

Any ideas on what I should do to make this script work? Or is there another way to extract such values without  having  a licensed version of ArcGIS available?

Multiple options but nothing pure FME, see this topic for samples.


Multiple options but nothing pure FME, see this topic for samples.

Thanks @nielsgerrits​ for your answer.

The solutions provided with python are good but they all require the use of the arcpy library and hence the availability of a license version of Arcgis.

 

Are there other options to have something in python without using arcpy?


Thanks @nielsgerrits​ for your answer.

The solutions provided with python are good but they all require the use of the arcpy library and hence the availability of a license version of Arcgis.

 

Are there other options to have something in python without using arcpy?

When googling I found this answer on Stack Exchange:

https://gis.stackexchange.com/questions/325020/how-to-extract-filegdbs-domains-without-arcgis

I never tried this as I have the Esri licenses, but it is worth a shot, depending how hard you need it.


Thanks @nielsgerrits​ for your answer.

The solutions provided with python are good but they all require the use of the arcpy library and hence the availability of a license version of Arcgis.

 

Are there other options to have something in python without using arcpy?

If I chatgpt this question I get the following response. I did not test this.

from osgeo import gdal
import os
 
def export_coded_domains(file_geodatabase, output_folder):
    # Open the GDB using GDAL
    gdb_driver = gdal.GetDriverByName('OpenFileGDB')
    gdb_dataset = gdal.OpenEx(file_geodatabase, gdal.OF_READONLY | gdal.OF_VECTOR)
 
    # Get the number of layers in the GDB
    layer_count = gdb_dataset.GetLayerCount()
 
    # Iterate over each layer
    for i in range(layer_count):
        layer = gdb_dataset.GetLayerByIndex(i)
 
        # Get the layer name
        layer_name = layer.GetName()
 
        # Create a subfolder for the layer
        output_folder_layer = os.path.join(output_folder, layer_name)
        if not os.path.exists(output_folder_layer):
            os.makedirs(output_folder_layer)
 
        # Get the layer definition and attribute table
        layer_definition = layer.GetLayerDefn()
        layer_table = layer.GetLayerTable()
 
        # Iterate over the fields in the attribute table
        field_count = layer_table.GetFieldCount()
        for j in range(field_count):
            field_definition = layer_table.GetFieldDefn(j)
 
            # Check if the field has a domain
            if field_definition.HasDomain():
                domain = field_definition.GetDomain()
 
                # Export the domain definition to a text file
                domain_definition_file = os.path.join(output_folder_layer, f"{field_definition.GetName()}.txt")
                with open(domain_definition_file, 'w') as f:
                    f.write(f"Domain Name: {domain.GetName()}\n")
                    f.write(f"Domain Type: {domain.GetTypeName()}\n")
                    f.write(f"Code, Description\n")
                    codes = domain.GetCodedValues()
                    for code in codes:
                        f.write(f"{code}, {codesÂcode]}\n")
 
    # Close the GDB dataset
    gdb_dataset = None
 
# Usage example
file_geodatabase = r'path\to\your\file_geodatabase.gdb'
output_folder = r'path\to\output\folder'
 
export_coded_domains(file_geodatabase, output_folder)

 


Reply