|
POST
|
I think you'll want a variation of this code found here. I've modified the code and it worked for my test folder which has multiple subfolders and shapefiles. import arcpy, os
workspace = r'C:\Users\xxx\Desktop\boundary'
output_folder = r'C:\Users\xxx\Desktop\New folder'
Dict = {}
allFolders = [os.path.join(workspace, name) for name in os.listdir(workspace) if os.path.isdir(os.path.join(workspace, name))]
def recursive_list_fcs(workspace, wild_card=None, feature_type=None):
"""Returns a list of all feature classes in a tree. Returned
list can be limited by a wildcard, and feature type.
"""
preexisting_wks = arcpy.env.workspace
arcpy.env.workspace = workspace
try:
for root, dirs, files in os.walk(workspace):
arcpy.env.workspace = root
for fc in arcpy.ListFeatureClasses(wild_card, feature_type):
Dict[workspace].append(arcpy.Describe(fc).catalogPath)
# Pick up workspace types that don't have a folder
# structure (coverages, file geodatabase do)
subFolders = set(arcpy.ListWorkspaces()) - \
set(arcpy.ListWorkspaces('', 'FILEGDB')) -\
set(arcpy.ListWorkspaces('', 'COVERAGE'))
for subFolder in subFolders:
arcpy.env.workspace = os.path.join(root, workspace)
for fc in arcpy.ListFeatureClasses(wild_card,feature_type):
Dict[workspace].append(arcpy.Describe(fc).catalogPath)
for dataset in arcpy.ListDatasets('', 'FEATURE'):
for fc in arcpy.ListFeatureClasses(wild_card,feature_type,dataset):
Dict[workspace].append(arcpy.Describe(fc).catalogPath)
if len(Dict[workspace]) > 0:
arcpy.Merge_management(Dict[workspace], os.path.join(output_folder,folderName+"_Merge.shp"))
print (folderName+"_Merge.shp" + " created")
except Exception as err:
raise err
finally:
arcpy.env.workspace = preexisting_wks
for folder in allFolders:
folderName = os.path.basename(folder).split(".")[0]
print folderName
Dict[folder]=[]
recursive_list_fcs(folder,wild_card = None, feature_type = "Point")
... View more
11-02-2015
09:39 AM
|
1
|
0
|
5280
|
|
POST
|
Is it a feature class in a geodatabase? Have you tried exporting to shapefile and editing or vice versa if it is a shapefile now? Also, I'm sure you may have already checked the different threads, but here is a thread that has a lot of workarounds that people have used.
... View more
10-29-2015
11:49 AM
|
1
|
0
|
724
|
|
POST
|
Then mark Jake Skinner's reply as the answer for sure. Just use spatial join with any of the optional parameters: import arcpy
arcpy.SpatialJoin_analysis (pointFeatureClass, lineFeatureClass, outputFeatureClass,"JOIN_ONE_TO_MANY", "KEEP_ALL")
... View more
10-29-2015
04:05 AM
|
0
|
0
|
1996
|
|
POST
|
Could you maybe elaborate on what you are trying to do? What is touching the point feature? What is the Point Feature ID that you are trying to update? Do you have a completed example in an attribute table that you could share with us?
... View more
10-28-2015
05:43 AM
|
0
|
4
|
1996
|
|
POST
|
Dan, just out of curiosity, did you try a double except statement with the first except block invoking a specific error set up similar to Gerry's except arcpy.ExecuteError: ?
... View more
10-26-2015
08:55 AM
|
0
|
1
|
2167
|
|
POST
|
Yes you are correct. I should have referenced the layer object. Did you try this yet: lyr = arcpy.mapping.Layer("in_memory\\tempFC") arcpy.mapping.AddLayer(mxd.activeDataFrame, lyr,"TOP")
... View more
10-26-2015
08:50 AM
|
1
|
1
|
3382
|
|
POST
|
Oh wait I didn't notice this before, but in addition to changing to a data frame object you also need to generate a mapping layer object to add to your TOC first: lyr = arcpy.mapping.Layer(tempFC) arcpy.mapping.AddLayer(mxd.activeDataFrame, lyr ,"TOP") Hopefully that will solve the issue.
... View more
10-26-2015
08:42 AM
|
0
|
3
|
1215
|
|
POST
|
Gerry what is the error message giving you exactly?
... View more
10-26-2015
08:39 AM
|
0
|
1
|
1215
|
|
POST
|
Python 2.7. It looks like that functionality is either redundant or did not follow over to 3.4. That's too bad.
... View more
10-26-2015
08:38 AM
|
0
|
0
|
2168
|
|
POST
|
You can have multiple except lines within a single try statement. That should not effect the code.
... View more
10-26-2015
08:19 AM
|
1
|
6
|
2168
|
|
POST
|
The Add Layer function looks for a data frame object not a data frame name. You should be able to just change your code to: arcpy.mapping.AddLayer(mxd.activeDataFrame, tempFC,"TOP") However, sometimes you need to explicitly set the layer to a full path like so: arcpy.mapping.AddLayer(mxd.activeDataFrame, "in_memory\\tempFC","TOP")
... View more
10-26-2015
08:17 AM
|
1
|
7
|
2168
|
|
POST
|
You got it. You can set the output parameter to be a Feature Layer and then direction to Output like so.
... View more
10-19-2015
12:35 PM
|
1
|
0
|
856
|
|
POST
|
Matthew, the GetParameterAsText is for setting parameters for a script tool. In my code there are two parameters that the script tool would look for then. An Input Layer and an Output Layer. Also I need to edit the code because the first input should be arcpy.GetParameterAsText(0). If you want to test the code outside of a python script tool you would set the 'lyr' to a full path to a shapefile or feature class. Such as: lyr = "C:\Test.shp"
... View more
10-19-2015
12:20 PM
|
1
|
2
|
856
|
|
POST
|
Python Add-Ins are definitely handy if you can get the coding to work. Whether you go with an add-in or just a standard script tool you'll want to set it up with a selection check like so: import arcpy
feature = arcpy.GetParameterAsText(0)
outputFeature = arcpy.GetParameterAsText(1)
selectionCheck = arcpy.Describe(feature).FIDSet
if not selectionCheck:
arcpy.AddError("\nYou must have a selection.\n")
else:
arcpy.CopyFeatures_management(feature, outputFeature)
... View more
10-19-2015
11:48 AM
|
0
|
3
|
2480
|
|
POST
|
Is there any reason you wouldn't just use Copy Features ArcGIS Help (10.2, 10.2.1, and 10.2.2) ? I'm just trying to figure out what the purpose of creating a script tool would be when there are multiple standard ways to do an export operation within ArcMap? I suppose having a python add-in on mouse click or selection would be the most user friendly way to go about it. Is this for users who are not familiar with ArcMap?
... View more
10-19-2015
11:32 AM
|
0
|
1
|
2480
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-26-2016 10:40 AM | |
| 1 | 10-05-2015 09:10 AM | |
| 1 | 01-19-2016 06:01 AM | |
| 1 | 01-06-2016 05:27 AM | |
| 1 | 12-09-2015 05:59 AM |
| Online Status |
Offline
|
| Date Last Visited |
05-01-2024
04:58 PM
|