#-------------------------------------------------------------------------------
# Name: Exercise 5
# Purpose: To clip raster images to the Trempealeau County boundary for future use.
#
# Author: Kiersten Bauer
#
# Created: 08/03/2017
#-------------------------------------------------------------------------------
#import system modules and Spatial Analyst
import arcpy
from arcpy import env
from arcpy.sa import *
#Check out the Spatial Analyst extension (must be available to check out!)
arcpy.CheckOutExtension("spatial")
#set environment settings
arcpy.env.workspace =
"Q:\StudentCoursework\CHupy\GEOG.337.001.2175\BAUERKIE\Labs\Exercises\Ex5\DatasetRastS"
arcpy.env.overwriteOutput = True
print "{}".format(env.workspace)
#get a list of rasters in the workspace
listOfRasters = arcpy.ListRasters()
print "{}".format(listOfRasters)
#loop through the rasters in the loop
for raster in listOfRasters:
#define the outputs
rasterOut = '{}_Out.tif'.format(raster)
rasterExtract = '{}_Extract.tif'.format(raster)
#project the rasters
arcpy.ProjectRaster_management(raster, rasterOut, "Q:\StudentCoursework\CHupy\GEOG.337.001.2175\BAUERKIE\Labs\Exercises\Ex5\DatasetRastS\TrempWebDATA.gdb\Boundaries\County_Boundary")
#Extract the rasters and copy the raster into the geodatabase
outExtractByMask = ExtractByMask(rasterOut, 'Q:\StudentCoursework\CHupy\GEOG.337.001.2175\BAUERKIE\Labs\Exercises\Ex5\DatasetRastS\TrempWebDATA.gdb\Boundaries\County_Boundary')
outExtractByMask.save(rasterExtract)
arcpy.RasterToGeodatabase_conversion(rasterExtract, 'Q:\StudentCoursework\CHupy\GEOG.337.001.2175\BAUERKIE\Labs\Exercises\Ex5\DatasetRastS\TrempWebDATA.gdb')
print "Raster to Geodatabase conversion {} sucessful".format(rasterExtract)
print "The script is complete"
No comments:
Post a Comment