<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Does CreateFeatureclass_management preserve field order? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166250#M12803</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;EDIT: My question about order preservation still stands, but my root needs are better addressed on my follow up question here: (Is there a token for everything EXCEPT SHAPE@): &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/86790-Is-there-a-token-for-everything-EXCEPT-SHAPE?p=306729#post306729" rel="nofollow" target="_blank"&gt;http://forums.arcgis.com/threads/86790-Is-there-a-token-for-everything-EXCEPT-SHAPE?p=306729#post306729&lt;/A&gt;&lt;SPAN&gt;.&amp;nbsp; Creating my own "complete" field list proved easier than I was imagining, and was solved by a function provided by Caleb1987 on the above link.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Original question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The CreateFeatureclass_management help page describes the Template parameter as:&amp;nbsp; &lt;/SPAN&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The feature class used as a template to define the attribute schema of the feature class.&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;Does this include the field order?&amp;nbsp; I ask because the help page for arcpy.da.insertcursor says: &lt;/SPAN&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Use an asterisk (*) instead of a list of fields if you want to access all fields from the input table [...]. However, for faster performance and reliable field order, &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In other words, if I use a search cursor with "*" for fields then can I directly assign that tuple to my new FC?&amp;nbsp; i.e. is the following valid?&amp;nbsp; Will the field order for the row tuple be preserved between the template and new feature classes (excepting the caveats in the help pages regarding blob and raster types)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.CreateFeatureclass_management( newFCpath, newFCname, "POINT", templateFC, "DISABLED", "DISABLED", templateFC )&amp;nbsp; newRows&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = arcpy.da.InsertCursor(newFC,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "*") templateRows = arcpy.da.SearchCursor(templateFC, "*")&amp;nbsp; for row in templateRows: &amp;nbsp;&amp;nbsp;&amp;nbsp; newRows.insertRow( row )&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS: I just thought of an additional caveat when using feature classes with different geometries, but I've formed it as a separate question here (Is there a token for everything EXCEPT SHAPE@): &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/86790-Is-there-a-token-for-everything-EXCEPT-SHAPE?p=306729#post306729" rel="nofollow" target="_blank"&gt;http://forums.arcgis.com/threads/86790-Is-there-a-token-for-everything-EXCEPT-SHAPE?p=306729#post306729&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PPS: Based on comments from Caleb1987 on my other post I realize the code above will not work because the OID will be a part of the tuple from the search cursor, and I can't assign the OID to the new feature.&amp;nbsp; The question about field order still stands though.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Jun 2013 13:22:36 GMT</pubDate>
    <dc:creator>StormwaterWater_Resources</dc:creator>
    <dc:date>2013-06-17T13:22:36Z</dc:date>
    <item>
      <title>Does CreateFeatureclass_management preserve field order?</title>
      <link>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166250#M12803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;EDIT: My question about order preservation still stands, but my root needs are better addressed on my follow up question here: (Is there a token for everything EXCEPT SHAPE@): &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/86790-Is-there-a-token-for-everything-EXCEPT-SHAPE?p=306729#post306729" rel="nofollow" target="_blank"&gt;http://forums.arcgis.com/threads/86790-Is-there-a-token-for-everything-EXCEPT-SHAPE?p=306729#post306729&lt;/A&gt;&lt;SPAN&gt;.&amp;nbsp; Creating my own "complete" field list proved easier than I was imagining, and was solved by a function provided by Caleb1987 on the above link.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Original question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The CreateFeatureclass_management help page describes the Template parameter as:&amp;nbsp; &lt;/SPAN&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The feature class used as a template to define the attribute schema of the feature class.&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;Does this include the field order?&amp;nbsp; I ask because the help page for arcpy.da.insertcursor says: &lt;/SPAN&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Use an asterisk (*) instead of a list of fields if you want to access all fields from the input table [...]. However, for faster performance and reliable field order, &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In other words, if I use a search cursor with "*" for fields then can I directly assign that tuple to my new FC?&amp;nbsp; i.e. is the following valid?&amp;nbsp; Will the field order for the row tuple be preserved between the template and new feature classes (excepting the caveats in the help pages regarding blob and raster types)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.CreateFeatureclass_management( newFCpath, newFCname, "POINT", templateFC, "DISABLED", "DISABLED", templateFC )&amp;nbsp; newRows&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = arcpy.da.InsertCursor(newFC,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "*") templateRows = arcpy.da.SearchCursor(templateFC, "*")&amp;nbsp; for row in templateRows: &amp;nbsp;&amp;nbsp;&amp;nbsp; newRows.insertRow( row )&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS: I just thought of an additional caveat when using feature classes with different geometries, but I've formed it as a separate question here (Is there a token for everything EXCEPT SHAPE@): &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/86790-Is-there-a-token-for-everything-EXCEPT-SHAPE?p=306729#post306729" rel="nofollow" target="_blank"&gt;http://forums.arcgis.com/threads/86790-Is-there-a-token-for-everything-EXCEPT-SHAPE?p=306729#post306729&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PPS: Based on comments from Caleb1987 on my other post I realize the code above will not work because the OID will be a part of the tuple from the search cursor, and I can't assign the OID to the new feature.&amp;nbsp; The question about field order still stands though.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Jun 2013 13:22:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166250#M12803</guid>
      <dc:creator>StormwaterWater_Resources</dc:creator>
      <dc:date>2013-06-17T13:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Does CreateFeatureclass_management preserve field order?</title>
      <link>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166251#M12804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm still curious if these two cursors will return the same fields in the same order:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.CreateFeatureclass_management( newFCpath, newFCname, "POINT", templateFC, "DISABLED", "DISABLED", templateFC )

