Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm not entirely sure if I am using the correct terminology, so I apologize in advance. What I am looking to do is create a file geodatabase and add a feature class directly into that file geodatabase, as opposed to creating a feature class outside the file geodatabase and then importing it into the file geodatabase. The reason I need to be able to create the feature class directly in a file geodatabase is because I need to have attribute table columns that are nullable, whereas if I create a feature class outside the file geodatabase and then import it into the file geodatabase, nulls will not be allowed. Please correct me if I am wrong. Currently, I am able to create the file geodatabase, but I can't add a feature class directly to the file geodatabase. Any help would be greatly appreciated. Thanks.

The code I currently have is:

 import os, arcgisscripting
 gp = arcgisscripting.create(9.3)
 gp.Overwriteoutput = 1
 cwd = "C:\\Path\\To\\directory"
 gp.workspace = cwd
 gp.toolbox = "management"
 number = '1'
 fileGDB = "test_%s.gdb" % number
 shpFile = "file_%s.shp" % number
 gp.CreateFileGDB(cwd, fileGDB)
 gp.CreateFeatureclass(fileGDB, shpFile, "POINT", '#', '#', '#', '#')
 gp.addfield ( shpFile, fieldName, "FLOAT", "20","20", "#", "#", "NULLABLE", "#", "#")
 ...the rest of my code here
share|improve this question
Why are you using a modulus when defining your file GDB and shpFile name? – Nathanus Jul 8 '11 at 21:13
@Nathanus: in this context % is a string formatting operator, so the result is 'test_1.gdb' – Mike T Jul 8 '11 at 22:15
@9monkeys: you have a subtle typo with "C:\Path\\To\\directory" .. make this either "C:\\Path\\To\\directory" or r"C:\Path\To\directory" – Mike T Jul 8 '11 at 22:19
Are you trying to import a shapefile into the GDB? In that case you would use FeatureClassToFeatureClass. I think you do have some terminology confused. – Sean Jul 9 '11 at 15:28
@Mike Yes, thanks, that was a typo. I don't want to import a shapefile into the GDB because the shapefile needs to be able accomodate nulls, which shapefiles can't (see this very interesting post while GDBs can. That being said, if I build the shapefile outside of the GDB then I won't be able to use nulls whereas if I build inside of a GDB then I can use nulls. – 9monkeys Jul 11 '11 at 12:13
up vote 4 down vote accepted

I think your first problem is that you're appending ".shp" to your output geodatabase featureclass. Remove this and your problem may be solved.

shpFile = "file_%s" % number  #--removed ".shp"
...the rest of your code here
share|improve this answer
Yes, that worked. Thanks – 9monkeys Jul 11 '11 at 14:42
Glad to help... – Jason Jul 14 '11 at 3:38

Since the steps you are doing comprise of geoprocessing tools, could you just build it in model builder and export out the script to py? I did this in 9.3.1, I'm not sure if the script is the same in 9.3, see code below.

# Import system modules
import sys, string, os, arcgisscripting

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

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

# Local variables...
test_gdb = "C:\\Temp\\test.gdb"
Temp = "C:\\Temp"
fclass = "C:\\Temp\\test.gdb\\fclass"
test_gdb__2_ = "C:\\Temp\\test.gdb"
fclass__2_ = "C:\\Temp\\test.gdb\\fclass"

# Process: Create File GDB...
gp.CreateFileGDB_management(Temp, "test")

# Process: Create Feature Class...
gp.CreateFeatureclass_management(test_gdb__2_, "fclass", "POLYGON", "", "DISABLED", "DISABLED", "", "", "0", "0", "0")

# Process: Add Field...
gp.AddField_management(fclass, "number", "LONG", "2", "", "", "", "NULLABLE", "NON_REQUIRED", "")

You may have to reference the toolboxes that you are using.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.