1

I create an empty file geodatabase (gdb), and I would like to import in this gdb several feature dataset, at least 120 different dataset. I would like to import those dataset from a table like an excel table.

I try to do this with the python command with something like :

arcpy.CreateFileGDB_management("C:/data/arcgis/gdb", "gdbTemp.gdb")
<Result 'C:/data/arcgis/gdb\\gdbTemp.gdb'>

>>> import arcpy
from arcpy import env

env.workspace = "C:/data/arcgis/gdb"
arcpy.CreateFeatureDataset_management("C:/data/arcgis/gdbTemp.gdb", 

...

From the last line I don't know how to :

  • import my spreadsheet
  • tell I want for each line of the spreadsheet a new feature Dataset in my geodatabase

My actual spreadsheet looks like that, Its is very basic with only the name of the dataset (I want to go step by step).

enter image description here

So, I would like to create for each row a new dataset in the geodatabase.

I found something for an other post, It seems to be a good starting point :

fdList = [...]

Here I could make a command that get back from the spreadsheet the name of all my future dataset.

Then with a loop, add them on the geodatabase :

for fd in fdList:
    arcpy.CreateFeatureDataset_management(""C:/data/arcgis/gdbTemp.gdb"", fd, "I:/python/MultipleFD2GDB/2229.prj")

I need to do this with the python command (is this arcpy?)

6
  • It sounds like there are two things (your two dot points) you are stuck on, so I suspect that you have two questions to research. For us to help, on either of them, we would need to be able to see what is in each of a few rows from your spreadsheet. It looks like you are experimenting from the Python window of ArcMap (which is good), but when you present code here I think it needs to be something that we can run using IDLE (or whichever Python IDE a potential answerer chooses to use).
    – PolyGeo
    Commented Jul 27, 2015 at 7:39
  • @PolyGeo I try to add some details. The first thing I'd like to know is : how in the python's command (with CreateFeatureDataset) I could create all the dataset from the Excel file. Is it even possible ? It would be very long to create one by one all the dataset !
    – Manimalis
    Commented Jul 27, 2015 at 7:58
  • 1
    Are you sure that you want to create feature datasets? The reason I ask is that the values you have in column A of your spreadsheet look more like feature classes.
    – PolyGeo
    Commented Jul 27, 2015 at 8:37
  • @PolyGeo I checked and I really want to create feature datasets. I don't need feature classes
    – Manimalis
    Commented Jul 27, 2015 at 8:39
  • 1
    Feature datasets are to be used only for cooperative editing (e.g., poles and transmission lines), not to group feature classes. To state "I don't need feature classes" means you need to review the Esri data model terminology.
    – Vince
    Commented Jul 27, 2015 at 10:40

1 Answer 1

3

Below is the code you require:

import arcpy
xls = r"C:\Scratch\Book1.xls"
table =r"C:\Scratch\tempxls.dbf"
arcpy.ExcelToTable_conversion(xls,table)
with arcpy.da.SearchCursor(table,["Feature"]) as cursor:
    for row in cursor:
        fd = row[0]
        print "Creating FeatureDataset: " + fd
        arcpy.CreateFeatureDataset_management(r"C:\Scratch\fGDB_Scratch.gdb", fd)

# Clean up
arcpy.Delete_management(table)

You need to read the Excel file, I did this by converting it into a temporary dBase file which I delete at the end. The code then steps through the temporary table reading each row and using that as the name for the FeatureDataset. In my example I do not set a spatial reference.

I don't think (but could be wrong) that you can read an Excel table with a search cursor in arcpy. This answer to Reading Excel sheet in ArcPy script? discusses reading an Excel sheet using another Python module.

4
  • I try your code. It's seems good but I have the following error : Runtime error Traceback (most recent call last): File "<string>", line 6, in <module> RuntimeError: A column was specified that does not exist.
    – Manimalis
    Commented Jul 27, 2015 at 12:38
  • I don't know how to solve this error... @Hornbydd
    – Manimalis
    Commented Jul 27, 2015 at 12:39
  • Have you just copied and edited it? Python is very particular with regards to spacing. Don't get TAB and space characters mixed up. I would check that first.
    – Hornbydd
    Commented Jul 27, 2015 at 13:25
  • I had some mistakes but now it works very well, thank you ! @Hornbydd
    – Manimalis
    Commented Jul 28, 2015 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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