<?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: Using a file path stored in an attribute field to add data to the data frame in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714802#M55463</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nathan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The cursor will honor a selection and would work similar to other geoprocessing tools when a selection is applied to the data that is being processed (only the selection gets processed).&amp;nbsp; You could select the attributes manually in the attribute table or use the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000071000000"&gt;Select Layer By Attribute&lt;/A&gt; tool within your script and build in a SQL expression to select the records you would like to add.&amp;nbsp; Let me know what you think! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Apr 2015 14:38:22 GMT</pubDate>
    <dc:creator>DavidChambers1</dc:creator>
    <dc:date>2015-04-10T14:38:22Z</dc:date>
    <item>
      <title>Using a file path stored in an attribute field to add data to the data frame</title>
      <link>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714801#M55462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to add a raster dataset to my dataframe from a path stored in a field within the attribute table of a feature class.&amp;nbsp; Ideally, I would like to add the rasters one at a time based upon a selection performed on the feature class.&amp;nbsp;&amp;nbsp; I have a python script which will add the raster based on the file path in the field but I am having trouble adding the selection process to it.&amp;nbsp; Has anybody done something similar or have any ideas?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fc = "C:/Users/username/Documents/ArcGIS/Default.gdb/script_input"&lt;/P&gt;&lt;P&gt;fields = ["filepath"]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# For each row print the "path" field&lt;/P&gt;&lt;P&gt;#&amp;nbsp; &lt;/P&gt;&lt;P&gt;#&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(fc, fields) as cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pathfield = ("{0}".format(row[0]))&lt;/P&gt;&lt;P&gt;print(pathfield)&lt;/P&gt;&lt;P&gt;# Local variables:&lt;/P&gt;&lt;P&gt;qqlayer = pathfield&lt;/P&gt;&lt;P&gt;Output_raster_layer_name = "Raster to Look at"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Process: Make Raster Layer&lt;/P&gt;&lt;P&gt;test = arcpy.MakeRasterLayer_management(qqlayer, Output_raster_layer_name, "", "213322.051897854 4081064.77976305 290804.751897854 4174358.97976305", "")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Apr 2015 14:20:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714801#M55462</guid>
      <dc:creator>NathanPugh</dc:creator>
      <dc:date>2015-04-10T14:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using a file path stored in an attribute field to add data to the data frame</title>
      <link>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714802#M55463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nathan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The cursor will honor a selection and would work similar to other geoprocessing tools when a selection is applied to the data that is being processed (only the selection gets processed).&amp;nbsp; You could select the attributes manually in the attribute table or use the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000071000000"&gt;Select Layer By Attribute&lt;/A&gt; tool within your script and build in a SQL expression to select the records you would like to add.&amp;nbsp; Let me know what you think! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Apr 2015 14:38:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714802#M55463</guid>
      <dc:creator>DavidChambers1</dc:creator>
      <dc:date>2015-04-10T14:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using a file path stored in an attribute field to add data to the data frame</title>
      <link>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714803#M55464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;resolved?​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Apr 2015 02:25:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714803#M55464</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-04-19T02:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using a file path stored in an attribute field to add data to the data frame</title>
      <link>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714804#M55465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for suggesting the SQL expression.&amp;nbsp; Your 1st comment about manually selecting a record in the attribute table is the one I would like to go with but for some reason does not work.&amp;nbsp; The script always returns the 1st record no matter which record is selected.&amp;nbsp; Any suggestions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2015 15:08:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714804#M55465</guid>
      <dc:creator>NathanPugh</dc:creator>
      <dc:date>2015-04-22T15:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using a file path stored in an attribute field to add data to the data frame</title>
      <link>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714805#M55466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Nathan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you doing something similar to &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Interactively_selecting_records_in_a_table/005s0000004v000000/"&gt;this documentation&lt;/A&gt; for selecting the records interactively? If you are selecting the records of the feature layer in the map document then you would need to process that same feature layer with the search cursor.&amp;nbsp; In your script it looks like you are referencing a hardcoded input fc which is not the same layer that is in the map document:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;fc = "C:/Users/username/Documents/ArcGIS/Default.gdb/script_input"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;That variable would need to reference the in-memory feature layer.&amp;nbsp; Check out the arcpy.mapping module in order to accomplish this.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;In order to avoid the in-memory processing I believe the Select Layer By Attribute tool could be used in the script to select records from your harcoded FC. This would not allow you to select attributes interactively though.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Let me know if you have any specific questions about that and best of luck!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;David&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2015 15:27:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714805#M55466</guid>
      <dc:creator>DavidChambers1</dc:creator>
      <dc:date>2015-04-22T15:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using a file path stored in an attribute field to add data to the data frame</title>
      <link>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714806#M55467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That was the ticket!&amp;nbsp; Thanks.&amp;nbsp; Here is the correct code script below.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/P&gt;&lt;P&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;/P&gt;&lt;P&gt;lyr = arcpy.mapping.ListLayers(mxd, "qq")[0]&lt;/P&gt;&lt;P&gt;fields = ["path"]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# For each row print the "path" field&lt;/P&gt;&lt;P&gt;#&amp;nbsp; &lt;/P&gt;&lt;P&gt;#&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(lyr, fields) as cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pathfield = ("{0}".format(row[0]))&lt;/P&gt;&lt;P&gt;print(pathfield)&lt;/P&gt;&lt;P&gt;# Local variables:&lt;/P&gt;&lt;P&gt;qqlayer = pathfield&lt;/P&gt;&lt;P&gt;Output_raster_layer_name = "QQ to inspect"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Process: Make Raster Layer&lt;/P&gt;&lt;P&gt;arcpy.MakeRasterLayer_management(qqlayer, Output_raster_layer_name, "", "", "")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Apr 2015 18:41:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-file-path-stored-in-an-attribute-field-to/m-p/714806#M55467</guid>
      <dc:creator>NathanPugh</dc:creator>
      <dc:date>2015-04-24T18:41:28Z</dc:date>
    </item>
  </channel>
</rss>

