<?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: Working with in_memory in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634313#M49415</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;unfortunately the result of &lt;BR /&gt; always comes as "&amp;lt;Field object at 0x55c7f90[0x577c590]&amp;gt;" and I never get the field name.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry about that, fabl is right, you need to pull out that name attribute, his suggestion:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;str([field.name for field in arcpy.ListFields(inMemInt)])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;is right on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing that may be tripping you up is if you go through shapefile format at some point in your processing, Shape_Length is more than 10 characters, so it can get truncated to SHAPE_LENG.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Sep 2012 21:21:16 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2012-09-14T21:21:16Z</dc:date>
    <item>
      <title>Working with in_memory</title>
      <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634305#M49407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I try to work having my data in memory and I'm running in some problems.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What am I doing?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I set my workspace to my database and load two feature layer into memory using MakeFeatureLayer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Then I create a SearchCursor to iterate over one of the layers in memory and use the SearchCursor in a for-loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Within the for-loop I read the ID and the coordinates of the current point in question out and use SelectLayerByAttribute to select this point.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Based on the selection I buffer the point by 500 meters and intersect the resulting buffer with the second layer in memory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All this seems to work, but then my problem starts.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to create a field within the result of the intersection process. the result of the intersection is written as well into memory, using in_memory. But I can't get it to work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.AddField_management(inMemoryIntersect, "Traffic", "DOUBLE")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To overcome the problem I created the field in one of the input datasets. But how can I calculate fields of datasets that are loaded into memory, e.g. the result of the intersection? I would also like to know how I can get a list of field names of a dataset loaded into memory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anybody has a solution for this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Bests Thomas&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Sep 2012 10:16:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634305#M49407</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2012-09-12T10:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: Working with in_memory</title>
      <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634306#M49408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Thomas,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What is the error you are receiving when you try to add the field to the IN_MEMORY dataset?&amp;nbsp; I was able to get this to work with the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env

env.workspace = r"C:\temp\python\test.gdb"

fc = "Parcels"

arcpy.MakeFeatureLayer_management(fc, "IN_MEMORY\test")

arcpy.AddField_management("IN_MEMORY\test", "PIN", "DOUBLE")

lstFields = arcpy.ListFields("IN_MEMORY\test")
for field in lstFields:
&amp;nbsp;&amp;nbsp; print field.name&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:59:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634306#M49408</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-12T02:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Working with in_memory</title>
      <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634307#M49409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here is the code I'm using and I just figured out that the AddField function is working. So it must be the CalculateField function. I'm not sure how to address the fields stored within the dataset in memory. The error I'm getting is Error 999999: Error executing function. Failed to execute (CalculateField).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import csv, sys
import arcpy as gp
from arcpy import env

env.workspace = r"C:\\Users\\thob\\Projects\\Road_Length.gdb"
env.overwriteOutput = True

BSMB = gp.MakeFeatureLayer_management("\\BSMB\\pntBSMB", "BSMB")
ROADS = gp.MakeFeatureLayer_management("\\Background\\Local_network", "ROADS")
inMemBuf = "in_memory/Buffer"
inMemInt = "in_memory/Intersect"
inMemSum = "in_memory/Statistic"
print("All variables in memory")

lstCalcD = []
distance = "500 Meters"

rowsCohort = gp.SearchCursor(BSMB)

