Select to view content in your preferred language

Allow Field Precision and Scale to be Defined in Feature Class Wizard

6129
27
05-30-2023 07:41 AM
Status: In Product Plan
Labels (1)
mpboyle
Frequent Contributor

When adding a "double" field type in ArcGIS Pros Feature Class Wizard, please allow precision and scale to be defined if using an enterprise geodatabase.

For example: if I add a double field to an enterprise geodatabase dataset within the wizard, the precision and scale can not be defined, and this results in them being 38,8.  In most of our use cases this far exceeds any precision and scale we'd use and bloats the table.  If I want to alter the precision and scale, I have to manually do it through the database interface like SSMS.

27 Comments
RonnieRichards

@SSWoodward 

@mpboyle is correct I don't think the option to specify precision in the Create Feature Class/Table wizards have ever been present in a Pro release. 

The right click within an Enterprise Geodatabase in Catalog is one of the quickest navigations for new tables in Catalog. Right click create a new table and import from a template. 

As an educator students are going to gravitate to the context tools before searching for geoprocessing tools so please make them behave consistently. Your future ArcGIS Desktop users will appreciate consistency and really enjoy creating GIS data models in the Enterprise GDB especially considering this requires Professional Plus licensing to "create" in an EGDB.

This was a solid workflow in ArcMap

Michele_Hosking

And you know what - it's not all about the Create Feature Class/Table wizards in Pro.  It's the fact that somewhere along the line (and this did happen during the ArcPro days) the default for a double field in an enterprise geodatabase has changed from 38/8 to 7/1. Now 38/8 is a little ridiculous I grant you but at least it's useful. It allows you to put whatever you like in the field so if someone forgets to change the precision it's still going to work.  7/1 is just a pain in the proverbial. As part of this can we please have this default changed to something sensible otherwise we will still be having the issue of finding out that a field doesn't have enough decimal places after a feature class /table has been created due to over-looking the 7/1 precision default and be back in the stupid position of having to recreate a table just to fix this issue.

RonnieRichards

@Michele_Hosking you are absolutely correct with that!!

This appeared to happen in the 3.2 release when the other GDB changes were introduced. Pro 3.2+ double data types are created as 7/1. This release also seems to break the FLOAT datatype.

Tables created prior to 3.2 release double data types were defined as 38/8.

RonnieRichards_0-1754612193053.pngRonnieRichards_1-1754612205281.pngRonnieRichards_2-1754612219840.png

PhilippeChesselVdG

Hello,

Yes , i am totally in line also with @Michele_Hosking , the problem is the change in 3.2 for Double and Float that has no logic and no justification for it. (Or ESRI should give us any good reason or that , i can hardly find any ?) 

And it is complicating a lot the life of end users.

The best option would be to allow scale and precision definition into the Add Table/Class wizard.

 

SSWoodward
Status changed to: Under Consideration
 
SSWoodward
Status changed to: In Product Plan
 
PeterMilenkovic

Yea this is a big let down.

My scenario is that i want to import a table from one sde to another. The field i wanted to modify was at position 10 of 42 so there is no way i was going to do this manually....

I asked co-pilot to generate some arcpy (notebook) that

  1. Copies the schema of the source to a dictionary
  2. Allows user input to modify field length, scale, precision for the specific field
  3. Creates new fc
  4. Systematically runs the add field tool using the schema dictionary
import arcpy, os

# Path to your feature class
source_name =<fc name to copy schema>
out_workspace = <path to sde connection>
out_name = <fc name>
spatial_ref_wkid = 7856  

# Initialize dictionary
schema_dict = {}

system_fields = ['OBJECTID','Shape','Shape.STLength()','Shape.STArea()']

source_fc = os.path.join(out_workspace, source_name)

# Loop through fields
for field in arcpy.ListFields(source_fc ):
    if field.name not in system_fields:
        schema_dict[field.name] = {
            "type": field.type,
            "length": field.length,
            "precision": field.precision,
            "scale": field.scale
        }

## hard coding the new precision/scale/length for the specific field
schema_dict['Estimated_Cost']['precision']=20
schema_dict['Estimated_Cost']['scale']=2
schema_dict['Estimated_Cost']['length']=22

SYSTEM_FIELD_NAMES = {"OBJECTID", "FID", "Shape", "SHAPE", "GLOBALID", "Shape_Length", "Shape_Area"}

def map_type_to_addfield(field_type):
    """
    Map Describe/ListFields types to AddField types.
    ArcPy expects AddField type keywords (TEXT, SHORT, LONG, FLOAT, DOUBLE, DATE, GUID, BLOB, RASTER).
    """
    mapping = {
        "String": "TEXT",
        "SmallInteger": "SHORT",
        "Integer": "LONG",
        "Single": "FLOAT",
        "Double": "DOUBLE",
        "Date": "DATE",
        "GlobalID": "GUID",
        "GUID": "GUID",
        "Blob": "BLOB",
        "Raster": "RASTER",
        # Types we won't add: 'OID', 'Geometry' (system-managed)
        "OID": "OID",
        "Geometry": "GEOMETRY",
    }
    return mapping.get(field_type, field_type)

def make_spatial_reference(wkid):
    if wkid is None:
        return None
    sr = arcpy.SpatialReference(int(wkid))
    return sr

# --------------------------
# Create feature class (Polygon, no Z, no M)
# --------------------------
if not arcpy.Exists(out_workspace):
    raise RuntimeError(f"Workspace does not exist: {out_workspace}")

sr = make_spatial_reference(spatial_ref_wkid)
arcpy.management.CreateFeatureclass(
    out_path=out_workspace,
    out_name=out_name,
    geometry_type="POLYGON",
    template="",
    has_m="DISABLED",
    has_z="DISABLED",
    spatial_reference=sr
)

out_fc = os.path.join(out_workspace, out_name)

# --------------------------
# Add fields by looping schema_dict
# --------------------------
for fname, props in schema_dict.items():
    # Skip known system fields if they were captured in your dict by accident
    if fname in SYSTEM_FIELD_NAMES:
        continue

    ftype = map_type_to_addfield(props.get("type"))
    if ftype in ("OID", "GEOMETRY"):
        # Do not add system-managed types
        continue

    length = props.get("length")
    precision = props.get("precision")
    scale = props.get("scale")

    # ArcPy expects "" (empty string) for unspecified numeric props
    # and uses 'length' only for TEXT/BLOB; precision/scale for numeric
    arcpy.management.AddField(
        in_table=out_fc,
        field_name=fname,
        field_type=ftype,
        field_precision=precision if (precision is not None) else "",
        field_scale=scale if (scale is not None) else "",
        field_length=length if (length is not None) else "",
        field_alias=fname,  # keep alias same as name; change if you have it
        field_is_nullable="NULLABLE",
        field_is_required="NON_REQUIRED",
        field_domain=""
    )

print(f"Created feature class and added {len(schema_dict)} fields at: {out_fc}")