newRows&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = arcpy.da.InsertCursor(newFC,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "*")
templateRows = arcpy.da.SearchCursor(templateFC, "*")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However I realize my comments below are not fully correct.&amp;nbsp; The geometry will copy because "*" returns only the XY of the centroid, not the full geometry.&amp;nbsp; The token SHAPE@ returns a geometry object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Additionally, after looking through the variables while debugging in PyScripter I realized that using the "*" does not return field names, so my question above should really be a special case of the more general: how do you determine what is what when using "*" for fields?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:40:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166251#M12804</guid>
      <dc:creator>StormwaterWater_Resources</dc:creator>
      <dc:date>2021-12-11T08:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Does CreateFeatureclass_management preserve field order?</title>
      <link>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166252#M12805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your cursor has a field property that you can query to get a tuple of field names in the index order they are in.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Eg&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;templateRows.fields&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit: To bridge the gap that remains you can just make a dictionary of index/field name values to reference the name instead of the index.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;for index, field in enumerate(templateRows.fields): &amp;nbsp;&amp;nbsp;&amp;nbsp; d[field] = index&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So you can do something like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;for row in templateRows: &amp;nbsp;&amp;nbsp;&amp;nbsp; val = row[d["field_name"]]&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dictionaries are pretty efficient so I don't imagine this would be a big hit on performance, thought I haven't done any benchmarks on it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jun 2013 13:48:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166252#M12805</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-06-18T13:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Does CreateFeatureclass_management preserve field order?</title>
      <link>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166253#M12806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;templateRows.fields&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sure enough.&amp;nbsp; There it is staring me in the face from the help we page.&amp;nbsp; I guess I looked at the parameters, and then skipped down to the examples jumping right over that messy stuff in between.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I plussed and checked your reply because, while it does not directly answer the *original* question, it pretty much renders it moot, and you've directly answered the more general follow-up question.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;To bridge the gap that remains you can just make a dictionary of index/field name values to reference the name instead of the index.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for index, field in enumerate(templateRows.fields):
&amp;nbsp;&amp;nbsp;&amp;nbsp; d[field] = index&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;So you can do something like this.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for row in templateRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; val = row[d["field_name"]]&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've used dictionaries extensively in Perl (where they're called hashes), even for exactly this purpose, but hadn't yet thought to use them in Python.&amp;nbsp; That is an excellent use.&amp;nbsp; I hate using just numbers as indexes.&amp;nbsp; I'll gladly trade the extra code for the clarity of what index you're accessing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:40:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166253#M12806</guid>
      <dc:creator>StormwaterWater_Resources</dc:creator>
      <dc:date>2021-12-11T08:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Does CreateFeatureclass_management preserve field order?</title>
      <link>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166254#M12807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To your original question, the tool 'should' preserve field order. With the caveat the system fields usually rearrange themselves.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Eg OID, Shape, Your_Fields, Shape_Length/Area&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also here are some of the quick trials I ran to show the difference between straight index referencing and dict field name referencing and the code used to generate them below. Was going through ~900k rows in a table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;index time: 19.5900778076&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;index time: 19.2306036588&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;index time: 19.4666773613&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;index time: 19.395765612&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;index time: 19.5033476872&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;index time: 19.3282738665&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;index time: 19.2130868052&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;index time: 19.0405310563&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;index time: 19.115207967&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;index time: 19.1235100947&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict time: 20.4310177626&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict time: 20.4020019139&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict time: 20.3490997958&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict time: 20.4130341569&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict time: 20.2006479064&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict time: 20.3282768531&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict time: 20.168064434&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict time: 20.0710841148&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict time: 20.1822551461&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict time: 20.4257584827&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main_index():
&amp;nbsp;&amp;nbsp;&amp;nbsp; curs = arcpy.da.SearchCursor(table, '*')
&amp;nbsp;&amp;nbsp;&amp;nbsp; t0 = _timer()
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val1 = row[6]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val2 = row[7]
&amp;nbsp;&amp;nbsp;&amp;nbsp; t1 = _timer() - t0
&amp;nbsp;&amp;nbsp;&amp;nbsp; index_times.append(t1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print('index time: {0}'.format(t1))

def main_dict():
&amp;nbsp;&amp;nbsp;&amp;nbsp; curs = arcpy.da.SearchCursor(table, '*')
&amp;nbsp;&amp;nbsp;&amp;nbsp; t0 = _timer()
&amp;nbsp;&amp;nbsp;&amp;nbsp; d = {}
&amp;nbsp;&amp;nbsp;&amp;nbsp; for index, field in enumerate(curs.fields):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d[field] = index
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val1 = row[d['POLY_NUM']]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val2 = row[d['TYPE']]
&amp;nbsp;&amp;nbsp;&amp;nbsp; t1 = _timer() - t0
&amp;nbsp;&amp;nbsp;&amp;nbsp; dict_times.append(t1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print('dict time: {0}'.format(t1))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:40:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/does-createfeatureclass-management-preserve-field/m-p/166254#M12807</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T08:40:23Z</dc:date>
    </item>
  </channel>
</rss>

