Specify geometry type using python...?

1659
4
Jump to solution
12-07-2016 06:23 AM
AhmedAbdelnasser1
New Contributor III
  1. OK, here is the story :
    I am working with ORACLE enterprise 12c DB 
    created big number of  feature classes from oracle with SDO geometry type.

  2. what i want :
     I want to register every feature class so ESRI can identify the geometry type using python.
    but the problem is to specify the geometry type before registering. 

    P.s: I can do that using arc catalog  right click on every feature class.Manage.Register with the DB.then a popup will appear and I have to enter the geometry type from a drop down list , but this will take forever!.

  3. what i have done
    I wrote this python code i need to add on it the part to specify the geometry but i don't know the function or the way to that.
    in line 11 is the path to the sde connection to the oracle DB.
    in line 12  is the path for a file containing the names for all my feature classes.

    # -*- coding: cp1252 -*-
    
    import sys
    import traceback
    import subprocess
    import arcpy
    
    
    try:
        arcpy.env.workspace = r"C:\xxESRI\Desktop10.4\ArcCatalog\12C_oracle.sde"
        txtPath = r"C:\Users\FCList.txt"
        txt = open(txtPath, "r")
        for line in txt.readlines():
            fcName = line.split(":")[0]
            print (fcName)
            arcpy.RegisterWithGeodatabase_management(fcName)
            print ("{0} ist registriert".format(fcName))
        txt.close()
    
    
    except:
        try:
            txt.close()
        except:
            pass
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
        pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n    " + \
                str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
        print(pymsg)
        msgs = "Arcpy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
        print(msgs)
    ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

0 Kudos
1 Solution

Accepted Solutions
ChristianWells
Esri Contributor

Currently this functionality does not exist within arcpy, however, one workaround is to insert 1 record of the spatial type you want. From here, register the table where arcpy will discover the geometry type. Once this is complete you can delete the data from the table. 

View solution in original post

4 Replies
ChristianWells
Esri Contributor

Currently this functionality does not exist within arcpy, however, one workaround is to insert 1 record of the spatial type you want. From here, register the table where arcpy will discover the geometry type. Once this is complete you can delete the data from the table. 

AhmedAbdelnasser1
New Contributor III

Thank you Christian for your response , 

regarding the workaround it wont easily apply in my case because the size,number of the tables and the relations it would take a lot more than registering the features manually!

 Will appreciate sharing any other workaround to fix it  it ...

0 Kudos
ChristianWells
Esri Contributor

Thanks, Ahmed. Unfortunately, your options for workarounds are limited to: 

1. Insert 1 record in the table
2. Manually update entity via ArcCatalog and register
3. Create all feature classes from Arcpy, not SQL

0 Kudos
LukeWebb
Occasional Contributor III

Do you have an method to populate the data into the tables? If you need the data within anyways you need to do this task either way, and then you can run your existing script.

If not, how do you plan to specify the geometry types anyways? You would need to specify them somewhere, then you could create a sample feature for each type of geometry, and have a line of code to copy this feature into the FC. e.g.

__author__ = 'WebbL'


import sys
import traceback
import subprocess
import arcpy


try:
    arcpy.env.workspace = r"C:\xxESRI\Desktop10.4\ArcCatalog\12C_oracle.sde"
    txtPath = r"C:\Users\FCList.txt"
    txt = open(txtPath, "r")
    for line in txt.readlines():
        fcName = line.split(":")[0]

        #Add a feature of required geometry type
        fcGeometryType = line.split(":")[1]
        inputGeometryFeat = [os.path.join(geometryTemplateFolder, fcGeometryType)]
        arcpy.Append_management(inputGeometryFeat,  fcName, "NO_TEST")


        print (fcName)
        arcpy.RegisterWithGeodatabase_management(fcName)
        print ("{0} ist registriert".format(fcName))


        #Clean up the template geometry
        arcpy.DeleteFeatures_management(fcName)

    txt.close()


except:
    try:
        txt.close()
    except:
        pass
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n    " + \
            str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
    print(pymsg)
    msgs = "Arcpy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
    print(msgs)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos