Hi Dear Friends,
How to split the data drawing number wise for all features from mdb or gdb file.
I have 8 types of drawing numbers available in data I want to split each drawing number separate data mdb format or gdb format file.
Thanks
Santhosh
Since you are using 10.1, I experimented with SelectLayerByAttributes. I found it easiest to code to work with one geodatabase (the one in your zip file). I first ran a script to get a list of the unique attributes used in the DRAWING_REFERENCE fields of all the features in the gdb. Since the drawing reference is rather long, I paired it with a shorter substring. This is what the gdb looks like in catalog:
Each feature is appended with the short substring; in this case, GF is highlighted. Here's the code:
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> os gdb <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Path\to\COBW_Firealarm.gdb'</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> gdb <SPAN class="comment token"># needed for ListDatasets</SPAN> fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'DRAWING_REFERENCE'</SPAN><SPAN class="punctuation token">]</SPAN> draw_ref <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="comment token"># unique values in DRAWING_REFERENCE fields, name append value</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="string token">'111-111-AP'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'AP'</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="string token">'C0500-GS-0117-04-EL-FA-A0-01-001-001'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'01'</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="string token">'C0500-GS-0117-04-EL-FA-A0-02-001-001'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'02'</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="string token">'C0500-GS-0117-01-EL-FA-A0-03-001-001'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'03'</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="string token">'C0500-GS-0117-04-EL-FA-A0-04-001-001'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'04'</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="string token">'C0500-GS-0117-04-EL-FA-A0-05-001-001'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'05'</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="string token">'C0500-GS-0117-04-EL-FA-A0-06-001-001'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'06'</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="string token">'C0500-GS-0117-01-EL-FA-A0-B1-001-001'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'B1'</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="string token">'C0500-GS-0117-04-EL-FA-A0-B2-001-001'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'B2'</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="string token">'C0500-GS-0117-04-EL-FA-A0-GF-001-001'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'GF'</SPAN> <SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># name append keeps feature name from becoming too long</SPAN> <SPAN class="keyword token">for</SPAN> fds <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListDatasets<SPAN class="punctuation token">(</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Feature'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\nProcessing {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fds<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN>fds<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\t{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># use fc for name of target geodatabase</SPAN> in_fc <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>gdb<SPAN class="punctuation token">,</SPAN>fds<SPAN class="punctuation token">,</SPAN>fc<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Exists<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'temp_layer'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'temp_layer'</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>in_fc<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'temp_layer'</SPAN><SPAN class="punctuation token">)</SPAN> ref_num <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="keyword token">for</SPAN> dr <SPAN class="keyword token">in</SPAN> draw_ref<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># loop through drawing reference list</SPAN> <SPAN class="comment token"># dr[0] = DRAWING_REFERENCE field value</SPAN> <SPAN class="comment token"># dr[1] = a substring of DRAWING_REFERENCE used in naming new feature class</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'temp_layer'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'NEW_SELECTION'</SPAN><SPAN class="punctuation token">,</SPAN> where_clause <SPAN class="operator token">=</SPAN> <SPAN class="string token">"DRAWING_REFERENCE = '{}'"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>dr<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> count <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'temp_layer'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>getOutput<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> count <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> ref_num <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN> new_fc <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>fds<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"{}_{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN>dr<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\t\t{} -- count: {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>new_fc<SPAN class="punctuation token">,</SPAN>count<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># write the selected features to a new featureclass</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CopyFeatures_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'temp_layer'</SPAN><SPAN class="punctuation token">,</SPAN> new_fc<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\t\t{} total new features"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>ref_num<SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'temp_layer'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\nDone."</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
For the next steps, you can use a script to loop through the draw_ref list, making a copy the first gdb, deleting the features that don't match the current value in the draw_ref list, and repeat until each drawing reference has its own gdb.
Hope this helps.
sounds like ...
Split By Attributes—Help | ArcGIS Desktop
Dear Dan Patterson,
yes It is working as a shape file but i nedd direct feature class it's possible or not if it's possible plz help me.
make the destination output a geodatabase, or easier still, use Copy Features to bring the shapefile into a gdb, then do the split
When you say 'drawing number', are you referring to the DRAWING_REFERENCE field in your data? If so, I'm counting 10 different values.
111-111-AP C0500-GS-0117-01-EL-FA-A0-03-001-001 C0500-GS-0117-01-EL-FA-A0-B1-001-001 C0500-GS-0117-04-EL-FA-A0-01-001-001 C0500-GS-0117-04-EL-FA-A0-02-001-001 C0500-GS-0117-04-EL-FA-A0-04-001-001 C0500-GS-0117-04-EL-FA-A0-05-001-001 C0500-GS-0117-04-EL-FA-A0-06-001-001 C0500-GS-0117-04-EL-FA-A0-B2-001-001 C0500-GS-0117-04-EL-FA-A0-GF-001-001 <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
If this is not what you mean, could you explain 'drawing number'.
Dear Randy Burton,
In this gdb have DRAWING_REFERENCE field in that different drawing numbers available in gdb.
for example:
C0500-GS-0117-01-EL-FA-A0-03-001-001 this is the drawing number.
And your version of ArcGIS? 10.5 or 10.6 or Pro ? Looks like Split By Attributes requires one of these versions.
The following code will split your features based on DRAWING_REFERENCE and place them in a geodatabase named with the feature class. From here you should be able to copy them into the desired structure with additional scripting. It does appear that domains and subtypes are preserved. I could not get SplitAttributes to create the features inside a dataset, but it might output to shape files.
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> os gdb <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\path\to\folder\COBW_Firealarm\COBW_Firealarm.gdb'</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> gdb out_folder <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\path\to\folder\COBW_Firealarm'</SPAN> <SPAN class="comment token"># geodatabases go here</SPAN> fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'DRAWING_REFERENCE'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> fds <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListDatasets<SPAN class="punctuation token">(</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Feature'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Processing {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fds<SPAN class="punctuation token">)</SPAN> sr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>fds<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>SpatialReference <SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN>fds<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\t{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># use fc for name of target geodatabase</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CreateFileGDB_management<SPAN class="punctuation token">(</SPAN>out_folder<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'{}.gdb'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> in_fc <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>gdb<SPAN class="punctuation token">,</SPAN>fds<SPAN class="punctuation token">,</SPAN>fc<SPAN class="punctuation token">)</SPAN> target <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>out_folder<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'{}.gdb'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># print in_fc</SPAN> <SPAN class="comment token"># print target</SPAN> <SPAN class="comment token"># save split in file geodatabase with name of original feature class</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SplitByAttributes_analysis<SPAN class="punctuation token">(</SPAN>in_fc<SPAN class="punctuation token">,</SPAN> target<SPAN class="punctuation token">,</SPAN> fields<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Here's what the output looked like:
I am getting error can you give me the solution for this error. I am using ArcGIS 10.1
Attached below image for your reference.
Error Below Code
check the folder in the error message... the geodatabase already exists and you can't overwrite it.
I am assuming that the picture in my last post is generally what you are looking for.
As Dan Patterson mentioned, since the database exists you can't overwrite it. You can delete it with code or just use it. A line of code could be added to check for the existence of the database.
As seen in your attached jpeg, you are getting a second error:
object has no attribute 'SplitByAttributes_analysis'
Split By Attributes was added at version 10.5 and Pro. Since you are at 10.1, we will need a different solution. I would suggest looping through your datasets and features and using Select Layer By Attribute with a where clause, something like:
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'FA_Box'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'NEW_SELECTION'</SPAN><SPAN class="punctuation token">,</SPAN> where_clause <SPAN class="operator token">=</SPAN> <SPAN class="string token">"DRAWING_REFERENCE = 'C0500-GS-0117-01-EL-FA-A0-03-001-001'"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
If records are selected, then copy them to the appropriate database. Hope this helps.
10.1?! missed that
https://www.arcgis.com/home/item.html?id=15ca63aebb4647a4b07bc94f3d051da5
the original split by attribute... can't remember if it works on that old a version.
but it has the coolest page icon, if I may say so
I really appreciate you for helpling thank you somuch.
santhosh
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.