3

I am working on a Geo database where there is a layer with many polygons. i want to find that which polygons boundaries are connected so that i can create new layer from that polygons and which polygon boundary is not connected with first polygon, like there is space between them, so i want to not include that polygon in layer. This process will be achieved through python programming

I am using python in Arcgis 10.2.

  • I don't know the code specifically, but I can give you an idea of how I would approach this. You should be able to get the geometry for the polygons. Break down the ring(s) into points. Create lines from the points in 2 point segments. Take all your line features and check for overlapping/intersections against each other. If they intersect, save the geometry into a new feature in a new layer, or whatever you would like to do with that feature. I am definitely curious if there are more efficient/better ways though. – Branco Mar 9 '15 at 20:07
  • @Branco what if i will check if polygon shares a same boundary with other polygon at some point? – Waqar ahmad Mar 9 '15 at 21:07
  • @Branco what you think about the polygon class method called touch ? – Waqar ahmad Mar 9 '15 at 21:14
  • I'd start with spatial join on itself using one to many relationship. By going through output table you'll be able to group polygons and do much more – FelixIP Mar 10 '15 at 3:00
  • Use the Polygon Neighbors tool to create a table of which polygons neighbor each other. – PolyGeo Mar 27 '16 at 5:08
1

There may be faster ways, but my method of achieving this goal is to make use of a cursor to test each feature through selection. In the code below, a feature layer is created of your input feature class. Then each feature is selected by OID through an SQL where clause. A select by location is then performed on the same layer (I use "SHARE_A_LINE_SEGMENT_WITH", but "INTERSECT" may be more suitable depending on the data set). The original feature is then removed from the selection. Then the scripts checks for selection. If no features are selected, it is known that the feature does not have any neighbors. The 'island' feature's OID is then added to a list. Once the cursor completes, the list of OIDs is used to create an SQL where clause. This where clause is applied to the feature layer, and the result is exported.

In the script, inFC is your input feature class. outFcLocation is your output geodatabase. outFCName is the name of the output feature class.

import arcpy

#In feature class
inFC = r"C:\example.gdb\in_feature_class"

#Out feature class
outFcLocation = r"C:\example.gdb"
outFCName = "out_feature_class"

#Create feature layer to allow selection
arcpy.MakeFeatureLayer_management (inFC, "lyr")

#OID field name of feature layer
OIDfld = arcpy.Describe ("lyr").OIDFieldName

#Create list to be populated with 'island' features
OIDs = []

#Cursor to iterate through features
cursor = arcpy.da.SearchCursor ("lyr", "OID@")
for row in cursor:

    #select feature with sql where clause
    sql = '"{0}" = {1}'.format (OIDfld, row[0])
    arcpy.SelectLayerByAttribute_management ("lyr", "", sql)

    #Check for neighbors using select by location
    arcpy.SelectLayerByLocation_management ("lyr", "SHARE_A_LINE_SEGMENT_WITH", "lyr")

    #Remove original feature from selection
    arcpy.SelectLayerByAttribute_management ("lyr", "REMOVE_FROM_SELECTION", sql)

    #Check if any selection remains
    if not arcpy.Describe ("lyr").FIDSet:
        #If no selection, add OID to list
        OIDs.append (str(row[0]))


#Clean up
del row
del cursor

#Create selection sql for final feature
OIDstr = ",".join (OIDs)
sql = '"{0}" IN ({1})'.format (OIDfld, OIDstr)

#Select 'island' features
arcpy.SelectLayerByAttribute_management ("lyr", "", sql)

#Export features to new feature class
arcpy.FeatureClassToFeatureClass_conversion ("lyr", outFcLocation, outFCName)

You may have issues if you have more than 1000 'island' features, as sqls can't handle it I think. See this post for a workaround.

0

I would do an intersection resulting in a new feature class with the overlaps. Then run Select by Location (select with polygon in Qgis) with a search radius of a few meters and select features from your polygons that overlap with the intersections. Then export your selection to a new feature class.

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.