Select to view content in your preferred language

gp.QualifiedFieldNames = "UNQUALIFIED" is not working

3034
8
07-21-2011 07:43 AM
HalilSiddique
Frequent Contributor
Hi all,

I have the following script, but for some reason in my shapefile (Step 5) , its does not keep the field name for the Joined fields.

# Name: BLPU_VIEW.py
# Author: Halil Siddique
# Description: This scripts will  Join the BLPU Point layer and the GIS_LLPG_SOURCE view.
# Date: 21/07/2011

# Create the Geoprocessor object
import arcgisscripting
gp = arcgisscripting.create(9.3)

# Allow Overwrite
gp.OverwriteOutput = 1

# Set Workspace
gp.Workspace = "C:\\datadump"
datadump = gp.Workspace

# Input variables from SDE
inputPoint = "C:\\TestData on CORPGIS.sde\\TESTDATA.BLPU_POINT"
inputView = "C:\\TestData on CORPGIS.sde\\TESTDATA.GIS_LLPG_SOURCE"
BLPU_TEST = "C:\\TestData on CORPGIS.sde\\TESTDATA.BLPU_TEST"

# Input variables from datadump folder

# Allow Unqualified field names
gp.QualifiedFieldNames = "UNQUALIFIED"

#####################################################################

try:

    
    # Create Feature Layer from BLPU point
    gp.makeFeatureLayer_management(inputPoint, "point_lyr")
    print "1 - ", inputPoint, "is now a feature layer"

    # Export GIS_LLPG_SOURCE to datadump to get OID
    gp.copyrows_management(inputView, "GIS_LLPG_SOURCEExport")
    print "2 - ", "inputView", "has been exported to", datadump

    # Create Table View from GIS_LLPG_SOURCE
    gp.makeTableView_management("GIS_LLPG_SOURCEExport", "GIS_LLPG_SOURCEView")   
    print "3 - GIS_LLPG_SOURCE is now a table view"

     # Join BLPU_POINT layer  with GIS_LLPG_SOURCE
    gp.AddJoin_management("point_lyr", "UPRN", "GIS_LLPG_SOURCEView", "UPRN")
    print "4 - ", "Points has been joined to GIS_LLPG_SOURCE"

    
    # Export Joined Point layer
    gp.copyFeatures_management("point_lyr", "READY_FOR_SDE")
    print "5 - ", "Joined points has been exported to", datadump

    # Delete features from SDE layer
    gp.deletefeatures(BLPU_TEST)
    print "6 - ", "BLPU_TEST features deleted"

    # Upload new BLPU points
    gp.append_management("C:\\datadump\\READY_FOR_SDE.SHP", BLPU_TEST, "NO_TEST","")
    print "7 - ", "new BLPU points uploaded"
    
except:
    print "Error has occured"
    print gp.getmessages()




My field names end up becoming

  GIS_LLPG_S   GIS_LLPG_1   GIS_LLPG_2   GIS_LLPG_3   GIS_LLPG_4   GIS_LLPG_5   GIS_LLPG_6   GIS_LLPG_7   GIS_LLPG_8   GIS_LLPG_9   GIS_LLP_10   GIS_LLP_11   GIS_LLP_12   GIS_LLP_13   GIS_LLP_14   GIS_LLP_15   GIS_LLP_16
Anyone got any ideas or workarounds?

Cheers
halil
Tags (2)
0 Kudos
8 Replies
OliverSoong
Emerging Contributor
I'm running ArcGIS Desktop 10.0 SP5.

I'm trying to write a python script to join fields from an Info table to a Coverage region and then Copy Features into a shapefile.  Join Field isn't working for me (all new fields are blank), but Add Join does work when I test things.  However, the qualified field names are too long for the shapefile, so they get truncated in an uninformative manner.  My fields are named uniquely, so I wanted to use unqualified field names.

If I set arcpy.env.qualifiedFieldNames = False, the coverage region fields are qualified and the new fields from the info table are not.

If I start a fresh ArcMap session, then set arcpy.env.qualifiedFieldNames = False in the python window, I get the same results, but I noticed that I can simultaneously have arcpy.env.qualifiedFieldNames = False and GeoProcessing->Environments->Fields->Maintain fully qualified field names be checked.

If I start a fresh ArcMap session, set arcpy.env.qualifiedFieldNames = False in the python window, and uncheck GeoProcessing->Environments->Fields->Maintain fully qualified field names, I get the expected/desired results.

Just for kicks, if I start a fresh ArcMap session, and only uncheck GeoProcessing->Environments->Fields->Maintain fully qualified field names, I only get qualified field names.  This is consistent with previously reported behavior:
http://forums.esri.com/Thread.asp?c=93&f=986&t=278342&mc=4

Basically, it looks like the ArcMap GUI setting and the python setting are actually separate and both are being used.
0 Kudos
curtvprice
MVP Alum
Basically, it looks like the ArcMap GUI setting and the python setting are actually separate and both are being used.


