<?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 Populating a point layer field with an attribute of a polygon layer it falls inside in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496799#M39023</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to automate a process to populate a field in a point feature class with the name of district (a polygon layer) that it falls inside using python.&amp;nbsp; Ideally this script would&amp;nbsp;only populate the points that have NULL district names.&amp;nbsp; I'm thinking this&amp;nbsp;may be done &lt;SPAN style="color: #242729; background-color: #f9f8f6;"&gt;programmatically&lt;/SPAN&gt; using the select by attribute, select by location, and calculate field functions? If someone could point me in the right direction, that would be much appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Dec 2019 22:25:14 GMT</pubDate>
    <dc:creator>shildebrand</dc:creator>
    <dc:date>2019-12-02T22:25:14Z</dc:date>
    <item>
      <title>Populating a point layer field with an attribute of a polygon layer it falls inside</title>
      <link>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496799#M39023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to automate a process to populate a field in a point feature class with the name of district (a polygon layer) that it falls inside using python.&amp;nbsp; Ideally this script would&amp;nbsp;only populate the points that have NULL district names.&amp;nbsp; I'm thinking this&amp;nbsp;may be done &lt;SPAN style="color: #242729; background-color: #f9f8f6;"&gt;programmatically&lt;/SPAN&gt; using the select by attribute, select by location, and calculate field functions? If someone could point me in the right direction, that would be much appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2019 22:25:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496799#M39023</guid>
      <dc:creator>shildebrand</dc:creator>
      <dc:date>2019-12-02T22:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Populating a point layer field with an attribute of a polygon layer it falls inside</title>
      <link>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496800#M39024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you looked at the spatial join tool?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2019 17:15:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496800#M39024</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2019-12-04T17:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Populating a point layer field with an attribute of a polygon layer it falls inside</title>
      <link>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496801#M39025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah that's essentially what i'm trying to do except I don't want to create a new feature class.&amp;nbsp; I want the result of the spatial join to populate the existing point feature class.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2019 17:46:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496801#M39025</guid>
      <dc:creator>shildebrand</dc:creator>
      <dc:date>2019-12-04T17:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Populating a point layer field with an attribute of a polygon layer it falls inside</title>
      <link>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496802#M39026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just do the spatial join with the out to a in_memory FC.&amp;nbsp; Then join back to the original and calc it over.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2019 18:57:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496802#M39026</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2019-12-04T18:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: Populating a point layer field with an attribute of a polygon layer it falls inside</title>
      <link>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496803#M39027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think Doug's suggestion is the only option. Here is a code sample that you may use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;wks = os.path.join(os.getcwd(), "UpdateOneFC.gdb")&amp;nbsp;&lt;SPAN style="color: #339966;"&gt; # or hard code the workspace&lt;/SPAN&gt;&lt;BR /&gt; &lt;BR /&gt; point_fc = os.path.join(wks, "cities")&amp;nbsp;&amp;nbsp;&lt;BR /&gt; poly_fc = os.path.join(wks, "districts")&lt;BR /&gt; out_fc = r"memory\\spj_out"&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN style="color: #339966;"&gt; &amp;nbsp;# &lt;STRONG&gt;in_memory&lt;/STRONG&gt; if on 10x&lt;/SPAN&gt;&lt;BR /&gt; &lt;BR /&gt; # create a FieldMappings object&lt;BR /&gt; &lt;STRONG&gt;field_mapping&lt;/STRONG&gt; = arcpy.FieldMappings()&lt;BR /&gt; &lt;BR /&gt; &lt;SPAN style="color: #339966;"&gt;# create a fieldmap object using Join Feature's District field.&lt;/SPAN&gt;&lt;BR /&gt; fm = arcpy.FieldMap()&lt;BR /&gt; fm.addInputField(poly_fc, "District")&lt;BR /&gt; &lt;BR /&gt; &lt;SPAN style="color: #339966;"&gt;# update the variable field properties&lt;/SPAN&gt;&lt;BR /&gt; out_fld = fm.outputField&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN style="color: #339966;"&gt;# get District field from the output field&lt;/SPAN&gt;&lt;BR /&gt; out_fld_name = "District_trns"&amp;nbsp; &amp;nbsp; &lt;SPAN style="color: #339966;"&gt;# new name of the polygon field&lt;/SPAN&gt;&lt;BR /&gt; fm.outputField = out_fld&lt;BR /&gt; &lt;BR /&gt; &lt;SPAN style="color: #339966;"&gt;# add back the updated field map&lt;/SPAN&gt; &lt;BR /&gt; &lt;STRONG&gt;field_mapping&lt;/STRONG&gt;.addFieldMap(fm)&lt;BR /&gt; &lt;BR /&gt; &lt;SPAN style="color: #339966;"&gt;# transfer Polygon NAMEs to point fc&lt;/SPAN&gt; &lt;BR /&gt; result = arcpy.analysis.SpatialJoin(point_fc, poly_fc, out_fc, "JOIN_ONE_TO_ONE", "KEEP_ALL", &lt;STRONG&gt;field_mapping&lt;/STRONG&gt;, "WITHIN")&lt;BR /&gt; out_fc = result.getOutput(0)&lt;BR /&gt; &lt;BR /&gt; &lt;SPAN style="color: #339966;"&gt;# check result&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="color: #339966;"&gt;for testing purpose&lt;/SPAN&gt;&lt;BR /&gt; for fld in arcpy.ListFields(out_fc, "*"):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; print(fld.name)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;This will create a new feature class - I don't see any other tool can do so in-place. If you want the new field to your Target Feature Class then you use Join Field to to transfer the field back.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2019 02:26:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populating-a-point-layer-field-with-an-attribute/m-p/496803#M39027</guid>
      <dc:creator>NobbirAhmed</dc:creator>
      <dc:date>2019-12-05T02:26:58Z</dc:date>
    </item>
  </channel>
</rss>

