2

What process can I use to remove isolated cells in my layer; i.e. cells that don't have an immediate neighbour are to be removed - I've circled a couple in the image below. These are based on an index within a table built with the fishnet tool. Many of the cells for the index column in the attribute table are blank.

enter image description hereenter image description here

  • 1
    If you have access to spatial analyst extension you could use a Con with FocalStatistics (SUM) of an IsNull raster < 8 like: arcpy.sa.Con(arcpy.sa.FocalStatistics(arcpy.sa.IsNull(YourRaster),arcpy.sa.NbrRectangle(3,3,'CELL'),'SUM') < 8, YourRaster). If your data is feature data then look at Polygon Neighbors resources.arcgis.com/en/help/main/10.2/index.html#//… - polygons with no adjacent polygons don't appear in the output table (advanced license required). – Michael Stimson Jun 27 '18 at 5:50
  • 1
    Are you trying to do this within ArcMap or within ArcGIS Pro? If it is both then please just ask about one here and about the other in a separate question. That way you can tell us precisely what you have tried, and where you are stuck, in each. – PolyGeo Jun 27 '18 at 6:05
  • If it is vector data use Select tool and select those with a Shape Area > the area of one cell. – BERA Jun 27 '18 at 10:20
  • @BERA: all cells are a separate row - therefore all have the same area and this doesn't work. – val Jun 27 '18 at 10:55
  • @MichaelStimson: I'm trying the Polygon Neighbour tool. It creates a table but how do I use the values in that table to filter my layer? It works but I'm left with a table that has no spatial features. – val Jun 27 '18 at 10:56
4

If you are working with a vector dataset and you want to identify the polygons that have no neighbours so to remove them this can be easily done without any code, you could wrap it up in a model if you are automating this in the future.

  1. Run the Polygons Neighbors tools making sure the reporting field is an unique ID field, such as OBJECTID or FID. This will create a table for all polygons that share a boundary with at least one other neighbouring polygon.

Screenshot

  1. Now create a relate between this table and the polygon Featureclass as shown below (note you are relating src_OBJECTID in table to OBJECTID in FeatureClass):

Relate

  1. Select all rows in the table.
  2. Run the relate and pass the selection back to the polygon Featureclass.
  3. Invert the selection.

Ready to delete

  1. Delete isolated polygons, you could use the Delete Features tool for that as that honours selections.
2

You can use Python. For each cell, check that no other cell share a vertice:

import arcpy
from collections import defaultdict

layer = "fishnet"

#Create a dictionary of each vertice as key, and a list of all objectids at that vertice as value
d = defaultdict(list)
oids = []
with arcpy.da.SearchCursor(layer,['OID@','SHAPE@']) as cursor:
    for oid, shape in cursor:
        oids.append([oid,shape.pointCount])
        for vertices in shape:
            for vertice in vertices[:-1]:
                d[(vertice.X,vertice.Y)].append(oid)

#For each objectid check that they dont share vertices with another objectid
loners = []
for o in oids:
    c = 0
    #for k,v in d.items(): #py3/ArcGIS Pro
    for k,v in d.iteritems(): #py2/ArcMap
        if o[0] in v:
            c+=len(v)
    if c < o[1]:
        loners.append(o[0])

sql = """{0} IN({1})""".format(arcpy.AddFieldDelimiters(layer,arcpy.Describe(layer).OIDFieldname),','.join(str(o) for o in loners))
arcpy.SelectLayerByAttribute_management(in_layer_or_view=layer, 
                                       where_clause=sql)

Lonely cells get selected: enter image description here

-1

It seems to me that you are dealing with vector dataset so Select Layer by Location tool should do the trick.

  • Could you add more details. What should be used for Selection Features etc.? – BERA Jun 27 '18 at 10:21
  • @Alesinar: I'm looking for a functional method - not selecting things by hand. Sorry if that was not explicitly in the OP. – val Jun 27 '18 at 10:57

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.