<?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: CalculateGeometryAttributes produces None values in multiprocessing in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495381#M70871</link>
    <description>&lt;P&gt;Since this seems to be a bug as per &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;'s reply, you could try using an UpdateCursor to get the area for now:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import datetime

def process(fc):
        arcpy.env.workspace = "G:/usgrids2020/test1/"
        arcpy.env.overwriteOutput=True
        state = fc[34:-7]
        print(f"Processing for {state.upper()}")
        readTime = datetime.datetime.now()
        # arcpy.env.workspace = os.path.join(gdb_path, f"usa{state}.gdb")
        #Import the feature for boundary and water
        # fc = f"usa{state[3:5]}_joined"
        fcInMem = arcpy.management.CopyFeatures(fc, f"in_memory/usa{state}_fcInMem")
        water_fc = f"{fc[:-7]}_water_layer"
        waterInMem = arcpy.management.CopyFeatures(water_fc, f"in_memory/usa{state}_waterInMem")
        #Create the temporary id for joining fields later
        arcpy.AddField_management(fcInMem,'tempid','LONG')
        arcpy.CalculateField_management(fcInMem,"tempid",'!OBJECTID!','PYTHON')
        #Calculate the area(land+water) by GEODESIC method =&amp;gt; Kytt recommended
        arcpy.management.AddField(fcInMem, "GEODESIC_AREA", "FLOAT")
        with arcpy.da.UpdateCursor(fcInMem, ["SHAPE@AREA", "GEODESIC_AREA"]) as cursor:
            for row in cursor:
                row = dict(zip(cursor.fields, row))
                row['GEODESIC_AREA'] = row['SHAPE@AREA'] # This is in feature units, so you will likely need the conversion factor from arcpy.LinearUnitConversionFactor
                cursor.updateRow(row.values())
        #arcpy.management.CalculateGeometryAttributes(fcInMem, "GEODESIC_AREA AREA_GEODESIC", "", "SQUARE_METERS")&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 20 Jun 2024 14:45:27 GMT</pubDate>
    <dc:creator>HaydenWelch</dc:creator>
    <dc:date>2024-06-20T14:45:27Z</dc:date>
    <item>
      <title>CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1494707#M70850</link>
      <description>&lt;P&gt;I was trying to perform a geo analysis and the function CalculateGeometryAttributes produced None values when I wrapped the script in multiprocessing, but it worked correctly in a for loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def process(fc):
        arcpy.env.workspace = "G:/usgrids2020/test1/"
        arcpy.env.overwriteOutput=True
        state = fc[34:-7]
        print(f"Processing for {state.upper()}")
        readTime = datetime.datetime.now()
        # arcpy.env.workspace = os.path.join(gdb_path, f"usa{state}.gdb")
        #Import the feature for boundary and water
        # fc = f"usa{state[3:5]}_joined"
        fcInMem = arcpy.management.CopyFeatures(fc, f"in_memory/usa{state}_fcInMem")
        water_fc = f"{fc[:-7]}_water_layer"
        waterInMem = arcpy.management.CopyFeatures(water_fc, f"in_memory/usa{state}_waterInMem")
        #Create the temporary id for joining fields later
        arcpy.AddField_management(fcInMem,'tempid','LONG')
        arcpy.CalculateField_management(fcInMem,"tempid",'!OBJECTID!','PYTHON')
        #Calculate the area(land+water) by GEODESIC method =&amp;gt; Kytt recommended
        arcpy.management.AddField(fcInMem, "GEODESIC_AREA", "FLOAT")
        arcpy.management.CalculateGeometryAttributes(fcInMem, "GEODESIC_AREA AREA_GEODESIC", "", "SQUARE_METERS")        &lt;/LI-CODE&gt;&lt;P&gt;This is what it generated:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;(None, 'USA_100030117003015')
