POST
|
Question about the importance of this script: Is this your companies (organization's) policy to convert shapefiles to file geodatabases? Or is ESRI dictating this move because shapefiles are going to be deprecated in the near future? It was an internal company shift from shapefiles to FGDB's.
... View more
11-20-2012
08:23 AM
|
0
|
0
|
345
|
POST
|
Hello all, In the code below, I can get the python window in arcmap to show that the visibility flag is being changed for the apprpriate fields, but the changes aren't being reflected in the new feature layer's attribute table. I've tried updating the MXD, the active view, all sorts of things. Any help would be appreciated. try:
layer = pythonaddins.GetSelectedTOCLayerOrDataFrame()
fldInfo = arcpy.FieldInfo()
KeepList = ['Loc_name','Match_type','Match_addr']
for field in arcpy.ListFields(layer):
if field.name in list(KeepList):
fldInfo.addField(field,field ,"VISIBLE","")
for field in arcpy.ListFields(layer):
if field.name not in list(KeepList):
fldInfo.addField(field,field,"HIDDEN","")
except:
Problem()
else:
arcpy.MakeFeatureLayer_management(layer, "Formatted","","",fldInfo)
... View more
11-20-2012
08:21 AM
|
0
|
0
|
556
|
POST
|
Your idea worked! Here is the code as of current: import arcpy,os
from arcpy import env
path = 'E:\\GDBConversionProject\\2062 Cabin Bluff'
env.workspace = path
arcpy.management.CreateFileGDB(env.workspace,"Project","10.0")
try:
def fcs_in_workspace(workspace):
env.workspace = workspace
for fc in arcpy.ListFeatureClasses():
yield fc
for ws in arcpy.ListWorkspaces():
for fc in fcs_in_workspace(os.path.join(workspace, ws)):
if ws != path +"\\Project.gdb":
yield fc
OutGDB = env.workspace +'\\Project.gdb'
for fc in fcs_in_workspace(env.workspace):
arcpy.FeatureClassToGeodatabase_conversion(fc,OutGDB)
print(fc +' copied.')
except Exception as e:
print(e)
else:
env.workspace = path
print("Compressing FileGDB.")
arcpy.CompressFileGeodatabaseData_management(OutGDB)
print(OutGDB + " has been compressed.")
... View more
04-20-2012
10:40 AM
|
0
|
0
|
345
|
POST
|
No, the indentation isn't correct and thanks for the catch on fcs_in_workspace. Nerves got the best of me while I was setting up, with it being my first post and all. I will test the != idea and get back to you. Thanks!
... View more
04-20-2012
10:01 AM
|
0
|
0
|
345
|
POST
|
I'm trying to convert all shapefiles into feature classes in my directory, including what's inside sub-folders. The code that I've compiled below (from reading previous answers and trial & error on my part) accomplishes this, but it seems that it also begins to iterate through the newly created GDB as well, which is bad. Any advice or insight would be greatly appreciated. import arcpy from arcpy import env import os path = 'C:\\Data' env.workspace = path arcpy.management.CreateFileGDB(env.workspace,"Project","10.0") try: def fcs_in_workspace(workspace): env.workspace = workspace for fc in arcpy.ListFeatureClasses(): yield fc for ws in arcpy.ListWorkspaces(): for fc in fcs_in_workspace(os.path.join(workspace, ws)): yield fc OutGDB = env.workspace +'\\Project.gdb' for fc in fcs_in_workspace(env.workspace): arcpy.FeatureClassToGeodatabase_conversion(fc,OutGDB) print(fc +' copied.') except Exception as e: print(e) else: env.workspace = path arcpy.CompressFileGeodatabaseData_management(OutGDB) print(OutGDB + " has been compressed.")
... View more
04-20-2012
09:30 AM
|
0
|
5
|
543
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|