AnsweredAssumed Answered

Use row as input to other processes in python

Question asked by CareysDrum on Dec 5, 2014
Latest reply on Dec 5, 2014 by jonesgeorge

I am new to python and need help. Looked for my answer but don't know if I am even using the correct terminology.

I have a model in which I iterated through rows and performed a set of processes on each. For example a feature class with 10 features and on each of the 10 features I wanted to create an individual feature class....or... for each row create a raster based on the field (e.g.) ID. I am trying to turn this to python due to a host of reasons.

Here is what I have so far, but I cannot get it to work. Any help would be appreciated.

 

# Import arcpy module
print "Starting...."
import arcpy
from arcpy import env

# Check out any necessary licenses
arcpy
.CheckOutExtension("spatial")
env
.overwriteOutput = True

selectingfeatures
= "\\\\silver\\clients\\SYN\\Projects\\P696\\8_BaseMine\\Processing\\TEMP\\trans1.shp"
Trans1_shp = "\\\\silver\\clients\\SYN\\Projects\\P696\\8_BaseMine\\Processing\\TEMP\\trans1.shp"
basecldem
= "\\\\silver\\clients\\SYN\\Projects\\P696\\8_BaseMine\\Data\\From_Client\\20141023_DataDumpFromBrent\\ClosureSurface\\basecldem"
TEMP
= "\\\\silver\\clients\\SYN\\Projects\\P696\\8_BaseMine\\Processing\\TEMP"
Zone3_shp = "\\\\silver\\clients\\SYN\\Projects\\P696\\8_BaseMine\\Processing\\TEMP\\Zone2.shp"
transarea
= "\\\\silver\\clients\\SYN\\Projects\\P696\\8_BaseMine\\Processing\\TEMP\\transarea"
RegionGRP = "\\\\silver\\clients\\SYN\\Projects\\P696\\8_BaseMine\\Processing\\TEMP\\regiongrp"
ZonalMean = "\\\\silver\\clients\\SYN\\Projects\\P696\\8_BaseMine\\Processing\\TEMP\\zonalmean"
ZoneArea = "\\\\silver\\clients\\SYN\\Projects\\P696\\8_BaseMine\\Processing\\TEMP\\zonearea"
Transition__n_ = "\\\\silver\\clients\\SYN\\Projects\\P696\\8_BaseMine\\Processing\\TEMP\\transition_%n%"
I_trans1
= "I_trans1_FID"

selectingLayer
= arcpy.MakeFeatureLayer_management(selectingfeatures)
rows
= arcpy.SearchCursor(selectingLayer)
#cursor = arcpy.SearchCursor(fc)
#row = cursor.next()
#while row:
# print(row.getValue(field))
for row in rows:
  arcpy
.FeatureClassToFeatureClass_conversion(row, TEMP, "Zone2.shp", "", "ID \"ID\" true true false 4 Short 0 4 ,First,#,\\\\silver\\clients\\SYNCRUDE\\Projects\\P696\\8_BaseMine\\Processing\\TEMP\\trans1.shp,ID,-1,-1", "")
  
print "Finished PFC 2 FC...."
# Process: Polygon to Raster
  arcpy
.PolygonToRaster_conversion(Zone3_shp, "ID", ZoneArea, "CELL_CENTER", "NONE", "1")
  
print "Finished Polygon to Raster...."
# Process: Extract by Mask
  arcpy
.gp.ExtractByMask_sa(basecldem, Zone3_shp, transarea)
  
print "Extract by Mask...."
# Process: Region Group
  arcpy
.gp.RegionGroup_sa(ZoneArea, RegionGRP, "FOUR", "WITHIN", "ADD_LINK", "")
  
print "Finished Region Group...."
# Process: Zonal Statistics
  arcpy
.gp.ZonalStatistics_sa(RegionGRP, "VALUE", transarea, ZonalMean, "MEAN", "DATA")
  
print "Finished Zonal Statistics...."
# Process: Raster Calculator
  arcpy
.gp.RasterCalculator_sa("If( \"%basecldem%\" > ( 0.5 + \"%ZonalMean%\" ), 0, 1 )", Transition__n_)
  
print "Finished Raster Calcualtor"

Outcomes