import arcpy ##from arcpy.sa import * from arcpy import env ##arcpy.CheckOutExtension("Spatial") workspace = arcpy.env.workspace = "X:\\Grid\\Grid_Working.gdb\\All_Tiles\\" ##arcpy.env.overwrightOutput = True GDB = "X:\\Grid\\Grid_Working.gdb\\All_Tiles\\" FC = "X:\\Grid\\Grid_Working.gdb\\All_Tiles\\Grid_w_rShad" fieldName = "Grid_Num" buf = '200 feet' def selectBufExport(GDB, FC, fieldName, fieldVal, buf): selection = arcpy.selectByAttributes(GDB +'\\'+ FC, '%s = %s' % (fieldName, fieldVal)) bufferedSelection = arcpy.Buffer(selection, buf) arcpy.Export(bufferedSelection, GDB + '\\' + '%s_%s_tile' % (fieldName, fieldVal)) for (fieldVal, buf) in [(7, buf), (22, buf)]: selectBufExport(GDB, FC, fieldName, fieldVal, buf)
GDB = workspace = arcpy.env.workspace = "X:\\Grid\\Grid_Working.gdb\\working_utm" outFold = "X:\Grid\\Shape_AOI_files" FC = "X:\\Grid\\Grid_Working.gdb\\All_Tiles\\Grid_w_rShad" fieldName = "Grid_Num" buf = '200 feet' def selectBufExport(GDB, FC, fieldName, fieldVal, buf): selection = arcpy.Select_analysis(FC, GDB + '\\' + fieldVal, '%s = %s' % (fieldName, fieldVal)) bufferedSelection = arcpy.Buffer_analysis(selection, GDB + '\\' + "_buf", buf) arcpy.Export(bufferedSelection, GDB + '\\' + '%s_%s_tile' % (fieldName, fieldVal)) for (fieldVal, buf) in [(2, buf), (22, buf)]: selectBufExport(GDB, FC, fieldName, fieldVal, buf)
import arcpy import os def bufferFeaturesToIndividualFCs(inputFC, outputWorkspace, fieldName, bufferAmount, inputWhereClause=None): """Buffers each feature in the input feature class and creates a new feature class for each buffered feature. Specify a WHERE clause to specify which features should be processed.""" arcpy.env.overwriteOutput = True # Overwrite outputs if they already exist desc = arcpy.Describe(inputFC) oidField = desc.OIDFieldName # Get the name of the ObjectID field so we can copy individual features oidFieldDelimited = arcpy.AddFieldDelimiters(inputFC, oidField) # Add field delimiters outside of the loop since it could be expensive rows = arcpy.SearchCursor(inputFC, inputWhereClause) # Create a cursor with which we can loop over the input features tempFC = r"in_memory\temp" # Designate a temporary feature class. In this case we use the in-memory workspace for row in rows: # Loop over the input features whereClause = "%s = %d" % (oidFieldDelimited, row.getValue(oidField)) # Construct a WHERE clause for the current feature's ObjectID arcpy.FeatureClassToFeatureClass_conversion(inputFC, os.path.dirname(tempFC), os.path.basename(tempFC), whereClause) # Copy the current feature to the temporary feature class outputFCName = "%s_%s_Buffer" % (os.path.basename(inputFC), str(row.getValue(fieldName))) # Construct the name of the output feature class outputFCPath = os.path.join(outputWorkspace, outputFCName) # Construct the full path of the output feature class arcpy.Buffer_analysis(tempFC, outputFCPath, bufferAmount) # Buffer the temporary feature class and write it to the output feature class if arcpy.Exists(tempFC): arcpy.Delete_management(tempFC) # Clean up the temporary workspace if __name__ == "__main__": inputFC = r"C:\GISData\test.gdb\control" outputGDB = r"C:\GISData\buffertest.gdb" fieldName = "ID" bufferAmount = "200 feet" inputWhereClause = '"CONTROL_ID" IN(1, 2)' bufferFeaturesToIndividualFCs(inputFC, outputGDB, fieldName, bufferAmount, inputWhereClause)
arcpy.MakeFeatureLayer_management(Jurs_dis, "JurLyr") rows = arcpy.SearchCursor("JurLyr", "", "", "Jur_Name", "") arcpy.MakeFeatureLayer_management(parcels, "parcLyr") for row in rows: arcpy.SelectLayerByLocation_management("parcLyr", "HAVE_THEIR_CENTER_IN", "JurLyr", "", "NEW_SELECTION") arcpy.CalculateField_management("parcLyr", "Dist", "%s") %(row.Jur_Name)