The geoprocessing environment settings read when a tool dialog is run many not always be in synch, with the application settings, but in the context of a script, the environment settings are entirely local and should override any GP settings set at the application or model or tool level.

You may have better luck by specifying it as a boolean. (Easier to spell!)

arcpy.qualifiedFieldNames = False


A warning: in arcpy, arcpy.env object names are case-sensitive. For example:

>>> arcpy.env.QualifiedFieldNames = False # No error, but will not work
>>> arcpy.env.qualifiedFieldNames = False # will work


arcgisscripting is still there under ArcPy, so they do share environments, and setting either "gp" or "arcpy" should "take" with any tools run.

I did this test with 10.1:

>>> import arcpy
>>> import arcgisscripting
>>> gp = arcgisscripting.create(9.3)
>>> gp.QualifiedFieldNames = "QUALIFIED"
>>> gp.QualifiedFieldNames
True
>>> arcpy.env.qualifiedFieldNames
True
>>> gp.QualifiedFieldNames = "UNQUALIFIED"
>>> gp.QualifiedFieldNames
False
>>> arcpy.env.qualifiedFieldNames
False
0 Kudos
FrankChin
Emerging Contributor
I am also experiencing this problem. Even though I set: arcpy.env.qualifiedFieldNames = False and verify with a print statement that qualifiedFieldNames is "False", when I join a layer file to a table, the field names still have the predicated file/table name preceeding it.  Has anyone found a solution?
0 Kudos
curtvprice
MVP Alum
Even though I set: arcpy.env.qualifiedFieldNames = False and verify with a print statement that qualifiedFieldNames is "False", when I join a layer file to a table, the field names still have the predicated file/table name preceding it.


I believe the qualified field names still exist in the table view after you do a join; the environment setting comes into play when that table view is accessed by a tool that copies the table, for example, CopyFeatures_management. In the tool output, the names should not be qualified if qualifiedFieldNames is False.

This is what is demonstrated in the example in the help for qualifiedFieldNames.
0 Kudos
FrankChin
Emerging Contributor
Even when I save the layer to a layer file, the source names still persist.
0 Kudos
curtvprice
MVP Alum
Even when I save the layer to a layer file, the source names still persist.


If you want to remove the source names, you need to copy out to a dataset. Saving to a layer will not unqualify field names, as a layer just points to the datasets - which have not changed.

For example, if I do a join, this is what I get for a field list:

arcpy.AddJoin(..)

Field                        Type     Len
-------------------------    -------  ---
Yellowsone_line.FID          OID       4
Yellowsone_line.Shape        Geometry  0
Yellowsone_line.ObjectID     Integer   9
Yellowsone_line.FEATURE      String   21
Yellowsone_line.NAME         String   59
Yellowsone_line.STATE        String    5
Yellowsone_line.MILES        Double   12
Yellowstone_lakes.FID        Integer   4
Yellowstone_lakes.ObjectID   Integer   9
Yellowstone_lakes.FEATURE    String   22
Yellowstone_lakes.NAME       String   40
Yellowstone_lakes.STATE      String   20
Yellowstone_lakes.SQMI       Double   10


Now, if I copy this, qualifiedFieldNames comes into play:

arcpy.env.qualifiedFieldNames = True
arcpy.CopyFeatures_management("Yellowsone_line","e:\\work\\xxline.shp")

          Field            Type   Len
      ----------      ---------- -----
             FID             OID     4
           Shape        Geometry     0
      Yellowsone         Integer     9
      Yellowso_1          String    21
      Yellowso_2          String    59
      Yellowso_3          String     5
      Yellowso_4          Double    14
      Yellowston         Integer     9
      Yellowst_1         Integer     9
      Yellowst_2          String    22
      Yellowst_3          String    40
      Yellowst_4          String    20
      Yellowst_5          Double    12



arcpy.env.qualifiedFieldNames = False
arcpy.CopyFeatures_management("Yellowsone_line","e:\\work\\xxline.shp")

           Field            Type   Len
      ----------      ---------- -----
             FID             OID     4
           Shape        Geometry     0
        ObjectID         Integer     9
         FEATURE          String    21
            NAME          String    59
           STATE          String     5
           MILES          Double    14
           FID_1         Integer     9
      ObjectID_1         Integer     9
       FEATURE_1          String    22
          NAME_1          String    40
         STATE_1          String    20
            SQMI          Double    12
0 Kudos
FrankChin
Emerging Contributor
Thank you Curtis, that worked.  I am new to ArcGIS, so I am just learning the concepts.
0 Kudos
curtvprice
MVP Alum
Thank you Curtis, that worked.  I am new to ArcGIS, so I am just learning the concepts.


No problem! Glad to help -- I wish someone had explained this to me. The help kind of misses how this works IMHO. I will share my blog post to the help authors (note, you can comment and suggest things in the online ArcGIS help web pages - this is a big help to everyone!)
0 Kudos