Select to view content in your preferred language

I want to create a few geoprocesses for each of the rows in a feature

1066
2
Jump to solution
09-21-2012 08:00 PM
OLANIYANOLAKUNLE
Frequent Contributor
I want to create a few geoprocesses for each of the rows in a feature, so that a row gets worked on at a time then when the operations is finished it moves on to the next row till it gets to the last row, I used the script below but its not working; it creates the buffer for all the features first before moving to the next geoprocessing operation instead of creating the output of the two geoprocesses first then move to the next row. Please what im I doing wrong. Thank you.

fc = 'C:/Users/Administrator/Documents/ArcGIS/Default.gdb/Test' field = "OBJECTID" with arcpy.da.SearchCursor(fc, (field)) as cursor: ...     for row in cursor: ...         arcpy.Buffer_analysis("Test", "DataDrivenPage_Bufferz", "14 meters", "FULL", "ROUND", "NONE")      arcpy.Clip_analysis("DataDrivenPage_Bufferz","Test","dd")
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
OLANIYANOLAKUNLE
Frequent Contributor
Thanks i got the solution for my issues;

See code below


mxd = arcpy.mapping.MapDocument("Current")         df = arcpy.mapping.ListDataFrames(mxd)[0]         fc = 'Database Connections/TDPMode.sde/KWAGISMAIN.DBO.Parcels'         field = "OBJECTID"         field1 = "LGA"         field2 = "District"         field3 = "Block_No"         field4 = "Plot_No"         rows = arcpy.SearchCursor(fc)         row = rows.next()         while row:             val = row.getValue(field)             val1 = row.getValue(field1)             val2 = row.getValue(field2)             val3 = row.getValue(field3)             val4 = row.getValue(field4)             whereClause = '"OBJECTID"' + " = '" + str(val) + "'"             outName = "Block_" + str(val3) + "_Plot_" + str(val4) + "_" + str(val2) + "_Area_of_" + str(val1) + "_LGA" + ".pdf"             path = "C:/Users/Administrator/Documents/ArcGIS/Default.gdb/"             arcpy.SelectLayerByAttribute_management("Parcels", "NEW_SELECTION", whereClause)             arcpy.Buffer_analysis ("Parcels", "DataDrivenPage_Buffer", "14 meters", "FULL", "ROUND", "NONE")             layer_list = "Lines","Parcels","Access_Road_Graphics","Points","Lines_Split"             for layer in layer_list:                 arcpy.SelectLayerByLocation_management(layer, "COMPLETELY_WITHIN", "DataDrivenPage_Buffer", "", "NEW_SELECTION")             exportLayer = "Points", "Lines", "Parcels","Lines_Split","Access_Road_Graphics"             for layer in exportLayer:                 outFC = path + layer + "_New"                  arcpy.Clip_analysis(layer,"DataDrivenPage_Buffer",outFC)                 arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")             mxd = arcpy.mapping.MapDocument("current")             lyr = arcpy.mapping.ListLayers(mxd, "Lines_New")[0]             for lblClass in lyr.labelClasses:                 lblClass.SQLQuery = '"ParcelID"' + "=" + str(val)                  arcpy.RefreshActiveView()             arcpy.SelectLayerByAttribute_management("DataDrivenPage_Buffer", "NEW_SELECTION", "OBJECTID = 1")             df.zoomToSelectedFeatures()             mxd = arcpy.mapping.MapDocument("Current")             for df in arcpy.mapping.ListDataFrames(mxd):                 df.rotation = 0             if df.scale <= 400:                  df.scale = 500             if df.scale > 400 and df.scale < 1000:                 df.scale = 1000                 else:                  df.scale = 2000             arcpy.mapping.ExportToPDF(mxd,r"C:\STATE\\Batch\\" + "TDP_For_" + outName)             row = rows.next()


I think i'm improving....:D

View solution in original post

0 Kudos
2 Replies
MarcinGasior
Frequent Contributor
If you want to use single geometry in geoprocessing tools, you have to define it first in a FOR loop:
for row in cursor:
    singleGeom = row.Shape

then use singleGeom variable in a tool as an input:
arcpy.Buffer_analysis(singleGeom,...)
0 Kudos
OLANIYANOLAKUNLE
Frequent Contributor
Thanks i got the solution for my issues;

See code below


mxd = arcpy.mapping.MapDocument("Current")         df = arcpy.mapping.ListDataFrames(mxd)[0]         fc = 'Database Connections/TDPMode.sde/KWAGISMAIN.DBO.Parcels'         field = "OBJECTID"         field1 = "LGA"         field2 = "District"         field3 = "Block_No"         field4 = "Plot_No"         rows = arcpy.SearchCursor(fc)         row = rows.next()         while row:             val = row.getValue(field)             val1 = row.getValue(field1)             val2 = row.getValue(field2)             val3 = row.getValue(field3)             val4 = row.getValue(field4)             whereClause = '"OBJECTID"' + " = '" + str(val) + "'"             outName = "Block_" + str(val3) + "_Plot_" + str(val4) + "_" + str(val2) + "_Area_of_" + str(val1) + "_LGA" + ".pdf"             path = "C:/Users/Administrator/Documents/ArcGIS/Default.gdb/"             arcpy.SelectLayerByAttribute_management("Parcels", "NEW_SELECTION", whereClause)             arcpy.Buffer_analysis ("Parcels", "DataDrivenPage_Buffer", "14 meters", "FULL", "ROUND", "NONE")             layer_list = "Lines","Parcels","Access_Road_Graphics","Points","Lines_Split"             for layer in layer_list:                 arcpy.SelectLayerByLocation_management(layer, "COMPLETELY_WITHIN", "DataDrivenPage_Buffer", "", "NEW_SELECTION")             exportLayer = "Points", "Lines", "Parcels","Lines_Split","Access_Road_Graphics"             for layer in exportLayer:                 outFC = path + layer + "_New"                  arcpy.Clip_analysis(layer,"DataDrivenPage_Buffer",outFC)                 arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")             mxd = arcpy.mapping.MapDocument("current")             lyr = arcpy.mapping.ListLayers(mxd, "Lines_New")[0]             for lblClass in lyr.labelClasses:                 lblClass.SQLQuery = '"ParcelID"' + "=" + str(val)                  arcpy.RefreshActiveView()             arcpy.SelectLayerByAttribute_management("DataDrivenPage_Buffer", "NEW_SELECTION", "OBJECTID = 1")             df.zoomToSelectedFeatures()             mxd = arcpy.mapping.MapDocument("Current")             for df in arcpy.mapping.ListDataFrames(mxd):                 df.rotation = 0             if df.scale <= 400:                  df.scale = 500             if df.scale > 400 and df.scale < 1000:                 df.scale = 1000                 else:                  df.scale = 2000             arcpy.mapping.ExportToPDF(mxd,r"C:\STATE\\Batch\\" + "TDP_For_" + outName)             row = rows.next()


I think i'm improving....:D
0 Kudos