try: import arcpy, os, sys, traceback arcpy.env.overwriteOutput = True #Get the input feature class or layer ## inFeatures = arcpy.GetParameterAsText(0) ## outFeatures = arcpy.GetParameterAsText(1) inFeatures = r"C:\csny490\habitat_frag_analysis_20110919\circles.gdb\mature_interior_forest" outFeatures = r"C:\csny490\habitat_frag_analysis_20110919\circles.gdb\out_polys" #Some housekeeping inDesc = arcpy.Describe(inFeatures) oidName = str(inDesc.OIDFieldName) if inDesc.dataType == "FeatureClass": inFeatures = arcpy.MakeFeatureLayer_management(inFeatures) sR = inDesc.spatialReference xyTol = sR.XYTolerance arcpy.env.overwriteOutput = True #Create the stub output feature class arcpy.CopyFeatures_management(inFeatures,outFeatures) arcpy.AddField_management(outFeatures, "BUFFDIST", "DOUBLE") OIDFieldName = arcpy.Describe(outFeatures).OIDFieldName arcpy.MinimumBoundingGeometry_management(outFeatures, "in_memory\\br", "RECTANGLE_BY_WIDTH", "NONE", "", "MBG_FIELDS") #Create dictionary of ORIG_FID,MBR_WIDTH fidWidthDict = dict([(r.ORIG_FID, r.MBG_WIDTH) for r in arcpy.SearchCursor("in_memory\\br")]) # arcpy.Delete_management("in_memory\\br") #Calculate the inscribed circles rows = arcpy.UpdateCursor(outFeatures) for row in rows: print "Processing polygon " + str(row.getValue(OIDFieldName)) inShape = row.shape aGeom = arcpy.Geometry() maxBuffDist = fidWidthDict[row.getValue(OIDFieldName)] / 2 minBuffDist = xyTol geomList = [] while (maxBuffDist - minBuffDist) >= xyTol: midBuffDist = (minBuffDist + maxBuffDist) / 2.0 print "Checking buffer distance = " + str(midBuffDist * -1) geomList = arcpy.Buffer_analysis(inShape, aGeom, midBuffDist * -1, "FULL","", "NONE", "") if len(geomList) > 0: minBuffDist = midBuffDist else: maxBuffDist = midBuffDist geomList = arcpy.Buffer_analysis(inShape, aGeom, (midBuffDist - (2 * xyTol)) * -1, "FULL","", "NONE", "") inPoint = arcpy.FeatureToPoint_management(geomList[0], aGeom, "INSIDE")[0] geomList = arcpy.Buffer_analysis(inPoint, aGeom, (midBuffDist - xyTol), "FULL" ,"", "NONE", "") row.BUFFDIST = midBuffDist * -1 row.shape = geomList[0] rows.updateRow(row) del row, rows print "Done!!!" except: print "\n*** LAST GEOPROCESSOR MESSAGE (may not be source of the error)***" print arcpy.GetMessages() print "\n*** PYTHON ERRORS *** " print "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0] print "Python Error Info: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.