<?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: Calculate Geometry - Custom Python Set Units via CSV in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024574#M59849</link>
    <description>&lt;P&gt;Thanks. Probably beyond my ability and time, but I see what I can do with this if something else doesn't come up.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Feb 2021 19:55:42 GMT</pubDate>
    <dc:creator>ChasCrandell</dc:creator>
    <dc:date>2021-02-08T19:55:42Z</dc:date>
    <item>
      <title>Calculate Geometry - Custom Python Set Units via CSV</title>
      <link>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024549#M59845</link>
      <description>&lt;P&gt;ArcGIS Dektop 10.6.1&lt;/P&gt;&lt;P&gt;I have to repeat a process on many GDBs quarterly. Need to calculate spatial fields (e.g. ccordinateX, coordinateY, featureArea, featureAreaUom, featureLength, featureLengthUom, featurePerimeter, featurePerimeterUom) with units based on an input CSV list of feature classes. Feature classes have spatial unit attributes that may differ based on the input CSV. CSV sample:&lt;/P&gt;&lt;TABLE border="1" width="99.87212276214834%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="21.22762148337596%" height="20"&gt;Feature_Class&lt;/TD&gt;&lt;TD width="25.44757033248082%"&gt;Area&lt;/TD&gt;&lt;TD width="18.414322250639387%"&gt;UOM_Area&lt;/TD&gt;&lt;TD width="15.9846547314578%"&gt;Line&lt;/TD&gt;&lt;TD width="18.797953964194374%"&gt;UOM_Line&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="21.22762148337596%" height="20"&gt;Grid_A&lt;/TD&gt;&lt;TD width="25.44757033248082%"&gt;ACRES&lt;/TD&gt;&lt;TD width="18.414322250639387%"&gt;Acres&lt;/TD&gt;&lt;TD width="15.9846547314578%"&gt;MILES_US&lt;/TD&gt;&lt;TD width="18.797953964194374%"&gt;US Survey Mile&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="21.22762148337596%" height="20"&gt;Ber_L&lt;/TD&gt;&lt;TD width="25.44757033248082%"&gt;NA&lt;/TD&gt;&lt;TD width="18.414322250639387%"&gt;NA&lt;/TD&gt;&lt;TD width="15.9846547314578%"&gt;FEET_US&lt;/TD&gt;&lt;TD width="18.797953964194374%"&gt;Feet&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="21.22762148337596%" height="20"&gt;RegA_A&lt;/TD&gt;&lt;TD width="25.44757033248082%"&gt;SQUARE_YARDS&lt;/TD&gt;&lt;TD width="18.414322250639387%"&gt;Square Yards&lt;/TD&gt;&lt;TD width="15.9846547314578%"&gt;FEE_US&lt;/TD&gt;&lt;TD width="18.797953964194374%"&gt;Feet&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="21.22762148337596%" height="20"&gt;AirDot_P&lt;/TD&gt;&lt;TD width="25.44757033248082%"&gt;NA&lt;/TD&gt;&lt;TD width="18.414322250639387%"&gt;NA&lt;/TD&gt;&lt;TD width="15.9846547314578%"&gt;NA&lt;/TD&gt;&lt;TD width="18.797953964194374%"&gt;NA&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I merged some existing scripts (I'm still a novice with python) to get the script below, which works (except I have to build out for more fields), except it sets the featureArea and featureLength units to meters based on the coordinate system of the feature classes, rather than taking units from the CSV. There is a commented out line close to the bottom "row[count] = &lt;A href="mailto:SHAPE.LENGTH@r[3]&amp;quot;" target="_blank" rel="noopener"&gt;SHAPE.LENGTH@r[3]"&lt;/A&gt;&amp;nbsp;that is the area where I think this needs to be altered?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os, sys, shutil, csv

Repository = arcpy.GetParameterAsText(0)
InCSV = arcpy.GetParameterAsText(1)

arcpy.env.workspace = Repository

#Create list of feature classes
def getFCList(vPath):
    vFullFCList = []
    vDSList = arcpy.ListDatasets()
    for ds in vDSList:
        vFCList = arcpy.ListFeatureClasses('*', 'All', ds)
        vFullFCList = vFullFCList + vFCList
    vFCList2 = arcpy.ListFeatureClasses()
    vFullFCList = vFullFCList + vFCList2
    return vFullFCList

