bartkowalski

Problem with populating new feature class using template feature class.

Discussion created by bartkowalski on Sep 7, 2011
Latest reply on Sep 8, 2011 by bartkowalski
hello,
I wrote a script that creates a new feature class with field values from a table accessed from SQL server. Instead of adding individual fields to the new feature class i tried to specify a template feature class, but I can't get it to work.

The code is:

import arcpy
import pyodbc
from arcpy import env
cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=user;PWD=password;SERVER=server; DATABASE=ftord; APP=MyApp')

cursor=cnxn.cursor()
cursor.execute("select well_name, welltype_desc from dbo.Wells_view")
rows = cursor.fetchall()

env.overwriteOutput = True
env.workspace = r"G:\Fort_Ord_GIS\Master_Coverage\Fort_Ord.gdb"
template = r"G:\Fort_Ord_GIS\Master_Coverage\Fort_Ord.gdb\improvement_well\water_well_point"

Wells = arcpy.CreateFeatureclass_management(r"G:\Temp\Bart\scratch.gdb", "ODB9", "POINT",template, "DISABLED", "DISABLED", template)
#arcpy.AddField_management(Wells,'PKWellID','TEXT')  
#arcpy.AddField_management(Wells,'PKMApID','TEXT')
#arcpy.AddField_management(Wells,'FKMetalID','TEXT')
#arcpy.AddField_management(Wells,'FKMediaID','TEXT')
#arcpy.AddField_management(Wells,'FKCoordbtID','TEXT')
#arcpy.AddField_management(Wells,'FKMnwellID','TEXT')
#arcpy.AddField_management(Wells,'WellCatDOM','TEXT')
#arcpy.AddField_management(Wells,'WellTypDOM','TEXT')
#arcpy.AddField_management(Wells,'WellStaDOM','TEXT')

Wcur = arcpy.InsertCursor(Wells)

for row in rows:
        #print row.well_name
        t_row = Wcur.newRow()
        t_row.PKWellID = row.well_name
        t_row.WellStaDOM = row.welltype_desc
        Wcur.insertRow(t_row)

cnxn.commit() 
cursor.close()
cnxn.close()

del row
del rows
del cursor 
del cnxn


The code works if I use the AddField commands foe each field individualy, but when I comment them out and try to use the template in CreateFeatureclass I get the following error messege:

Traceback (most recent call last):
  File "G:\Temp\Bart\Python\arcpy\ODBfetch4.py", line 30, in <module>
    t_row.PKWellID = row.well_name
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\_base.py", line 35, in __setattr__
    return setattr(self._arc_object, attr, ao)
RuntimeError: ERROR 999999: Error executing function.

I don't know what that means.

Any help would be appreciated,

Thanks,

Bart

Outcomes