Feature class to Feature class using python

3970
8
07-09-2015 02:07 PM
RyanKammerer1
New Contributor III

I have a feature class that has several sql db tables joined to it. It's been my workflow to update values in these tables, and then export the joined feature class over to sde GDB to use for published map services. I'm trying to automate this step using python. Is there a way in Python to open a map document (with the feature class and joined tables), select the feature class and export the feature class to a Geodatabase? Any help would be much appreciated.

Thank you

0 Kudos
8 Replies
SamuelTompsett
Occasional Contributor II

Hi Ryan,

I'm not positive about the join, but you can open a mxd with python using the arcpy.mapping module. It has access to the table of contents, so I would imagine the join would be active while open in python.

ArcGIS Help 10.1

-Sam

DarrenWiens2
MVP Honored Contributor

Not an answer, but I believe this should have worked. It doesn't. It blanks out all the joined fields in the first layer, which has a join:

import arcpy
arcpy.env.overwriteOutput = True

mxd = arcpy.mapping.MapDocument('C:/junk/junk_map.mxd')

layers = arcpy.mapping.ListLayers(mxd)

arcpy.CopyFeatures_management(layers[0],'C:/junk/FILE_GDB.gdb/copy')
SamuelTompsett
Occasional Contributor II

Good to know. Thanks for the reply Darren.

0 Kudos
RyanKammerer1
New Contributor III

Just thought I'd thank those for the feedback so far. I appreciate the suggestions and comments, but I still haven't resolved the issue. I'll keep trying.

Thank you

0 Kudos
AsrujitSengupta
Regular Contributor III

I am not much into Python, however you can try creating something like this:

sample.PNG

Basically, create a Python script which will Join the feature class to the different database tables and then Export the output of the Joins as a new Feature Class to the desired SDE geodatabase, for publishing.

RyanKammerer1
New Contributor III

Thanks Asrujit for the suggestion. I'll give that a try.

0 Kudos
BrandonKeinath1
Occasional Contributor III

Hi Ryan,

Another option you might try in python is arcpy.AddJoin.  It works like Join Field but since it operates on in-memory features it works much much faster.  I converted a model that used Join Field last week that took approximately 3 hours to run.  Now using AddJoin it runs in 2.5 minutes.

Brandon

RyanKammerer1
New Contributor III

Thanks for the suggestion Brandon, I'll test arcpy.AddJoin out. I have 7

tables joined to the feature class I'm trying to export to SDE and the

script has been running a good hour and a half and its still chewing on the

7th join. Thanks you for the advice!

Ryan

0 Kudos