TransWikia.com

Applying symbology based on algorithm using ArcPy with ArcGIS Pro

Geographic Information Systems Asked on June 26, 2021

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")

One Answer

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.

Answered by HybridOutcast on June 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP