I'm having some trouble connecting ideas on how to solve a problem. What I have is a shapefile from which I have to extract from one field, which contains 3 types of attributes (BS, RS, BRN). For each of those attributes, I've created a geodatabase and separate feature classes using another script.
I short, attributes have to go to their specific designation e.g. BS values go to feature BS, RS values etc.
My first guess is that I have to use Cursors to do it, but in this case I have to use both Search and Insert and how would I do that?
Would it make sense a start such as this?
import arcpy shape = "D:/M1 Geomatique/Programmation II/Dossier/ZONE_INONDATION_SYNTHESE_67.shp" gdb = "D:/M1 Geomatique/Programmation II/Dossier/inondation.gdb" field = "CODE_DEGRE" entite1 = "rs" entite2 = "bs" entite3 = "brn" rows = arcpy.InsertCursor(gdb) cursor = arcpy.SearchCursor(shape)
Perform a loop start with a SearchCursor followed by an InsertCursor could be a solution ? :
e.g.
with arcpy.da.SearchCursor(sourceFC,fieldnames) as sCur: with arcpy.da.InsertCursor(targetFC,fieldnames) as iCur:
Above is just an example I've picked up on stackexchange
How would you advise me to tackle this problem?
Solved! Go to Solution.
Make Feature Layer tool reference - Use the Where Clause parameter to restrict the features you want exported to the various layers.
From what you said, I believe you are overthinking this too much. You have a shapefile with a certain field in it with 3 different values. You want to make a new feature class for each based on the field value, either "rs", "bs" or "brn". Why not do a select by attribute for each one of those values, then make a feature layer then convert the feature layer to a feature class?
Or you could make a feature layer with a definition query FIELD1 = 'BS' etc. and export those features to a separate feature class.
Hey Ian,
Ian Murray wrote:
From what you said, I believe you are overthinking this too much. You have a shapefile with a certain field in it with 3 different values. You want to make a new feature class for each based on the field value, either "rs", "bs" or "brn". Why not do a select by attribute for each one of those values, then make a feature layer then convert the feature layer to a feature class?
Indeed, I was overthinking it. There goes my tendency of forgetting that ArcPy module already has plenty of functions and classes to relieve from making countless of procedures, loops, classes all by yourself.
Eventually, I solved the problem last evening by using MakeFeatureLayer tool, SelectLayerByAttribute and CopyFeatures, and it worked perfectly for all three of them. Everything got automatized in a single script, including the creation of a geodatabase to which these new features will go to.
Anyhow, thank you for taking your time.
Make Feature Layer tool reference - Use the Where Clause parameter to restrict the features you want exported to the various layers.
Actually, this is one of the tools which I had used to solve the problem.
Thank you for taking part in this.