stevedugdale

How do I process points individually in shapefile containing multiple points?

Discussion created by stevedugdale on Jun 6, 2012
Latest reply on Jun 6, 2012 by jskinner-esristaff
Hi,
This is my first attempt at using python.

I have a shapefile containing mutiple points and need to create an output raster where surrounding cells are given the euclidean distance to a specific point (i.e. NOT the nearest point).  If a tool is used manually from ArcToolbox it only processes selected records.  I have made two attempts (see code below) to select each record in turn using the FID field, and a loop through each record in turn.  However, although it runs and generates a raster for each iteration of the loop, all the output files are identical  (i.e. euclidean distance to NEAREST feature is calculated rather than euclidean distance to a single feature as selected in the loop).  It appears that the record is not "selected" when running my python script.

I tried two methods of attempting to process a single record at a time. 

count = 0

for row in rows:
     count = count + 1
     # print "ITERATION COUNT = " + count
     # print "FID = " + row.FID
    
     print count
     print row.FID

     #build the name of output raster: directory + filename HHxxxx_EucD where xxxx is the value of field FID in the input shapefile
     outRaster = os.path.join(outRasterDir, "HH" + str(row.FID) + "_EucD1k")

     # Temporary line below to display outraster filename and path (for debugging)
     print outRaster
           
     # Execute EucDistance
     # MAY NEED TO REMOVE PARAMETER outDirectionRaster FROM LINE BELOW AS DIRECTION RASTER IS NOT REQUIRED AND IS AN OPTIONAL PARAMETER
     # outEucDist = EucDistance(inSourceData, maxDistance, cellSize, outDirectionRaster)
     outEucDist = EucDistance(inSourceData, maxDistance, cellSize)
    

     # Save the output
     outEucDist.save(outRaster)


and the second came from another thread as mentioned in comment in code below:

# Need to process only the selected record - See http://forums.arcgis.com/threads/8428-Setting-a-Single-Record-to-Selected-with-Python
# for source of baseline code that follows

lookupDict = {}
searchRows = gp.searchcursor(inSourceData)
searchRow = searchRows.next()
while searchRow:
   lookupDict[searchRow.FID] = [searchRow.FID]
   count = count + 1
     # print "ITERATION COUNT = " + count
     # print "FID = " + row.FID
    
   print count
   print searchRow.FID

     #build the name of output raster: directory + filename HHxxxx_EucD where xxxx is the value of field FID in the input shapefile
   outRaster = os.path.join(outRasterDir, "HH" + str(searchRow.FID) + "_EucD1k")

     # Temporary line below to display outraster filename and path (for debugging)
   print outRaster
           
     # Execute EucDistance
     # MAY NEED TO REMOVE PARAMETER outDirectionRaster FROM LINE BELOW AS DIRECTION RASTER IS NOT REQUIRED AND IS AN OPTIONAL PARAMETER
     # outEucDist = EucDistance(inSourceData, maxDistance, cellSize, outDirectionRaster)
   outEucDist = EucDistance(inSourceData, maxDistance, cellSize)
    

     # Save the output
   outEucDist.save(outRaster)

Any ideas on how to loop through a shapefile one record at a time, use the selected single feature as the input file, generate and save an output raster for the euclidean distance from that single feature and then move onto the next feature etc.?

Any suggestions will be greatly appreciated.

Many thanks

Steve

Outcomes