<?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 How to select 3 points per polygon grid feature from another feature class in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1546892#M89004</link>
    <description>&lt;P&gt;I have survey data which is collected on a 1ha grid square, within each grid will be 4 survey points.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am looking to do is select 3 points that fall within a larger grid square, 10ha.&amp;nbsp;&lt;/P&gt;&lt;P&gt;With how the data has been collected there are roughly 36 points per 10ha grid square.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The points selected can be random.&lt;/P&gt;&lt;P&gt;I thought about creating random points and some sort of buffer but that is just a no go and also thought about select by attribute but the data doesn't lend itself to getting specifically 3 survey points selected using any one attribute.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've dropped a screenshot of how the survey appears with a 10ha polygon grid for reference.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions are welcome.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Oct 2024 10:09:08 GMT</pubDate>
    <dc:creator>AndrewHankinson</dc:creator>
    <dc:date>2024-10-09T10:09:08Z</dc:date>
    <item>
      <title>How to select 3 points per polygon grid feature from another feature class</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1546892#M89004</link>
      <description>&lt;P&gt;I have survey data which is collected on a 1ha grid square, within each grid will be 4 survey points.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am looking to do is select 3 points that fall within a larger grid square, 10ha.&amp;nbsp;&lt;/P&gt;&lt;P&gt;With how the data has been collected there are roughly 36 points per 10ha grid square.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The points selected can be random.&lt;/P&gt;&lt;P&gt;I thought about creating random points and some sort of buffer but that is just a no go and also thought about select by attribute but the data doesn't lend itself to getting specifically 3 survey points selected using any one attribute.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've dropped a screenshot of how the survey appears with a 10ha polygon grid for reference.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions are welcome.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 10:09:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1546892#M89004</guid>
      <dc:creator>AndrewHankinson</dc:creator>
      <dc:date>2024-10-09T10:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to select 3 points per polygon grid feature from another feature class</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1547363#M89046</link>
      <description>&lt;P&gt;Not sure if I understand your exact needs, but you can try something like below. I think a more efficient method would be doing a spatial join in memory and then working with a pandas Data Frame to select three points from each subgroup, but this may get you started.&lt;/P&gt;&lt;P&gt;Code below will randomly select exactly three points within each "box".&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VinceE_0-1728507127223.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/116921iF449A68040271C46/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VinceE_0-1728507127223.png" alt="VinceE_0-1728507127223.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import sys
import numpy as np

# a list of point IDs to eventually export
point_oids_to_export = []

# Iterate over your sampling boxes
with arcpy.da.SearchCursor('SamplingPointBox', "OID@") as scurs:
    for oid, in scurs:
        # Select the current box. Select all the points with that box.
        box_selection = arcpy.management.SelectLayerByAttribute('SamplingPointBox', 'NEW_SELECTION', f"OID = {oid}")
        point_selection = arcpy.management.SelectLayerByLocation('SamplingPoint', 'INTERSECT', 'SamplingPointBox')
        
        # Get a list of the OIDs of the points within the box.
        oidValueList = [r[0] for r in arcpy.da.SearchCursor(point_selection, ["OID@"])]
        
        # Select three of those OIDs, not selecting the same one twice.
        rng = np.random.default_rng()
        chosen_oids = rng.choice(oidValueList, 3, False, None, 0, False)
        
        # Add those three new points to the running list.
        point_oids_to_export.extend(chosen_oids)

# Select all the collected points based on the long list of OIDs
query = f"OBJECTID IN {tuple(point_oids_to_export)}"
arcpy.management.SelectLayerByAttribute('SamplingPoint', 'NEW_SELECTION', query)

## export your selection from here, or add "arcpy.conversion.ExportFeatures()"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 20:54:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1547363#M89046</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2024-10-09T20:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to select 3 points per polygon grid feature from another feature class</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1549962#M89268</link>
      <description>&lt;P&gt;For posterity, this seems like a much more efficient option (working with Pandas Spatial Data Frames, instead of Cursors and SelectionByLocation/Attribute):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def new_method(pnt: Union[str, os.PathLike],    # full path to points
               box: Union[str, os.PathLike],    # full path to boxes
               box_id: str,                     # field name containing Box ID
               sample_count: int,               # how many points per box?
               output: Union[str, os.PathLike]  # full path to output FC
               ) -&amp;gt; None:                       # function has no return
    """SpatJoin points with boxes. Convert to SDF. Groups points by joined BOX ID.
    Select 3 points per group. Exports sampled Spatial Data Frame back to FC."""
    pnt_box_join = arcpy.analysis.SpatialJoin(pnt, box, r"memory\pnt_box_join").getOutput(0)

    # Convert FC to SDF. Drop unused columns. GroupBy BOX_ID column.
    # Without replacing, sample X# rows from each group. Export SDF back to FC.
    sdf = pd.DataFrame.spatial.from_featureclass(pnt_box_join)
    sdf = sdf.drop(columns=["Join_Count", "TARGET_FID", "Shape_Length", "Shape_Area"])
    sampled_sdf = sdf.groupby(box_id, group_keys=False).sample(n=sample_count)
    sampled_sdf.spatial.to_featureclass(location=output, sanitize_columns=False)
    print("SAMPLED SDF -&amp;gt; FC EXPORTED")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VinceE_0-1729265179912.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/117555i01C6B022725B301B/image-size/large?v=v2&amp;amp;px=999" role="button" title="VinceE_0-1729265179912.png" alt="VinceE_0-1729265179912.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 15:27:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1549962#M89268</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2024-10-18T15:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to select 3 points per polygon grid feature from another feature class</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1551678#M89442</link>
      <description>&lt;P&gt;Morning&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215483"&gt;@VinceE&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much for replying and sorry for the slow response.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I think you have understood my question perfectly. I have created some test data to see how the above works, and it works well. The only thing that came up was that if there were less than 3 points in a box then it would stop at that point. But that makes sense since its looking to select 3 points so this would be impossible if there aren't at least 3 to begin with.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;This is great, a real help and gives me something to learn from. Thanks again.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 02:14:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1551678#M89442</guid>
      <dc:creator>AndrewHankinson</dc:creator>
      <dc:date>2024-10-24T02:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to select 3 points per polygon grid feature from another feature class</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1551871#M89452</link>
      <description>&lt;P&gt;Sure, happy to help you work through anything further if you have additional questions!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 14:51:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-select-3-points-per-polygon-grid-feature/m-p/1551871#M89452</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2024-10-24T14:51:25Z</dc:date>
    </item>
  </channel>
</rss>

