THIS CODE LOADS A FC INTO A PYTHON DICTIONARY IN RAM # http://forums.arcgis.com/threads/17956-Using-centroid-geometry-to-get-values-of-intersecting-feature#post60607 # edits by Kimo import arcgisscripting, sys import random,datetime,pprint start = datetime.datetime.now() gp = arcgisscripting.create(9.3) #THE INPUT FC fc = "d:/workspace/datetest.gdb/pineforest" #Process: Build a field list and a mini dictionary to look up the field order (aka index) given a field name fieldList = gp.listfields(fc) fieldIndex = 0 fieldNameDict = {} for field in fieldList:    fieldNameDict[field.name] = fieldIndex    fieldIndex = fieldIndex + 1 shapeFieldName = gp.Describe(fc).shapeFieldName # fix missing definition pprint.pprint(fieldNameDict) #Process: Load the fc into a dictionary fcDictionary = {} oidFieldName = gp.describe(fc).oidfieldname searchRows = gp.searchcursor(fc) searchRow = searchRows.next() while searchRow:    oidFieldValue = searchRow.getvalue(oidFieldName)    fcDictionary[oidFieldValue] = []    for field in fieldList:        fcDictionary[oidFieldValue].append(searchRow.getvalue(field.name))    searchRow = searchRows.next() del searchRow,searchRows print print "Size of dictionary",len(fcDictionary) for sample in range(10):    print    idx = random.randint(0,len(fcDictionary))    #Print the values    print fcDictionary[idx]    #Print a name field value    print fcDictionary[idx][fieldNameDict["LCDB1NAME"]]    #Print the extent rectangle    print fcDictionary[idx][fieldNameDict[shapeFieldName]].extent    #Print ALL the coordinate pairs including parts and interior rings    shapeObj = fcDictionary[idx][fieldNameDict[shapeFieldName]]    for p in range(shapeObj.partCount):        part = shapeObj.getPart(p)        pnt = part.next()        while pnt:            print p,pnt.X,pnt.Y            pnt = part.next()            if not pnt:                pnt = part.next()                if pnt:                    interiorRing = True                    print "Hole" print "Completed",datetime.datetime.now() - start
[12139, <geoprocessing describe geometry object object at 0x16A388D8>, 66.0, u'Pine Forest - Closed Canopy', 66.0, u'Pine Forest - Closed Canopy', u'no', 64.70760971, 182.0, u'Rodney District', 16.0, u'Auckland Region', 11067.655349413637, 646803.66190707707] Pine Forest - Closed Canopy 1811685.23719998 5594544.72269999 1811781.95419998 5594599.59829999 NaN NaN NaN NaN 0 1811685.2372 5594544.9228 0 1811688.5206 5594544.9241 0 1811733.3278 5594561.747 0 1811781.9542 5594599.5983 0 1811780.0872 5594596.3042 0 1811757.3881 5594569.9774 0 1811726.5661 5594549.7439 0 1811689.9306 5594544.7227 0 1811685.2372 5594544.9228 Completed 0:00:14
#THIS CODE LOADS A FC INTO A PYTHON DICTIONARY IN RAM (AT LEAST IT SHOULD) import arcgisscripting, sys gp = arcgisscripting.create(9.3) fc = r"D:\csny490\overlay_20100115\gis_layers\county.gdb\county" #THE INPUT FC #Process: Build a field list and a mini dictionary to look up the field order (aka index) given a field name fieldList = gp.listfields(fc) fieldIndex = 0 fieldNameDict = {} for field in fieldList:    fieldNameDict[field.name] = fieldIndex    fieldIndex = fieldIndex + 1 #Process: Load the fc into a dictionary fcDictionary = {} oidFieldName = gp.describe(fc).oidfieldname searchRows = gp.searchcursor(fc) searchRow = searchRows.next() while searchRow:    oidFieldValue = searchRow.getvalue(oidFieldName)    fcDictionary[oidFieldValue] = []    for field in fieldList:        fcDictionary[oidFieldValue].append(searchRow.getvalue(field.name))    searchRow = searchRows.next() del searchRow del searchRows #Print the values of OBJECTID = 1 print fcDictionary[1] #Print the "COUNTY_NM" field value of OBJECTID = 1 print fcDictionary[1][fieldNameDict["COUNTY_NM"]] #Print the extent rectangle of OBJECTID = 1 print fcDictionary[1][fieldNameDict[shapeFieldName]].extent #Print the coordinate pairs of OBJECTID = 1 (assuming it is a single part feature) shapeObj = fcDictionary[1][fieldNameDict[shapeFieldName]] pointArray = shapeObj.getpart(0) pointObj = pointArray.next() while pointObj:    print str(pointObj.x) + ", " + str(pointObj.y)    pointObj = pointArray.next()
# create a dictionary of centroids sr = gp.Describe(fcAU).SpatialReference cur = gp.SearchCursor(fcAU,"land = 1") row = cur.next() dAU = {} pt = gp.CreateObject("Point") while row:    pt = row.shape.centroid    au = row.AU_NO    dAU[au] = pt    row = cur.next() del row,cur print "OD records",len(dAU)
parcel_desc=arcpy.Describe("parcels") #describe the parcels and get the shape field name parcel_shapefield=parcel_desc.ShapeFieldName flu_desc=arcpy.Describe("flu")#describe the flu and get the shape field name flu_shapefield=flu_desc.ShapeFieldName parcel_cursor=arcpy.UpdateCursor("parcels") for row in parcel_cursor: #iterate over the parcels    parcel_row_shape=row.getValue(parcel_shapefield) #get the geometry object    centroid=parcel_row_shape.centroid #get the centroid from the geometry object    flu_cursor=arcpy.SearchCursor("flu")    for flu_row in flu_cursor: #iterate over the flu        flu_row_shape=flu_row.getValue(flu_shapefield) #get the geometry object        if centroid.within(flu_row_shape)==True: #compare the two geometries            print "RENUM: %s FLU: %s" % (parcel_row.A1RENUM, flu_row.FLU_CODE) #do some junk with the two rows    del flu_cursor del parcel_cursor
parceldesc=arcpy.Describe('parcels') parcelShapeField=parceldesc.ShapeFieldName parcel_cursor=arcpy.UpdateCursor('parcels') for parcel_row in parcel_cursor: Â Â Â parcel_row_shape=parcel_row.getValue(parcelShapeField) # Â Â Â centroid=parcel_row_shape.centroid
centroid.crosses(other geometry object)
For update_row in update_cursor:  geo_update_row=create a geometry object for this row's label point  for search_row in search_cursor:    geo_search_row=create a geometry object for this row    if geo_update_row.crosses(geo_search_row) == True:      update_row.something = search_row.something      update_cursor.updaterow(update_row)    del geo_search_row    del geo_update_row
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.