<?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 Selecting Max Value from Current Selection in ArcMap Questions</title>
    <link>https://community.esri.com/t5/arcmap-questions/selecting-max-value-from-current-selection/m-p/1013987#M1818</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I have a Feature Class data set that contains many GPS points that where collected over the course of a couple years.&amp;nbsp; The latest ones have better accuracy compared to the older ones.&amp;nbsp; For example, a valve could have 2-3 GPS points scattered around it.&amp;nbsp; I have made a model that will iterate through each GPS point, select all the ones around it and select the oldest ones and either copy and move or delete them.&amp;nbsp; I have chosen the model route because it seemed the simplest solution, but....&lt;/P&gt;&lt;P&gt;I am having trouble getting a SQL expression to work for the last part, Selecting the oldest points.&amp;nbsp; So far I have been using the expression,&amp;nbsp;GPS_Time = (SELECT MIN( GPS_Time) FROM %Near_GPS_Point%) , but for some reason this doesn't seem to work for SUBSET_SELECTION.&amp;nbsp; I have tried many variations of this expression but invalid expression are my only results.&lt;/P&gt;&lt;P&gt;Not having any outputs created would be ideal as there are about 300k GPS points to iterate though.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jan 2021 16:28:18 GMT</pubDate>
    <dc:creator>EvanMyers1</dc:creator>
    <dc:date>2021-01-05T16:28:18Z</dc:date>
    <item>
      <title>Selecting Max Value from Current Selection</title>
      <link>https://community.esri.com/t5/arcmap-questions/selecting-max-value-from-current-selection/m-p/1013987#M1818</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I have a Feature Class data set that contains many GPS points that where collected over the course of a couple years.&amp;nbsp; The latest ones have better accuracy compared to the older ones.&amp;nbsp; For example, a valve could have 2-3 GPS points scattered around it.&amp;nbsp; I have made a model that will iterate through each GPS point, select all the ones around it and select the oldest ones and either copy and move or delete them.&amp;nbsp; I have chosen the model route because it seemed the simplest solution, but....&lt;/P&gt;&lt;P&gt;I am having trouble getting a SQL expression to work for the last part, Selecting the oldest points.&amp;nbsp; So far I have been using the expression,&amp;nbsp;GPS_Time = (SELECT MIN( GPS_Time) FROM %Near_GPS_Point%) , but for some reason this doesn't seem to work for SUBSET_SELECTION.&amp;nbsp; I have tried many variations of this expression but invalid expression are my only results.&lt;/P&gt;&lt;P&gt;Not having any outputs created would be ideal as there are about 300k GPS points to iterate though.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 16:28:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/selecting-max-value-from-current-selection/m-p/1013987#M1818</guid>
      <dc:creator>EvanMyers1</dc:creator>
      <dc:date>2021-01-05T16:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Max Value from Current Selection</title>
      <link>https://community.esri.com/t5/arcmap-questions/selecting-max-value-from-current-selection/m-p/1015966#M1862</link>
      <description>&lt;P&gt;So the model I was creating to find these points wasn't working out as well as I hoped.&amp;nbsp; I decided to switch gears and change my process to a python code.&amp;nbsp; The code works very well by adding the points I want to a keep_list and the bad ones to a discard_list.&amp;nbsp; Code is a little messy but it works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only issue I am having is at some point during a large dataset arcmap will crash.&amp;nbsp; To avoid this issue, I would like to populate the 'Status' field with "Good" if its on the keep_list.&amp;nbsp; I was thinking of doing an UpdateCursor but I am unsure how it can be done using a dictionary.&amp;nbsp; Any suggestions will be appreciated.&lt;/P&gt;&lt;PRE&gt;fc = &lt;SPAN&gt;'wSystemValves_dupsTest'&lt;BR /&gt;&lt;/SPAN&gt;unifield = &lt;SPAN&gt;'UNIQUEID'&lt;BR /&gt;&lt;/SPAN&gt;oidField = &lt;SPAN&gt;'OBJECTID'&lt;BR /&gt;&lt;/SPAN&gt;near_distn = &lt;SPAN&gt;'NEAR_DISTN'&lt;BR /&gt;&lt;/SPAN&gt;northCoord = &lt;SPAN&gt;'Northing' &lt;/SPAN&gt;&lt;SPAN&gt;# sort ascending&lt;BR /&gt;&lt;/SPAN&gt;eastCoord = &lt;SPAN&gt;'Easting' &lt;/SPAN&gt;&lt;SPAN&gt;# sort decending&lt;BR /&gt;&lt;/SPAN&gt;status = &lt;SPAN&gt;'Status'&lt;BR /&gt;&lt;/SPAN&gt;fields_sorted = &lt;SPAN&gt;'Northing D'&lt;/SPAN&gt;; &lt;SPAN&gt;'Easting A'&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;keep_list = &lt;SPAN&gt;list&lt;/SPAN&gt;()&lt;BR /&gt;discard_list = &lt;SPAN&gt;list&lt;/SPAN&gt;()&lt;BR /&gt;&lt;BR /&gt;sCursor = arcpy.SearchCursor(fc)&lt;BR /&gt;sRow = sCursor.&lt;SPAN&gt;next&lt;/SPAN&gt;()&lt;BR /&gt;&lt;SPAN&gt;while &lt;/SPAN&gt;sRow:&lt;BR /&gt;&lt;BR /&gt;    &lt;SPAN&gt;if &lt;/SPAN&gt;sRow.getValue(oidField) &lt;SPAN&gt;not in &lt;/SPAN&gt;discard_list:&lt;BR /&gt;        arcpy.SelectLayerByAttribute_management(fc&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"NEW_SELECTION"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"OBJECTID = {}"&lt;/SPAN&gt;.format(sRow.getValue(oidField)))&lt;BR /&gt;        arcpy.SelectLayerByLocation_management(fc&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"INTERSECT"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;fc&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;3&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"NEW_SELECTION"&lt;/SPAN&gt;)&lt;BR /&gt;        &lt;SPAN&gt;# get number of points selected&lt;BR /&gt;&lt;/SPAN&gt;        count = &lt;SPAN&gt;int&lt;/SPAN&gt;(arcpy.GetCount_management(fc).getOutput(&lt;SPAN&gt;0&lt;/SPAN&gt;))&lt;BR /&gt;&lt;BR /&gt;        &lt;SPAN&gt;# List all values:&lt;BR /&gt;&lt;/SPAN&gt;        sel_values = [&lt;SPAN&gt;list&lt;/SPAN&gt;(i) &lt;SPAN&gt;for &lt;/SPAN&gt;i &lt;SPAN&gt;in &lt;/SPAN&gt;arcpy.da.SearchCursor(fc&lt;SPAN&gt;, &lt;/SPAN&gt;[oidField&lt;SPAN&gt;, &lt;/SPAN&gt;northCoord&lt;SPAN&gt;, &lt;/SPAN&gt;eastCoord&lt;SPAN&gt;, &lt;/SPAN&gt;near_distn&lt;SPAN&gt;, &lt;/SPAN&gt;unifield])]&lt;BR /&gt;        &lt;SPAN&gt;# Sort by Northing and Easting:&lt;BR /&gt;&lt;/SPAN&gt;        sel_values_sorted = &lt;SPAN&gt;sorted&lt;/SPAN&gt;(sel_values&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;key&lt;/SPAN&gt;=&lt;SPAN&gt;lambda &lt;/SPAN&gt;x: (x[&lt;SPAN&gt;1&lt;/SPAN&gt;]&lt;SPAN&gt;, &lt;/SPAN&gt;-x[&lt;SPAN&gt;2&lt;/SPAN&gt;])&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;reverse&lt;/SPAN&gt;=&lt;SPAN&gt;False&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;        &lt;SPAN&gt;if &lt;/SPAN&gt;count == &lt;SPAN&gt;2 &lt;/SPAN&gt;&lt;SPAN&gt;and &lt;/SPAN&gt;sel_values_sorted[&lt;SPAN&gt;0&lt;/SPAN&gt;][-&lt;SPAN&gt;2&lt;/SPAN&gt;] &amp;lt; &lt;SPAN&gt;3&lt;/SPAN&gt;:&lt;BR /&gt;&lt;BR /&gt;            &lt;SPAN&gt;print &lt;/SPAN&gt;(sel_values_sorted)&lt;BR /&gt;            &lt;SPAN&gt;# keep the one with the correct coordinates&lt;BR /&gt;&lt;/SPAN&gt;            keepOID = sel_values_sorted[&lt;SPAN&gt;0&lt;/SPAN&gt;][&lt;SPAN&gt;0&lt;/SPAN&gt;]&lt;BR /&gt;            &lt;SPAN&gt;# discard the one with bad coordinates&lt;BR /&gt;&lt;/SPAN&gt;            discardOID = sel_values_sorted[&lt;SPAN&gt;1&lt;/SPAN&gt;][&lt;SPAN&gt;0&lt;/SPAN&gt;]&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;if &lt;/SPAN&gt;keepOID &lt;SPAN&gt;not in &lt;/SPAN&gt;keep_list:&lt;BR /&gt;                keep_list.append(keepOID)&lt;BR /&gt;            &lt;SPAN&gt;if &lt;/SPAN&gt;discardOID &lt;SPAN&gt;not in &lt;/SPAN&gt;discard_list:&lt;BR /&gt;                discard_list.append(discardOID)&lt;BR /&gt;            &lt;SPAN&gt;else&lt;/SPAN&gt;:&lt;BR /&gt;                &lt;SPAN&gt;pass&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;            print &lt;/SPAN&gt;(keep_list)&lt;BR /&gt;            &lt;SPAN&gt;print &lt;/SPAN&gt;(discard_list)&lt;BR /&gt;            &lt;SPAN&gt;# Use OIDS from dictionary values to select:&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;if &lt;/SPAN&gt;count == &lt;SPAN&gt;1 &lt;/SPAN&gt;&lt;SPAN&gt;and &lt;/SPAN&gt;sel_values_sorted[&lt;SPAN&gt;0&lt;/SPAN&gt;][-&lt;SPAN&gt;2&lt;/SPAN&gt;] == -&lt;SPAN&gt;1&lt;/SPAN&gt;:&lt;BR /&gt;            &lt;SPAN&gt;# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;            # The following inputs are layers or table views: "wSystemValves_dupsTest"&lt;BR /&gt;&lt;/SPAN&gt;            arcpy.CalculateField_management(fc&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"Status"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'"good"'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"PYTHON_9.3"&lt;/SPAN&gt;)&lt;BR /&gt;            keepOID = sel_values_sorted[&lt;SPAN&gt;0&lt;/SPAN&gt;][&lt;SPAN&gt;0&lt;/SPAN&gt;]&lt;BR /&gt;            &lt;SPAN&gt;if &lt;/SPAN&gt;keepOID &lt;SPAN&gt;not in &lt;/SPAN&gt;keep_list:&lt;BR /&gt;                keep_list.append(keepOID)&lt;BR /&gt;            &lt;SPAN&gt;print &lt;/SPAN&gt;(keep_list)&lt;BR /&gt;            &lt;SPAN&gt;print &lt;/SPAN&gt;(discard_list)&lt;BR /&gt;&lt;BR /&gt;    sRow = sCursor.&lt;SPAN&gt;next&lt;/SPAN&gt;()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 15:58:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/selecting-max-value-from-current-selection/m-p/1015966#M1862</guid>
      <dc:creator>EvanMyers1</dc:creator>
      <dc:date>2021-01-12T15:58:03Z</dc:date>
    </item>
  </channel>
</rss>