(None, 'USA_100030127001011')
(None, 'USA_100030151002006')
(None, 'USA_100030121001003')
(None, 'USA_100030112051009')
(None, 'USA_100030148102015')
(None, 'USA_100030112062022')
(None, 'USA_100030168063009')
(None, 'USA_100030166141010')
(None, 'USA_100030164041013')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 23:37:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1494707#M70850</guid>
      <dc:creator>HieuTran12</dc:creator>
      <dc:date>2024-06-18T23:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1494717#M70851</link>
      <description>&lt;P&gt;does the newer "memory" workspace behave differently than the "in_memory" workspace with multiprocessing?&lt;/P&gt;&lt;P&gt;I suspect a for loop would be better if using memory workspaces in any event&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 01:06:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1494717#M70851</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-06-19T01:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1494720#M70852</link>
      <description>&lt;P&gt;I tried without the "in_memory" as well but the result remains the same.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 01:22:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1494720#M70852</guid>
      <dc:creator>HieuTran12</dc:creator>
      <dc:date>2024-06-19T01:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1494930#M70856</link>
      <description>&lt;P&gt;Commented at &lt;SPAN&gt;&lt;A href="https://gis.stackexchange.com/questions/482764/arcpy-function-produced-none-values-in-multiprocessing" target="_blank" rel="noopener"&gt;python - ArcPy function produced None values in multiprocessing - GIS SE&lt;/A&gt;, it l&lt;SPAN class=""&gt;ooks to be a defect with CalculateGeometryAttributes. I was able to create a minimum reproducible example and have submitted to Esri Support to log a defect.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 13:55:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1494930#M70856</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2024-06-19T13:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495381#M70871</link>
      <description>&lt;P&gt;Since this seems to be a bug as per &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;'s reply, you could try using an UpdateCursor to get the area for now:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import datetime

def process(fc):
        arcpy.env.workspace = "G:/usgrids2020/test1/"
        arcpy.env.overwriteOutput=True
        state = fc[34:-7]
        print(f"Processing for {state.upper()}")
        readTime = datetime.datetime.now()
        # arcpy.env.workspace = os.path.join(gdb_path, f"usa{state}.gdb")
        #Import the feature for boundary and water
        # fc = f"usa{state[3:5]}_joined"
        fcInMem = arcpy.management.CopyFeatures(fc, f"in_memory/usa{state}_fcInMem")
        water_fc = f"{fc[:-7]}_water_layer"
        waterInMem = arcpy.management.CopyFeatures(water_fc, f"in_memory/usa{state}_waterInMem")
        #Create the temporary id for joining fields later
        arcpy.AddField_management(fcInMem,'tempid','LONG')
        arcpy.CalculateField_management(fcInMem,"tempid",'!OBJECTID!','PYTHON')
        #Calculate the area(land+water) by GEODESIC method =&amp;gt; Kytt recommended
        arcpy.management.AddField(fcInMem, "GEODESIC_AREA", "FLOAT")
        with arcpy.da.UpdateCursor(fcInMem, ["SHAPE@AREA", "GEODESIC_AREA"]) as cursor:
            for row in cursor:
                row = dict(zip(cursor.fields, row))
                row['GEODESIC_AREA'] = row['SHAPE@AREA'] # This is in feature units, so you will likely need the conversion factor from arcpy.LinearUnitConversionFactor
                cursor.updateRow(row.values())
        #arcpy.management.CalculateGeometryAttributes(fcInMem, "GEODESIC_AREA AREA_GEODESIC", "", "SQUARE_METERS")&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 20 Jun 2024 14:45:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495381#M70871</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-06-20T14:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495541#M70880</link>
      <description>&lt;P&gt;I tried your solution, but the results are very far off from the Geodesic method for area calculations.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 17:55:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495541#M70880</guid>
      <dc:creator>HieuTran12</dc:creator>
      <dc:date>2024-06-20T17:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495609#M70886</link>
      <description>&lt;P&gt;Did you make sure that the feature units are meters? If so you can try this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import datetime

