0

I'm quite new to ArcGIS and hope someone can help me.

I have one table that lists which polygons are contiguous with each other called BLPUsCavPlaceContigBLPUs that looks like this:

OBJECTID   blpuid  contigid  shape-length
    1         1        7          38
    2         1        16         42
    3         2        8          14

I then have a table of all the polygons called BLPUsCavPlace where the objectID is the blpuid and contigid:

OBJECTID   SHAPE   SHAPE_length  SHAPE_area
    1     polygon    126.846       986.093

Therefore I know which can merge with which, such as 1 and 7. I want to iterate through the first table, and for each row the cursor will take the blpuid and contigid and select these rows (OBJECTIDs) in BLPUsCavPlace, then it will dissolve them and add them to BLPUsCavPlaceDissolved.

So it would look at BLPUsCavPlaceContigBLPUs and select 1 and 7 in BLPUsCavPlace, then it would do the next row etc

The end result is that I have a polygon layer that contains all the possible dissolved polygons for each polygon within BLPUsCavPlace i.e. 1 + 7, 1 + 16, 2 + 8

I've been looking at arcpy.da.searchcursor which could retrieve the field values, but how would I then use the blpuid and contigid to select the rows in BLPUsCavPlace?

Any help is greatly appreciated!!

so i can run this:

fc = "BLPUsCavPlaceContigBLPUs"
fields = ["blpuid", "contigid"]

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:
        print("{0}, {1}".format(row[0], row[1]))

to get the field values, i then want to take the two values and use both as objectid in the other table and run dissolve on them

  • Can you explain "where the objectID is the blpuid and contigid" a bit more? Also, are you looking to run the Dissolve tool? – Paul Aug 14 '13 at 15:20
  • Hi - the objectID is a unique reference for every individual polygon in the layer BLPUsCavPlace. I've run the split polygon in all its vertices tool to know which polygons are contiguous with each other, then created the table BLPUsCavPlaceContigBLPUS to hold that information. So this was leftFID and rightFID, but i've combined them into one list of blpuid and contigid. The idea is to then be able to look up each possible dissolve of adjacent polygons, run the dissolve tool and add them into one master polygon layer of all possible merges. – user2581350 Aug 14 '13 at 15:43
2

Here is a rough draft of what I think you are after. Use the cursor to get the OBJECTID's that you need. I don't think that the da.SearchCursor is needed. The values from the cursor are used to form a SQL where clause in making a feature layer with only the two needed polygons. From there, dissolve with appropriate name. You will need to fit this your needs and give it some testing and error handling, but should give you a start.

import arcpy

arcpy.env.workspace = "...\\your_gdb"

FC = "BLPUsCavPlace"
TABLE = "BLPUsCavPlaceContigBLPUs"
FIELDS = ["blpuid", "contigid"]

with arcpy.SearchCursor(TABLE, FIELDS) as cursor:
    for row in cursor:
        OID1 = str(row[0])
        OID2 = str(row[1])
        SQL = "OBJECTID = %s OR OBJECTID = %s"%(OID1, OID2)
        arcpy.MakeFeatureLayer_management(FC, "TEMP_LYR", SQL)
        OUTPUT_NAME = "Dissolve_%s_%s"%(OID1, OID2)
        arcpy.Dissolve_management("TEMP_LYR", OUTPUT_NAME)
        arcpy.Delete_management("TEMP_LYR")

it may be the with/as, so try:

rows = arcpy.SearchCursor(TABLE, FIELDS)
for row in rows:
    OID1 = str(row[0])
    OID2 = str(row[1])
    SQL = "OBJECTID = %s OR OBJECTID = %s"%(OID1, OID2)
    arcpy.MakeFeatureLayer_management(FC, "TEMP_LYR", SQL)
    OUTPUT_NAME = "Dissolve_%s_%s"%(OID1, OID2)
    arcpy.Dissolve_management("TEMP_LYR", OUTPUT_NAME)
    arcpy.Delete_management("TEMP_LYR")

EDIT: this one is almost there, just having a problem with the output name as in the comment below

FC = "BLPUsCavPlace"
TABLE = "BLPUsCavPlaceContigBLPUs"
FIELDS = ["blpuid", "contigid"]
with arcpy.da.SearchCursor(TABLE, FIELDS) as cursor:
    for row in cursor:
        OID1 = str(int(row[0]))
        OID2 = str(int(row[1]))
        SQL = "OBJECTID = %s OR OBJECTID = %s"%(OID1, OID2)
        arcpy.MakeFeatureLayer_management(FC, "TEMP_LYR", SQL)
        OUTPUT_NAME = "Dissolve_%s_%s"%(OID1, OID2)
        arcpy.Dissolve_management("TEMP_LYR", OUTPUT_NAME)
        arcpy.Delete_management("TEMP_LYR")
  • thanks, gave it a go and got RunScript exec codeObject in main.__dict__ File "C:\Python27\Scripts\DissolveBLPUs.py", line 15, in <module> with arcpy.SearchCursor(fc, fields) as cursor: AttributeError: exit though. Nothing seems to be looking at TABLE, unless I'm reading it wrong? I changed it to with arcpy.SearchCursor(table, fields) as cursor: in case that made a difference as that is the table to iterate through but I got the same error... – user2581350 Aug 14 '13 at 17:36
  • hmmm, still getting the same error! any ideas?? – user2581350 Aug 14 '13 at 17:54
  • my apologies. I'm 95% not with it today. Fixed indentation and added a different cursor to try. If what you posted was returning values, use the da.SearchCursor; won't hurt anything. – gm70560 Aug 14 '13 at 18:09
  • thanks for all your help, getting closer! I now get this: C:\Users\Ant\Documents\ArcGIS\ITN.gdb\Dissolve_1.0_7.0 ERROR 000361: The name starts with an invalid character. Does it not like the full stop in there? Is there a way I can just append each new dissolved polygon to the same layer? – user2581350 Aug 14 '13 at 18:56
  • the ultimate end goal for me is to have all of these dissolves automatically added into one layer with those OIDs being added in the row under headings blpu1 and blpu2, i don't suppose you could help me manage that? – user2581350 Aug 14 '13 at 20:43

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.