# For each field in the object list, add the field name to the # name list. If the field is required, exclude it, to prevent errors exclude = ["UGISID", "LBL_X", "LBL_Y"] for field in fieldObjList: if not field.required: if not field.name in exclude: fieldNameList.append(field.name)
inputShapeFile = "C:/Temp/yourInput.shp" outputLocation = "C:/Temp" outputShapeFileName = "yourExport.shp" # List of the fields to keep. outputFields = ["UGISID", "LBL_X", "LBL_Y"] fieldMappings = arcpy.FieldMappings() # create the field mappings from the outputFields list. # only fields in the list will be included in the exported shape file. for field in outputFields: fieldMap = arcpy.FieldMap() fieldMap.addInputField(inputShapeFile, field) fieldMappings.addFieldMap(fieldMap) # Use FeatureClassToFeatureClass and apply the fieldMappings arcpy.FeatureClassToFeatureClass_conversion(inputShapeFile, outputLocation, outputShapeFileName, "", fieldMappings, "")
Hi Mark,
Thanks for the above.
Couple of questions (assume I know only a little Python, thanks)
Thanks,
Doug
There are so many different ways of tackling this issue, i.e., the "SQL LIKE with Python strings," that I encourage you to hit up Google or some other search engine. The question you have isn't really an ArcPy question, it is a general Python question, that has lots of answers floating around the web.
Thanks Josh. And thanks for keeping an eye on old threads.
I agree on all points.
I'm in the "gathering information" step before writing any code. I will take a look at other sources.
I need to remove unneeded data from multiple shapefiles saved in a .gdb.
Since the data originates as .shp files, I thought it would be best to work with arcpy and tap the GIS community.
Cheers,
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.