1

I'm working with ArcMap 10.2 on a layer of points that I have to move. I'm using the editor to move them. What I also need is to display these points based on how many are sharing the same coordinates X and Y, because that's how I find those I need to move ( I give priority to those points which share coordinates with many other points, for reasons you don't need to be bothered with). Getting a Summary Table from the concatenated X & Y and joining the count back to my points layer is the "standard" way to go, but I need to get a "real time" count of occurence of each value and I cannot extract each time the Summary Table and make the join. I searched for and tried with some python coding in the field calculator but didn't find anything working. Ideas?

  • As far as I know, there is no way to do this sort of real time analysis except maybe with ArcObjects. – Tom Mar 21 '16 at 17:45
2

Label your layer using this Python expression:

def FindLabel ([FID]):
  f=int([FID])
  mxd = arcpy.mapping.MapDocument("CURRENT")
  dFids={}
  lyr = arcpy.mapping.ListLayers(mxd,"POINTS")[0]
  with arcpy.da.SearchCursor(lyr,["FID","SHAPE@"]) as cursor:
    for row in cursor:
       FD,shp=row
       XY='%s %s' %(round(shp.firstPoint.X,2),round( shp.firstPoint.Y,2))
       if f == FD: aKey=XY
       try: dFids[XY]+=[FD]
       except: dFids[XY]=[FD]
  Fids=dFids[aKey]
  if f == Fids[0] and len(Fids)>1:
    return '<CLR red = "255">%i</CLR>'%len(Fids)
  return ""

It is intended for work with shapefiles, and you have to name your layer "POINTS".

Move point, click away,F5. Spatial duplicates will be labelled by count of overlaps:

enter image description here

UPDATED EXPRESSION:

dFids={}
def FindLabel ([FID]):
  global dFids
  f=int([FID])
  mxd = arcpy.mapping.MapDocument("CURRENT")
  lyr = arcpy.mapping.ListLayers(mxd,"POINTS")[0]
  if len(dFids)==0:
    with arcpy.da.SearchCursor(lyr,["FID","SHAPE@"]) as cursor:
      for row in cursor:
        FD,shp=row
        XY='%s %s' %(round(shp.firstPoint.X,2),round( shp.firstPoint.Y,2))
        if f == FD:aKey=XY
        try: dFids[XY]+=[FD]
        except: dFids[XY]=[FD]
  else:
    with arcpy.da.SearchCursor(lyr,["FID","SHAPE@"],r'"FID"='+str(f)) as cursor:
      for row in cursor:
        FD,shp=row
        aKey='%s %s' %(round(shp.firstPoint.X,2),round( shp.firstPoint.Y,2))
  Fids=dFids[aKey]; n=len(Fids)
  if f!=Fids[0] or n==1:return None
  if n==2:return '<CLR green = "255">%i</CLR>'%n
  if n<=4:return '<CLR blue = "255">%i</CLR>'%n
  return '<CLR red = "255">%i</CLR>'%n

enter image description here

It works much faster, because it builds dictionary just once. With very little effort it can be modified to update symbology field, but it will make it slow again

  • Note it is very slow, update tomorrow – FelixIP Mar 22 '16 at 4:38
  • Update tomorrow? What do you mean? Anyway thanks for the answer. I don't think this would solve my specific problem since I need speed and also need to label the layer with other information. I need it to be coloured or simbolyzed based on the number of points sharing same XY so that I can quickly spot the "most dense" XY among hundreds or thousands of points at a small scale. I wanted to try your solution nonetheless, but got this error: "Carriage returns are not allowed in simple expressions". – Michele Cordini Mar 22 '16 at 10:52
  • 1
    Check "Advanced" box and try again with updated script – FelixIP Mar 22 '16 at 19:50

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.