Wednesday 20 December 2017

arcgis desktop - Move .SHP from .MXD to gdb




Possible Duplicate:
How to move SHP to gdb with ArcView license?



Let's cut it short, I have numerous mxd with layer coming from .SHP and various servers WMS that I need to move to a gdb. What I want is to open the mxd and run a script that select all .SHP layers in the TOC create a gdb, export the .SHP, and create a new MXD with the new path pointing to gdb.



Following is the code I wrote, but I can't have it to select only the .SHP, I tried with describe dataType but they all come out as "FeatureLayer"...need help!


# Import system modules 
import arcpy, datetime, os, traceback
from arcpy import env

# Load required toolboxes...
arcpy.AddToolbox("C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\ArcToolbox\\Toolboxes\\Data Management Tools.tbx")


# Get the active map document

import arcpy.mapping
mxd = arcpy.mapping.MapDocument ("CURRENT")

# List broken links
# arcpy.mapping.ListBrokenDataSources(mxd)

# Set environment settings
ws = "C:\\PARK"
arcpy.env.workspace = ws
print("env.workspace completed successfully")

installdir = arcpy.GetInstallInfo("desktop")

#check GDB exist
gdb_nam = "test.gdb"
gdb_full_path = os.path.join(ws,gdb_nam)
if os.path.exists(gdb_full_path):
arcpy.Delete_management(gdb_full_path)
print("GDB checked")

# Execute CreateFileGDB

arcpy.CreateFileGDB_management(ws, gdb_nam)
print("CreateFileGDB completed successfully")
outWorkspace = gdb_full_path

# Iterate

list = []

for df in arcpy.mapping.ListDataFrames (mxd):
for fc in arcpy.mapping.ListLayers (mxd, "", df):

if (fc.datasetName.endswith(".shp")):
list.append(fc)
for fc in fclist:
arcpy.FeatureClassToGeodatabase_conversion(fc, gdb_full_path)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...