def process(fc):
        arcpy.env.workspace = "G:/usgrids2020/test1/"
        arcpy.env.overwriteOutput=True
        state = fc[34:-7]
        print(f"Processing for {state.upper()}")
        readTime = datetime.datetime.now()
        # arcpy.env.workspace = os.path.join(gdb_path, f"usa{state}.gdb")
        #Import the feature for boundary and water
        # fc = f"usa{state[3:5]}_joined"
        fcInMem = arcpy.management.CopyFeatures(fc, f"in_memory/usa{state}_fcInMem")
        water_fc = f"{fc[:-7]}_water_layer"
        waterInMem = arcpy.management.CopyFeatures(water_fc, f"in_memory/usa{state}_waterInMem")
        #Create the temporary id for joining fields later
        arcpy.AddField_management(fcInMem,'tempid','LONG')
        arcpy.CalculateField_management(fcInMem,"tempid",'!OBJECTID!','PYTHON')
        #Calculate the area(land+water) by GEODESIC method =&amp;gt; Kytt recommended
        arcpy.management.AddField(fcInMem, "GEODESIC_AREA", "FLOAT")
        with arcpy.da.UpdateCursor(fcInMem, ["SHAPE@", "GEODESIC_AREA"]) as cursor:
            for row in cursor:
                row = dict(zip(cursor.fields, row))
                row['GEODESIC_AREA'] = row['SHAPE@'].getArea('GEODESIC', 'SquareMeters')
                cursor.updateRow(row.values())
        #arcpy.management.CalculateGeometryAttributes(fcInMem, "GEODESIC_AREA AREA_GEODESIC", "", "SQUARE_METERS")&lt;/LI-CODE&gt;&lt;P&gt;Which uses the Polygon.getArea() method. It pulls the whole shape object though so if you're doing this for millions of rows it can slow down a bit, but you'll get an accurate Geodesic area.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 19:19:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495609#M70886</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-06-20T19:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495653#M70889</link>
      <description>&lt;P&gt;Wow, this could be an alternate method of CalculateGeometryAttributes. Or does it have any tradeoffs?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 20:33:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495653#M70889</guid>
      <dc:creator>HieuTran12</dc:creator>
      <dc:date>2024-06-20T20:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495721#M70893</link>
      <description>&lt;P&gt;The tradeoff is that you have to use an arcpy cursor object, but I do most of my scripting with cursors. Even wrote some wrapper classes that allow you to use cursor objects safely using python syntax (see my post in Python Ideas).&lt;/P&gt;&lt;P&gt;Cursors are great because they gave you really granular access to the feature data. They are still Python objects though and don't have all the horsepower of the base Arc functions that are implemented in C.&lt;/P&gt;&lt;P&gt;For use cases like this though, and basic CRUD ops on a dataset they're great. Especially if you use the where_clause and spatial_filter parameters properly.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 23:10:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1495721#M70893</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-06-20T23:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1500081#M70965</link>
      <description>&lt;P&gt;Hi Joshua, have you heard anything from them yet?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apparently, I need that function in order to run to get some data from it. There is alternative solution that Hayden posted below but I couldn't use it for my case.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 20:49:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1500081#M70965</guid>
      <dc:creator>HieuTran12</dc:creator>
      <dc:date>2024-07-01T20:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateGeometryAttributes produces None values in multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1500097#M70968</link>
      <description>&lt;P&gt;Spent time working through the issue with Esri Support, and it is complex.&amp;nbsp; The issue has nothing to do with any specific type of workspace, nor anything with CalculateGeometryAttributes itself, it has to do with how Esri has structured their code for hundreds of Python-based tools like CalculateGeometryAttributes.&amp;nbsp; There are literally hundreds of tools that will all fail to run with Python multiprocessing.&amp;nbsp; The crazy part is, for most of the tools only a single line of code needs to be changed to make it work.&lt;/P&gt;&lt;P&gt;The question then becomes are these issues with documentation or the software, are these defects or enhancement requests, etc....&amp;nbsp; I haven't closed out the Esri Support case yet, but I suspect it will be a mixture of documentation defects and software enhancements that come out of it.&lt;/P&gt;&lt;P&gt;In the meantime, one can at least roll their own code with ArcPy DA cursors.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 21:46:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculategeometryattributes-produces-none-values/m-p/1500097#M70968</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2024-07-01T21:46:20Z</dc:date>
    </item>
  </channel>
</rss>

