2

My goal is to create a raster from points with values based on at least 3 unique IDs within a cell. Cells that had fewer than 3 points with unique IDs will have value NA. See below for clarification. I looked at Selecting set number of points within polygon grid cells using QGIS? hoping to adapt it, but am still stuck.

I created a fishnet with certain cell size that I think may be reasonable. Now, I want to identify the number points within each cell with unique IDs (here, VesselID). Next, I want to assign NAs to my field of interest (here, AdjPounds) for points that do not fit the "minimum 3 unique IDs in the cell criteria". I thought about using the Intersect tool, but don't know how to add the criteria.

Can you help?

This is probably best done in Python, but I'm not familiar with that language yet.

More context: I will need to reiterate this process for several similar files and ultimately conduct raster math to get an average raster. I assume I will need to choose the same cell size when I create the rasters to avoid resampling to obtain the final "average" raster.

  • What do you want in AdjPounds when not NA? – BERA Aug 6 at 17:21
  • I want AdjPounds to be sum of value in the cell. I assumed this would happen when I use the Points to Raster tool and choose Sum based on that field. – KVininska Aug 6 at 17:23
  • So AdjPounds already has values and you want to Null out some of them based on your criteria? Which arcmap version do you have? – BERA Aug 6 at 17:25
  • 10.6. Also, trying intersect with fishnet and points and returning null output (because fishnet isn't a polygon?). – KVininska Aug 6 at 17:33
1

Intersect the points and fishnet polygons. Then one way is to use python and the pandas module to count unique point ids per fishnet id.

import arcpy
import pandas as pd

#Change these four lines to match your data
inter_output = r'C:\data.gdb\intersect123'
fishnet_id_field = 'FID_fishnet'
vessel_id_field = 'VesselID'
adjp_field = 'AdjPounds'

#Create a pandas dataframe by reading each record with da.SearchCursor
df = pd.DataFrame.from_records(data=arcpy.da.SearchCursor(inter_output, [fishnet_id_field, vessel_id_field]), columns=[fishnet_id_field, vessel_id_field])
#Count unique ids per fishnet
df = df.groupby(fishnet_id_field)[vessel_id_field].nunique().reset_index()
#Create a dictionary of the result with fishnet id as key and unique count as value
d = dict(zip(df[fishnet_id_field], df[vessel_id_field]))
#Update adjp_field using the dictionary
with arcpy.da.UpdateCursor(inter_output, [fishnet_id_field, adjp_field]) as cursor:
    for row in cursor:
        if d[row[0]]<3: #If less than 3 unique values
            row[1] = None
            cursor.updateRow(row)

If you dont want to use python you should be able to:

  1. Dissolve intersection by fishnet id and vessel id to remove duplicates
  2. Count using summary statistics
  3. Join results back to the points
  4. Field calculate if count >2
  • 1
    You are amazing! Thank you and this is a great way to learn the syntax in Python. Is there a way to generalize using %name_X_name% or something like that for the top 4 lines to be able to add this to ModelBuilder to iterate through several files in the geodatabase? For example run through interesect1, interesect2, etc. and/or with FID_fishnet_1, FID_fishnet_2, etc. – KVininska Aug 6 at 18:55
  • 2
    Yes but it is probably easier to do everything in python. Use listfeatureclasses and iterate over each intersection – BERA Aug 6 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.