1

I have a task of extracting raster values to point shapefiles, which is simple enough, but only where the raster filename is identical to the shapefile. For example, I have shapefiles "G1", "G2", "G3", and "G4" and I need to extract the values of rasters "G1", "G2", "G3", and "G4" to their corresponding shapefile.

Using Python (or Arc), is there a way I can convey this condition and automate the process?

3

Yes, you can automate this process.

  1. Create a list of rasters
  2. Start a loop and within that loop strip the ".tif" off the file name and replace with ".shp"
  3. Check to make sure the shapefile exists that corresponds to the raster
  4. Extract the raster values to the points

import arcpy, os
from arcpy.sa import *

arcpy.env.workspace = r'C:\Temp\rasters'
shp_ws = r'C:\Temp\shapefiles'

rasters = arcpy.ListRasters()

for ras in rasters:
    shp = ras.replace(".tif", ".shp")
    if arcpy.Exists(os.path.join(shp_ws, shp)):
        ExtractMultiValuesToPoints(os.path.join(shp_ws, shp), ras)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.