#Get list of feature classes
fcList = getFCList(arcpy.env.workspace)
#List of fields to be checked
geoFields = [ "coordinateX", "coordinateY", "featureLength", "featureLengthUom", "featureArea", "featureAreaUom", "featurePerimeter", "featurePerimeterUom"]

for fc in fcList:
    fields = []
    desc = arcpy.Describe(fc)
    dataSet = desc.path
    arcpy.AddMessage("Updating Attributes in {0}".format(fc))
    fieldList = arcpy.ListFields(fc)
    #If the following fields exist, adds the field name to a list to be used later.
    for field in fieldList:
            if field.name == "coordinateX":
                fields.append(field.name)
                fields.append("SHAPE@X")                    
            elif field.name == "coordinateY":
                fields.append(field.name)
                fields.append("SHAPE@Y") 
            elif field.name == "featureLength":
                fields.append(field.name)
                fields.append("SHAPE@LENGTH")
            elif field.name == "featureArea":
                fields.append(field.name)
                fields.append("SHAPE@AREA")
            elif field.name == "featurePerimeter":
                fields.append(field.name)
                fields.append("SHAPE@LENGTH")
            else:
                fields.append(field.name)

    #The tool checks if the field exists within a feature class
    #If the field exists it will populate that field with its corresponding value
    arcpy.AddMessage(fields)
    with open(InCSV, 'r') as source:
        rdr = csv.reader(source)
        UpdateName = desc.name
        for r in rdr:
            if len(fields) &amp;gt; 0:
                with arcpy.da.UpdateCursor(fc, fields) as cursor:
                    for row in cursor:
                        count = 0
                        while count &amp;lt; len(fields):
                            if fields[count] == "coordinateX":
                                idx = fields.index("SHAPE@X")
                                row[count] = row[idx] 
                            elif fields[count] == "featureLength" and UpdateName == r[0]:
                                idx = fields.index("SHAPE@LENGTH")
                                row[count] = row[idx]
                                #row[count] = SHAPE.LENGTH@r[3]
                            elif fields[count] == "featureAreaUom" and UpdateName == r[0]:
                                row[count] = r[2] 
                            elif fields[count] == "featureLengthUom" and UpdateName == r[0]:
                                row[count] = r[4]   
                            count += 1

                        cursor.updateRow(row)
sys.exit()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 19:26:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024549#M59845</guid>
      <dc:creator>ChasCrandell</dc:creator>
      <dc:date>2021-02-08T19:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Geometry - Custom Python Set Units via CSV</title>
      <link>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024559#M59846</link>
      <description>&lt;P&gt;Personally I would find it simpler to pass these into an existing GP tool such as&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-geometry-attributes.htm" target="_blank"&gt;Calculate Geometry Attributes (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could just loop through the for r in rdr, then use r[0], r[1]... etc as arguments to the tool.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 19:40:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024559#M59846</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-02-08T19:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Geometry - Custom Python Set Units via CSV</title>
      <link>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024574#M59849</link>
      <description>&lt;P&gt;Thanks. Probably beyond my ability and time, but I see what I can do with this if something else doesn't come up.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 19:55:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024574#M59849</guid>
      <dc:creator>ChasCrandell</dc:creator>
      <dc:date>2021-02-08T19:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Geometry - Custom Python Set Units via CSV</title>
      <link>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024619#M59855</link>
      <description>&lt;P&gt;I don't know what IDE you are using but take some time to learn the debugger.&amp;nbsp; Step through your code and look at what the variables are and adjust as necessary.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 21:11:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024619#M59855</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-08T21:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Geometry - Custom Python Set Units via CSV</title>
      <link>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024630#M59857</link>
      <description>&lt;P&gt;Your csv is well set up for this, this is an example of the process:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with open(InCSV, 'r') as source:
    rdr = csv.reader(source)
    for r in rdr:
        fc_name = r[0]
        area_unit = r[2]
        length_unit = r[4]
        geometry_fields = []
        if area_unit != 'NA':
            geometry_fields.append('AREA')
        if length_unit != 'NA':
            geometry_fields.append('LENGTH')

        arcpy.management.AddGeometryAttributes(fcName, geometry_fields, length_unit, area_unit)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 08 Feb 2021 21:30:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-geometry-custom-python-set-units-via-csv/m-p/1024630#M59857</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-02-08T21:30:01Z</dc:date>
    </item>
  </channel>
</rss>

