AnsweredAssumed Answered

Extract Values to Points Script

Question asked by mtgis on Jan 18, 2012
Latest reply on Jan 18, 2012 by mtgis
Hi All - I'm hoping that someone maybe able to help.  I have a shapefile with an attribute table that has a column named "YearMonth".  In this column each row has a value like this "1975_01", "1975_02", "1975_03" etc,.  These names are identical to filenames I have for a series of rasters.  My goal is to be able to create a python script that will read through each of these rows, check to see if that row matches with the name of the raster that I have in the same directory and execute the Extract Values to Points tool on the points where the "YearMonth" column matches that of the raster filename.  Below is my attempt at this script.  Although the tool ran fine the output shapefile had incorrect values.  I was wondering if anybody could help me identify the problem in this script and possibly pass along any ideas on how to reach my goal.  Your help is much appreciated.  Thanks! 

import arcpy from arcpy import env from arcpy.sa import * import os import string  #Check out Spatial Analyst Extension arcpy.CheckOutExtension("Spatial") env.overwriteOutput = "True"  workspace = "D:/FWP/GIS/Precipitation/" shp = "D:/FWP/GIS/Precipitation/Bridger.shp" outshp = "D:/FWP/GIS/Precipitation/ExtractValuesToPoints/"  env.workspace = workspace rows = arcpy.SearchCursor(shp) for row in rows:     yearmonth = row.YearMonth     for raster in arcpy.ListRasters():         x = raster[4:11]         if x == yearmonth:             ExtractValuesToPoints(shp, raster, outshp + "extractedbridger"+ ".shp")             print yearmonth + " " + raster print "done"     

Outcomes