This script has several parts:

  1. Select by location grid elements that overlap a specific feature class.
  2. Use a search cursor to create a list of DEMs from a field in the grid layer.
  3. Mosaic to new raster using the list of DEMs as input.
  4. Clip the newly created mosaic to the shape of the feature class.
  5. Project the clipped mosaic.
  6. Create contours.

Currently I'm getting this error message:

ExecuteError: Failed to execute. Parameters are not valid.

Undefined coordinate system for input dataset.

Failed to execute (ProjectRaster).

I'm still somewhat novice at coding.

Does anyone have experience doing something similar to this?

import arcpy
import arcpy.sa

arcpy.env.overwriteOutput = True
prj = r"C:\Desktop\NAD_1983_UTM_Zone_14N.prj"
InputGrid =r"S:\NED_10Meter_2010\metadata\NED_1_3_arcsec_Tiles.shp"

# Create Grid
GridLyr = arcpy.mapping.Layer(InputGrid)
NEDlist = []
fc = r"C:\Desktop\ContourTesting\Output\Area.shp"

arcpy.SelectLayerByLocation_management(GridLyr, 'INTERSECT', fc)
destination = r"C:\Desktop\ContourTest.gdb"
cursor = arcpy.da.SearchCursor(GridLyr, ["NAME"])
for row in cursor:   
    Path = r"S:\NED_10Meter_2010\grid" +"\\" + row[0][3:10] + "\\" + row[0]
arcpy.MosaicToNewRaster_management(NEDlist, destination, "Area_mosaic_tif", "", "32_BIT_FLOAT", "", "1")
arcpy.env.workspace = r"C:\Users\Desktop\Area_contour.gdb"
arcpy.Clip_analysis ("Rosebud_mosaic_tif", fc, "Area_mosaic_clip")
mosaic_tif = arcpy.ProjectRaster_management("Area_mosaic_clip", "Mosaic_project", prj, "CUBIC")
arcpy.gp.Contour_sa(mosaic_tif, "Script_contour", "10", "0", "1")
arcpy.Clip_analysis ("Script_contour", fc, "Area_mosaic_clip")
  • 1
    Instead of using a string "Mosaic_project" give it a genuine path like os.path.join(os.environ.get("tmp"),"Mosaic_project.tif"). Your mosaic_tif would be a geoprocessing result object not a raster. What is your workspace? I can see you're not giving full paths to a lot of your intermediaries. – Michael Stimson Jun 13 '17 at 22:28
  • You'd want to set that to a variable: mosaic_tif = os.path.join(os.environ.get("tmp"),"Mosaic_project.tif") then in project raster arcpy.ProjectRaster_management("Area_mosaic_clip", mosaic_tif , prj,.. – Michael Stimson Jun 13 '17 at 22:34
  • I assumed that by setting my workspace (arcpy.env.workspace = r"C:\Users\Desktop\Area_contour.gdb") that I didn't need to give full paths to my intermediary data. I'll assume that isn't the best way? – sd1272 Jun 13 '17 at 22:35
  • @MichaelMiles-Stimson, ok, I tried your suggestion above. I am still getting the same error message. Is there anything else I should try? – sd1272 Jun 13 '17 at 22:56
  • 1
    Perhaps prj = arcpy.SpatialReference(26914) but what's your in_coor_system? Yes, if you set your workspace you don't need full paths but GDB raster isn't the best format; the line that sets your workspace isn't in your code sample. You could follow the project raster by DefineProjection_management (mosaic_tif,prj) to enforce the spatial reference. It would be odd for the output spatial reference not to be set but if the input doesn't have a spatial reference the raster isn't projected at all and the output would be undefined also. – Michael Stimson Jun 13 '17 at 23:18