1

I am using ArcMap version 10.7.

I have 2 layers, one point and one polygon (council district boundaries). The polygon layer has several polygons in it and each point has a dollar amount associated with it. I am trying to find the median $ for each polygon. I tried a spatial join and setting the Field Map option for the $ to median but the output is $0 for all council districts.

0

3 Answers 3

2

You haven't said, but I'm guessing from your wording that you're in ESRI's ArcMap or ArcGIS Pro. I would suggest doing the spatial join and the stats as two separate steps. You can then join back your stats if you need to. The following should give you the information you're after.

  1. Spatial join your polygon identifier to each point. I did not change the field mapping parameter. enter image description here

  2. Use Summary Statistics to calculate the median, or other any other stats needed, for each polygon based on the output from step 1. enter image description here

2
  • Unfortunately, median is not an option in the Summary Statistics tool. Although, I did the first step and now each point has which council district it belongs to. Thoughts on the next step? Aug 19, 2020 at 15:12
  • @JessieMandirola Median is an option in my 2.6 dropdown in ArcGIS Pro. Also listed in the documentation (for Pro). pro.arcgis.com/en/pro-app/tool-reference/analysis/… Aug 19, 2020 at 21:38
2

Assuming that your points stored in shapefile and structured as follows:

enter image description here

you can use this workflow:

a) add long integer field (GNO) in example and and populate it using field calculator:

tbl=arcpy.da.TableToNumPyArray("POINTS",("fid","Value","GROUP_ID"))
bs=sorted(tbl, key=lambda x: (x[1]),reverse=False)
dPid={};d={}
for row in bs:
 N=dPid.get(row[2],0);N+=1
 dPid[row[2]]=N
 d[row[0]]=N
def SortGroupOrder(oid):
  return d[oid]
#---------------------
SortGroupOrder( !FID!)

b) compute total number of points per polygon:

Frequency("POINTS", "SUMMARY", frequency_fields="GROUP_ID")

c) transfer FREQUENCY values to POINTS table:

JoinField("POINTS", "GROUP_ID", "SUMMARY", "GROUP_ID")

d) compute median point. If there are plenty of points per each polygon I'd say this will do:

CalculateField("POINTS", "FREQUENCY", "[FREQUENCY]/2")

although strictly speaking procedure is different for odd and even numbers of frequency.

e) select median points:

SelectLayerByAttribute("POINTS", "NEW_SELECTION", '"GNO" = "FREQUENCY"')
1

If you're interested in a solution that involves the R-ArcGIS bridge and a single tool to do all of this in one step, check out this solution I came up with. You should be able to copy the code in an R script, import as a custom tool, and then you just have to specify a few input parameters like point layer, polygon layer, coordinate system, etc.

This solution basically does the join and summarize workflow mentioned above, it just condenses the steps into a single tool interface more like Summarize Within.

1
  • Welcome to GIS SE! Thanks for your contribution. It is always best to include the code in the body of the text. That way, if the link ever changes or goes 404, your answer is still available to others.
    – Aaron
    Feb 6, 2021 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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