AnsweredAssumed Answered

how to select points in a in a polygon that have a certain difference and append them to another shapefile

Question asked by simbakapfumo@gmail.com on May 11, 2018
Latest reply on May 14, 2018 by curtvprice

i have two different point shapefiles maximum.shp and minimum.shp. i also have a fishnet polygon shapefile that has 867 features. within each polygon there are maximum points and minimum points. now i want to select points in the maximum and in the minimum in each polygon if their grid_codes have a difference of 20m and append maximum points to another new shapefile  (selected_maximum_points) and the minimum points also to another new shapefile (selected_minimum_points). below is the code i have written so far. it only retains one point in each feature class. 

 

arcpy.MakeFeatureLayer_management(Grid,'index_lyr')
max_points = arcpy.SpatialJoin_analysis (MaximumPoints,Grid,"Surge_Tank")
min_points = arcpy.SpatialJoin_analysis (MinimumPoints,Grid,"Power_House")

MaximumCentralPoints = arcpy.CreateFeatureclass_management(workspace,"Maximum_CentralPoints_test",'POINT',max_points,has_m,has_z,sr)
MinimumCentralPoints = arcpy.CreateFeatureclass_management(workspace,"Minimum_CentralPoints_test",'POINT',min_points,has_m,has_z,sr)

arcpy.MakeFeatureLayer_management("Surge_Tank", 'point_lyr_max')
arcpy.MakeFeatureLayer_management("Power_House", 'point_lyr_min')
# page number represents the grid id
with arcpy.da.SearchCursor("Surge_Tank",["PageNumber","grid_code","OBJECTID"],'#',sr) as cursor1:
    for row in cursor1:
        with arcpy.da.SearchCursor("Power_House",["PageNumber","grid_code","OBJECTID"],'#',sr) as cursor2:
            for row2 in cursor2:
                if (row[0] == row2[0]):
                    if ((row[2]-row2[2])>=20):
                        arcpy.SelectLayerByAttribute_management('point_lyr_min','NEW_SELECTION',"OBJECTID = {}".format(row2[2]))
                        arcpy.FeatureClassToFeatureClass_conversion('point_lyr_min',workspace,"possible_powerhouse")
                        arcpy.Append_management("possible_powerhouse",MinimumCentralPoints,"TEST")
                        arcpy.SelectLayerByAttribute_management('point_lyr_max',"NEW_SELECTION","OBJECTID = {}".format(row[2]))
                        arcpy.FeatureClassToFeatureClass_conversion("point_lyr_max",workspace,"possible_surge_tank")
                        arcpy.Append_management("possible_surge_tank",MaximumCentralPoints,"TEST")

Outcomes