geodatabase export to shapefiles

3781
14
12-13-2016 12:36 PM
johncoon
New Contributor

I can't seem to find a tool in ArcMap 10.2.2 standard that allows you to export all the layers in my TOC to a directory

with each shapefile file name per layer in the TOC. I have a template geodatabase that I loaded shape file data into, then edited that data. Now I need to export some 100 plus layers from the geodatabase as shape files to update the original data.

Because of that, I'm looking for a Python sample that exports all the layers in my TOC  to a file location or a function that selects the current geodatabase and exports all the features to shape files. Do you just copy and paste Python code to run it?

Is this something that can be none if I've never used Python before. I didn't see a lot of help for it, but I might of been looking in the wrong location. I looked around for a VBA macro editor as well and could located that. I might have a chance with that.

Thank you

John

Tags (1)
0 Kudos
14 Replies
RebeccaStrauch__GISP
MVP Emeritus

You will probably want to start with arcpy.mapping

MapDocument—Help | ArcGIS for Desktop 

This has some sample scripts of accessing the mxd and components.  Basically you will want to access the current .mxd, then the dataframes then the layers.  You should be able to loop thru those and export them.  Sorry, no code right now....but someone might have some.

0 Kudos
johncoon
New Contributor

Rebecca,

This is a good start, Thank you. I'm sure I can find samples, its knowing what those sample do is what I'll need after I get started.

Why don't they have built in tools for things like fix broken. If everyone who would move data for whatever reason gets a broken link why not have a tool to re-path to a directory.

quickly with having to write a script.

Thank you

John

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Why don't they have built in tools for things like fix broken

I would say because there are just too many variables on how people set up their mxds and data. There are several threads on how people fix, and I have an addin /blogs/myAlaskaGIS/2015/08/31/python-addin-for-data-inventory-and-broken-link-repair?sr=search&searc...‌ that might help for that (if that is an issue).  Even the mxd's we have internally, created over many years and hardware changes are not a simple replace...this helps search out the many paths I had to the same data (sometimes dependent on the user/machine it was created) and can replace to one common path if needed....but that is of the subject of the post.

Once you get some code written, if you have issues, you can post, but make sure to us the ... in the toolbar for your comment, use the More->Syntax Highlighter->python and post you code there.  Python is very picky about spacing. 

Also, learn to use the   r"c:\mydir\mydubdir"     for paths,....that is   r"....path..."  otherwise the \ can be interpreted incorrectly.

This and many other python tips/links can be found /blogs/dan_patterson/2016/05/09/the-links?sr=search&searchId=3b2ea13c-be3b-4e62-b97a-1dc8faeff854&se...‌  

Have fun!

0 Kudos
johncoon
New Contributor

Rebecca,

I did have an issue a while ago with links on another project, I moved data and didn’t know the links would be lost. I fixed them manually. Now, I know to be careful when moving support data. I’m a cad guy in a GIS world currently. We normally consume GIS data, so updating features and validating exports, layers and attribute fields for a FAA online portal is a little more

GIS than I’m used to. One of my tasks is to export each feature from a template manual that is two volumes with 500 page each. That’s why I wanted/needed a tool to export multiple features. Thanks for all your help.

John

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

I have a template geodatabase that I loaded shape file data into, then edited that data. Now I need to export some 100 plus layers from the geodatabase as shape files...

Sorry, I was thinking you wanted the layers in a TOC of a map document, in which case code here   help exporting map layers  would be helpful.

If you are just trying to export layers in a GDB to shapefiles, look at these help pages

Feature Class To Shapefile—Help | ArcGIS for Desktop

Feature Class To Feature Class—Help | ArcGIS for Desktop 

They have code for scripting, but you may just be able to use the tool manually...unless there are too many to "drag-n-drop" in the tool, or if you need to rename output.  Keep in mind that shapefiles follow many of the old DBF and windows naming limitations, in which case some filenames or fieldnames may be renamed or truncated, causing potental duplicate names (which could cause the command to crash, etc), so if you can figure out a method to break it up so you can keep track of where you are in processing the 500 layers, that may be helpful. 

I don't speak CAD anymore (many moons ago I did a little) so I still may be interpreting your request incorrectly.  My apologies if I am, and maybe someone else can jump in. 

0 Kudos
johncoon
New Contributor

Rebecca,

I was looking to do the TOC export or by geodatabase. I thought they were doing the same task, exporting groups of shape file at one time to a directory. I apologize, I guess I was mixing up the tasks.

Thanks so much for the links. those look great. I’ll see if I came make some headway with them tonight.

Is Python a paste and run tool? You don’t need to load a dll or dvb to run.

John

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

You may want to also look at this thread...maybe model builder will help for you.

Is Python a paste and run tool?  You don’t need to load a dll or dvb to run.

If you are in a python window, in ArcMap or ArcCatalog or some other compatible python environment that sees the Python installed with the ArcGIS software, you can

import arcpy

and pretty much run any of the tools in the ArcGIS toolbox.  Running python itself is not what you would drag-n-drop into, but any of the tools with a user interface (which you could create yourself, but might not be worth your time right now), or the model builder can be.  If this is something you are doing often, it would be work automating is...if a one time thing, might not be worth it.  But if you do get it to run successfully, you can also grab the python snippet for the Geoprocessing- (on the toolbar in ArcMap/Catalog)>Results tab.  By the way, the file gdb is a better way to go than shapes, more reliable and more features built in....but maybe you have a specific reason for the shapes.

Many ways to do the same thing.

0 Kudos
johncoon
New Contributor

Rebecca,

I have watched a few you tube videos on the model builder, I did one for an online course I took a couple of years ago. I wish they had something like that for a civil cad environment.

I been writing vb apps for years to do stuff a lot less complicated that the model builder samples I’ve seen. Super powerful & clean, after you get the process down.

I’ll take a look. Again, thanks for the help. I’ll take a stab at it.

John

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Python is even easier than VB, in my opinion. I personally don't use Model Builder and prefer to just write it (or grab someone else's code and modify....isn't that the programmer's motto?).  I think you will like python once you get a handle on it. 

0 Kudos