Select to view content in your preferred language

Shapefile to Geodatabase scripting?

535
1
Jump to solution
11-18-2012 11:56 PM
TomHutchinson
Deactivated User
Hi all

I've built a model in model builder (9.2) and need to export the resulting output shape files into a Geodatabase within the same directory.

Normally I would use the 'Feature class to Geodatabase' tool within model builder however there are different output shape files created each time I run the model therefore conventional tools are not apopropriate.

I'm fairly new to Python and need the barebones of a script that will cut shapefiles from a directory into my Geodatabase.

Thanks,
Tom
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor
Hi all

I've built a model in model builder (9.2) and need to export the resulting output shape files into a Geodatabase within the same directory.

Normally I would use the 'Feature class to Geodatabase' tool within model builder however there are different output shape files created each time I run the model therefore conventional tools are not apopropriate.

I'm fairly new to Python and need the barebones of a script that will cut shapefiles from a directory into my Geodatabase.

Thanks,
Tom


Quickly put together, but it worked for me (ArcGIS 9.3.1). 

import arcgisscripting gp = arcgisscripting.create()  inputLocation = "C:\shps"  gp.Workspace = inputLocation  fcs = gp.ListFeatureClasses()  fcs.reset() fc = fcs.next() while fc:   ### to work with a File GDB, then use the .gdb extension   gp.FeatureClasstoGeodatabase(fc, inputLocation + "\\testFGDB.gdb")   ### to work with a Personal GDB, then use the .mdb file extension instead   gp.FeatureClasstoGeodatabase(fc, inputLocation + "\\testPGDB.mdb")    gp.AddMessage(str(fc) + " loaded into GDB")   fc = fcs.next()

View solution in original post

0 Kudos
1 Reply
JamesCrandall
MVP Frequent Contributor
Hi all

I've built a model in model builder (9.2) and need to export the resulting output shape files into a Geodatabase within the same directory.

Normally I would use the 'Feature class to Geodatabase' tool within model builder however there are different output shape files created each time I run the model therefore conventional tools are not apopropriate.

I'm fairly new to Python and need the barebones of a script that will cut shapefiles from a directory into my Geodatabase.

Thanks,
Tom


Quickly put together, but it worked for me (ArcGIS 9.3.1). 

import arcgisscripting gp = arcgisscripting.create()  inputLocation = "C:\shps"  gp.Workspace = inputLocation  fcs = gp.ListFeatureClasses()  fcs.reset() fc = fcs.next() while fc:   ### to work with a File GDB, then use the .gdb extension   gp.FeatureClasstoGeodatabase(fc, inputLocation + "\\testFGDB.gdb")   ### to work with a Personal GDB, then use the .mdb file extension instead   gp.FeatureClasstoGeodatabase(fc, inputLocation + "\\testPGDB.mdb")    gp.AddMessage(str(fc) + " loaded into GDB")   fc = fcs.next()
0 Kudos