0

Been battling this problem for a long time now, so hoping someone here can shed light on a possible solution. The problem is that I have 100 points and I want to apply a color palette to the points so that no two points within 25 miles have the same color. The issue I'm trying to prevent is having points close to each other being mistaken for similarity.

What I want this to do is, start with the first point, fill in a field with a value of "ONE" and then select a random point that's not within 25 miles of it. That next selected random point will also get a field value of "ONE". I want this to repeat until I have ten records (points) with a field value of "ONE" and that no two points in this sample is within 25 miles of any other point in the sample.

# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management('InputPoints100', 'NEW_SELECTION',"OBJECTID = 1")

# Process: Calculate Field
arcpy.management.CalculateField("InputPoints100", "Color", '"ONE"', "ARCADE", "ONE")

arcpy.SelectLayerByLocation_management('InputPoints100', 'WITHIN_A_DISTANCE', 'InputPoints100',"20 Miles", 'NEW_SELECTION', 'INVERT')

layer = "InputPoints100"
count = 1

def SelectRandomByCount (layer, count):
    import random
    layerCount = int (arcpy.GetCount_management (layer).getOutput (0))
    if layerCount < count:
        print("input count is greater than layer count")
        return
    oids = [oid for oid, in arcpy.da.SearchCursor (layer, "OID@")]
    oidFldName = arcpy.Describe (layer).OIDFieldName
    delimOidFld = arcpy.AddFieldDelimiters (layer, oidFldName)
    randOids = random.sample (oids, count)
    oidsStr = ", ".join (map (str, randOids))
    sql = "{0} IN ({1})".format (delimOidFld, oidsStr)
    arcpy.SelectLayerByAttribute_management (layer, "", sql)

SelectRandomByCount(layer, count)

arcpy.management.CalculateField("InputPoints100", "Color", '"ONE"', "ARCADE", "ONE")
  • 1
    If all your 100 points fall within a circle with diameter 25 miles then you are clearly facing an impossible task. Assuming that is not the case I think you should start working with two within 25 miles and one further away to see if you can get anywhere. – PolyGeo Aug 28 at 20:03
  • The 25 miles is arbitrary and is being used to determine the exclusion points. For example, after the first point is selected, the next point could be any of the remaining 99 points, of which 90 are outside of 25 miles. The problem is figuring out how to conceptualize the workflow to start a script. – Dave Aug 28 at 20:06
  • 1
    If you cannot yet start a script then you could take ArcPy and Python out of your question and focus on the ArcGIS Pro workflow instead, or even take ArcGIS Pro out too and then focus on whether an algorithm for what you are trying to do is possible. – PolyGeo Aug 28 at 20:27
0

I would recommend a different route via the Point Distance tool. You can use the resulting table to create an exclusion list as you iterate through each OID.

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.