for Brow in rowsCohort:
&amp;nbsp;&amp;nbsp;&amp;nbsp; BpntID = int(Brow.getValue("OldID"))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print(BpntID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; strSearch = "\"OldID\" = %s" %str(BpntID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; BpntX = Brow.getValue("POINT_X")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print BpntX
&amp;nbsp;&amp;nbsp;&amp;nbsp; BpntY = Brow.getValue("POINT_Y")&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SelectLayerByAttribute_management(BSMB, "NEW_SELECTION", strSearch)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Buffer_analysis(BSMB, inMemBuf, distance)
&amp;nbsp;&amp;nbsp;&amp;nbsp; inF = [inMemBuf, ROADS]
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Intersect_analysis(inF, inMemInt)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.ListFields(inMemInt)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management(inMemInt, "Traffic", "[AGADT2005] * [Shape_Length]", "VB", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; statF = [["Traffic", "SUM"]]
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Statistics_analysis(inMemInt, inMemSum, statF, "ID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; lstB = [BpntID, BpntX, BpntY, inMemSum]
&amp;nbsp;&amp;nbsp;&amp;nbsp; print(lstB)
&amp;nbsp;&amp;nbsp;&amp;nbsp; lstCalcD.append(lstB)

csvfile = open(r"C:\\User\\thob\\Projects\\lstTraf_x_d.csv", 'wb')
csvFile = csv.writer(csvfile, dialect='excel', delimiter=',')
csvFile.writerow(['ID,X,Y,Traffic_Load'])
csvFile.writerows(lstCalcD)
csvfile.close()
gp.Delete_management("in_memory")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:59:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634307#M49409</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2021-12-12T02:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Working with in_memory</title>
      <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634308#M49410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The question is, how can I do calculations on data that are in memory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Bests Thomas&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Sep 2012 11:51:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634308#M49410</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2012-09-12T11:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Working with in_memory</title>
      <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634309#M49411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I typically setup my field calculations outside of the tool line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;calcExpression = "'" + siteName + "'"
arcpy.CalculateField_management(singleSurveyImageLocationsDD_FCIM,"SiteName",calcExpression,"PYTHON_9.3","#")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I took this straight out of a python script I had sitting around. I like the "PYTHON_9.3" syntax better since I am already more familiar with it than vb.&amp;nbsp; In this case I was calculating the field on a feature class in the 'in_memory' workspace. For me I set up suffixes that tell me about the object. So '_FCIM' is a Feature Class in the 'in_memory' workspace. I also use '_FCNO', feature class name only, '_FCFP', feature class full path, etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My workflow for writing calculation in python is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Figure Out the Field Calculation in an ArcMap Session, saving it as a Calc File.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Use the 'Calculate Field Tool' in ArcToolbox to test it out with the geoprocessor. Some translation between the Calc File and the tool may be necessary.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Copy the #2 as a Python Snippet into my Python Code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Figure out how to make the exact same string in my code as the calc string that I copied in #3.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Make sure it all works with writing out to a geodatabase. Then move it over into memory. Somethings don't work in the 'in_memory' workspace, for example you can't project into the 'in_memory' workspace.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:59:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634309#M49411</guid>
      <dc:creator>GeorgeNewbury</dc:creator>
      <dc:date>2021-12-12T02:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Working with in_memory</title>
      <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634310#M49412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;gp.CalculateField_management(inMemInt, "Traffic", "[AGADT2005] * [Shape_Length]", "VB", "")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This looks fine - so I would make sure that your fields are all there and named exactly as you expected them by inserting this line right before the CalculateField:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.AddMessage(str(arcpy.ListFields(inMemInt)))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Sep 2012 16:53:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634310#M49412</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-09-12T16:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Working with in_memory</title>
      <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634311#M49413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Curtis,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;unfortunately the result of &lt;/SPAN&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; &lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.AddMessage(str(arcpy.ListFields(inMemInt)))&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; always comes as "&amp;lt;Field object at 0x55c7f90[0x577c590]&amp;gt;" and I never get the field name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with the VB syntax nothing worked at all, so I switched to Python syntax and there the &lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!AGADT2005! * !Shape_Length!&lt;/PRE&gt;&lt;SPAN&gt; comes with &lt;/SPAN&gt;&lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;ERROR 000539: Invalid field Shape_Length&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;. So, I do not know if this field does not exist.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Can anybody help here to get the names of the fields back?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers Thomas&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Sep 2012 14:06:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634311#M49413</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2012-09-14T14:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Working with in_memory</title>
      <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634312#M49414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ListFields() returns a list of field-objects. You need the name-attribute:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.AddMessage(str([field.name for field in arcpy.ListFields(inMemInt)]))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try pprint:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import pprint&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;outstring = pprint.pformat([field.name for field in arcpy.ListFields(inMemInt)]) arcpy.AddMessage(outstring)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try (I did not test it):&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/de/arcgisdesktop/10.0/help/index.html#//00s500000033000000" rel="nofollow" target="_blank"&gt;http://help.arcgis.com/de/arcgisdesktop/10.0/help/index.html#//00s500000033000000&lt;/A&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;'"AGADT2005" * "Shape_Length"'&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Sep 2012 14:50:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634312#M49414</guid>
      <dc:creator>FabianBlau</dc:creator>
      <dc:date>2012-09-14T14:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Working with in_memory</title>
      <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634313#M49415</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;unfortunately the result of &lt;BR /&gt; always comes as "&amp;lt;Field object at 0x55c7f90[0x577c590]&amp;gt;" and I never get the field name.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry about that, fabl is right, you need to pull out that name attribute, his suggestion:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;str([field.name for field in arcpy.ListFields(inMemInt)])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;is right on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing that may be tripping you up is if you go through shapefile format at some point in your processing, Shape_Length is more than 10 characters, so it can get truncated to SHAPE_LENG.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Sep 2012 21:21:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634313#M49415</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-09-14T21:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Working with in_memory</title>
      <link>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634314#M49416</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;One thing that may be tripping you up is if you go through shapefile format at some point in your processing, Shape_Length is more than 10 characters, so it can get truncated to SHAPE_LENG.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Well, after checking the field names I had to realize that there is no field for the shape length. Hence, I create and calculate it on the fly. Doesn't make much of a diverence in time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you so much guys, you helped me quite a bit.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers Thomas&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Sep 2012 10:55:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-in-memory/m-p/634314#M49416</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2012-09-16T10:55:04Z</dc:date>
    </item>
  </channel>
</rss>

