<?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 Re: Arcpy drop fields without generating feature class or shape file? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223579#M17278</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I won't bother linking you to a FieldInfo help page, then &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&amp;nbsp;We use FieldInfo as part of a process for exporting shapefiles with a subset of fields, first making the feature layer and then copying it out to a shapefile (after a couple other layer-based manipulations that aren't relevant here).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, what may work for you is creating an intermediate feature class (in_memory) from the feature layer once you have hidden the fields you don't want. Then, turn that feature class back into a feature layer. The hidden fields will go away when you make it into a "permanent" feature class, and then&amp;nbsp;should not exist once it's converted back to a feature layer. (I'll admit that I have not tested this, AND it's a sort of funky workaround... but maybe worth a shot?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So ......&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;FeatureClassToFeatureClass_conversion&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"temp_layer"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"in_memory"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"temp_fc"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"in_memory\\temp_fc"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"final_layer"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 10:53:07 GMT</pubDate>
    <dc:creator>EricaPfister</dc:creator>
    <dc:date>2021-12-11T10:53:07Z</dc:date>
    <item>
      <title>Arcpy drop fields without generating feature class or shape file?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223575#M17274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Creating a pretty simple GP service that returns select records from a large dataset.&amp;nbsp; Only need about 8 of the 25 or so columns from the data in the result.&lt;/P&gt;&lt;P&gt;All of the intermediate datasets, and output dataset, are just in memory feature layers.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to find a way to have this final output feature layer only include the 8 necessary columns.&amp;nbsp; I've tried setting the unneeded fields to hidden, which is ok up until I look at the json return from the GP service - the hidden fields are there.&amp;nbsp; Delete fields only works on feature classes/shape files etc - this kind of data is not needed for our purposes and requires extra code to ensure they are truncated/appended at each run.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way using MakeFeatureLayer_management (or anything else that can be in_memory) to simply drop fields, or explicitly say what fields to include?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jan 2018 22:57:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223575#M17274</guid>
      <dc:creator>AllenScully</dc:creator>
      <dc:date>2018-01-17T22:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy drop fields without generating feature class or shape file?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223576#M17275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As you know you cant delete hide the fields, since sql queries on limit the rows exposed not the columns.&lt;/P&gt;&lt;P&gt;In ArcGIS Pro, the process of deleting fields is now greatly simplified since you can batch delete just by providing the field names and without having to cycle through a list&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://pro.arcgis.com/en/pro-app/tool-reference/data-management/delete-field.htm"&gt;http://pro.arcgis.com/en/pro-app/tool-reference/data-management/delete-field.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The only other thing I can think of numpy/pandas solutions but it depends on the geometry type you need as to whether it would be speed enough and json output would take some work&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jan 2018 23:34:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223576#M17275</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-01-17T23:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy drop fields without generating feature class or shape file?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223577#M17276</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you using a FieldInfo object and it's still keeping the fields around in the&amp;nbsp;final JSON?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jan 2018 17:43:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223577#M17276</guid>
      <dc:creator>EricaPfister</dc:creator>
      <dc:date>2018-01-18T17:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy drop fields without generating feature class or shape file?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223578#M17277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Erica -&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, that's correct.&amp;nbsp; I have published the GP service from the python script where the MakeFeatureLayer_management&amp;nbsp;includes "Field_info=..." and lists all of the fields, including setting the unneeded ones to Hidden.&lt;/P&gt;&lt;P&gt;Looking at the rest URL, where it lists the fields, it appears to respect the 'Hidden' settings, displaying only those we need.&amp;nbsp; However on running the tool via REST, the output json returned includes all fields.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jan 2018 17:58:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223578#M17277</guid>
      <dc:creator>AllenScully</dc:creator>
      <dc:date>2018-01-18T17:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy drop fields without generating feature class or shape file?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223579#M17278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I won't bother linking you to a FieldInfo help page, then &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&amp;nbsp;We use FieldInfo as part of a process for exporting shapefiles with a subset of fields, first making the feature layer and then copying it out to a shapefile (after a couple other layer-based manipulations that aren't relevant here).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, what may work for you is creating an intermediate feature class (in_memory) from the feature layer once you have hidden the fields you don't want. Then, turn that feature class back into a feature layer. The hidden fields will go away when you make it into a "permanent" feature class, and then&amp;nbsp;should not exist once it's converted back to a feature layer. (I'll admit that I have not tested this, AND it's a sort of funky workaround... but maybe worth a shot?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So ......&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;FeatureClassToFeatureClass_conversion&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"temp_layer"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"in_memory"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"temp_fc"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"in_memory\\temp_fc"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"final_layer"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:53:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223579#M17278</guid>
      <dc:creator>EricaPfister</dc:creator>
      <dc:date>2021-12-11T10:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy drop fields without generating feature class or shape file?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223580#M17279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Erica -&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll give the in memory FC a shot.&amp;nbsp; Main issue is performance - since it's a GP service we're looking to maximize speed and keep things lightweight.&amp;nbsp; Will follow up with results.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jan 2018 18:57:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223580#M17279</guid>
      <dc:creator>AllenScully</dc:creator>
      <dc:date>2018-01-18T18:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy drop fields without generating feature class or shape file?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223581#M17280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Erica -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've implemented this in a draft GP service.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's super straightforward, and it works.&amp;nbsp; However there are a couple of things to report back -&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 - it does indeed add time to the GP tool returning results - went from 3.5 seconds to about 6 seconds in our case.&lt;/P&gt;&lt;P&gt;2 - in this case, I actually needed to use 2 FeatureClassToFeatureClass_conversion tools - the first allows you to delete fields from it.&amp;nbsp; However - when publishing the GP service with this as the output dataset, it still returns all of the fields, including those that were deleted.&amp;nbsp; Again, looking at the GP service REST end point, it does look correct - the deleted fields are not shown, but they are in the JSON results.&amp;nbsp; So, you actually need to create another in_memory feature class after dropping the fields - this one will be 'clean' and when used as the output of the GP tool only includes the desired fields.&lt;/P&gt;&lt;P&gt;3 - Even though the feature classes are in_memory, they are 'sticky' as far as holding on to data from a previous run of the tool.&amp;nbsp; So, for each in_memory feature class, I added:&lt;/P&gt;&lt;P&gt;if arcpy.exists(in_memory_fc):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Delete_management(in_memory_fc)&lt;/P&gt;&lt;P&gt;these are at the beginning of the script, to ensure the tool does not actually just return the same results from the last run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks -&amp;nbsp;&lt;/P&gt;&lt;P&gt;Allen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jan 2018 21:07:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223581#M17280</guid>
      <dc:creator>AllenScully</dc:creator>
      <dc:date>2018-01-22T21:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy drop fields without generating feature class or shape file?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223582#M17281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Update -&amp;nbsp;&lt;/P&gt;&lt;P&gt;While the tool worked fine in ArcMap, I had a hell of time getting the GP service to work correctly.&amp;nbsp; Ended up using CopyFeatures_management to create the desired in_memory feature classes instead of FeatureClasstoFeatureClass_management.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 21:47:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-drop-fields-without-generating-feature-class/m-p/223582#M17281</guid>
      <dc:creator>AllenScully</dc:creator>
      <dc:date>2018-01-25T21:47:19Z</dc:date>
    </item>
  </channel>
</rss>

