I want to write a scrpit that automatize the process of clip and project (in one GCS) to many .shp in folders and subfolders (row downloaded data), with 2 different GCS (CH1903+ or Lambert93).
For that, my script creates a new gdb with 2 feature_class: "Row" and "Clip_Project" then, I'm trying to create a loop to iterate all the feature class in my folders and subfolders.
I understood that the equivalent of "iterate feature class" in python is to define a list with
fcList=arcpy.ListFeatureClasses()
and then you create a loop: for fc in fcList
and add your function
The problem is that this function creates only a list of the .shp in the defined workspace . Since all my raw datas are classified in different subfolders, I want to find a way to get all .shp in all subfolders.
For now, my script looks like this:
# Import arcpy module
import arcpy, sys, string, os
# allow overwrite
arcpy.env.overwriteOutput = True
# Set Geoprocessing environments
workspace=arcpy.env.workspace = "C:\\PROG"
# Local variables:
Test_classement = "C:\\PROG\\MB_PROG\\Test_classement"
Coordinate_System = "PROJCS['RGF_1993_Lambert_93',GEOGCS['GCS_RGF_1993',DATUM['D_RGF_1993',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',700000.0],PARAMETER['False_Northing',6600000.0],PARAMETER['Central_Meridian',3.0],PARAMETER['Standard_Parallel_1',44.0],PARAMETER['Standard_Parallel_2',49.0],PARAMETER['Latitude_Of_Origin',46.5],UNIT['Meter',1.0]];-35597500 -23641900 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision"
Output_Coordinate_System_LV95 = "PROJCS['CH1903+_LV95',GEOGCS['GCS_CH1903+',DATUM['D_CH1903+',SPHEROID['Bessel_1841',6377397.155,299.1528128]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Hotine_Oblique_Mercator_Azimuth_Center'],PARAMETER['false_easting',2600000.0],PARAMETER['false_northing',1200000.0],PARAMETER['scale_factor',1.0],PARAMETER['azimuth',90.0],PARAMETER['longitude_of_center',7.439583333333333],PARAMETER['latitude_of_center',46.95240555555556],UNIT['Meter',1.0]]"
Brute_gdb = "C:\\PROG\\MB_PROG\\Test_classement\\Brute.gdb"
Brute = "C:\\PROG\\MB_PROG\\Test_classement\\Brute.gdb\\Brute"
ClipLV95 = "C:\\PROG\\MB_PROG\\Test_classement\\Brute.gdb\\ClipLV95"
# Process: Create File GDB
arcpy.CreateFileGDB_management(Test_classement, "Brute", "CURRENT")
# Process: Create Feature Dataset
arcpy.CreateFeatureDataset_management(Brute_gdb, "Brute", Coordinate_System)
# Process: Create Feature Dataset (2)
arcpy.CreateFeatureDataset_management(Brute_gdb, "ClipLV95", Output_Coordinate_System_LV95)
#Loop->iterator
fcs = []
walk = arcpy.da.Walk(workspace,datatype="FeatureClass",type="All")
for dirpath, dirnames, filenames in walk:
for filename in filenames:
fcs.append(os.path.join(dirpath, filename))
for fc in fcs:
root, ext = os.path.splitext(fc)
arcpy.FeatureClassToFeatureClass_conversion(fc , Brute, root + "_brute" + ext, "")
Execpt for typing and indentation errors, my loop didnt work to rename new feature classes because the root was all the path.
I fixed the last part like this:
workspace_brute=arcpy.env.workspace="C:\\PROG\\MB_PROG\\DONNEES\\"
fcs = []
walk = arcpy.da.Walk(workspace_brute,
datatype="FeatureClass",
type="All")
for dirpath, dirnames, filenames in walk:
for filename in filenames:
fcs.append(os.path.join(dirpath, filename))
for fc in fcs:
name=os.path.splitext(filename)[0] # Here we remove the extension from filename
arcpy.FeatureClassToFeatureClass_conversion(fc, Brute_fd, name + "_brute")
os.path
has no functionsplittext
because you've got an extra "t" in there. The function is calledsplitext
splittext
doesn't match your codesplitext
for filename in filenames
.