-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaxEntRasterPrep.py
65 lines (53 loc) · 2.15 KB
/
MaxEntRasterPrep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# MaxEntRasterPrep.py
# Created on: 2016-08-26 14:20:03.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: MaxEntRasterPrep <Input_Raster_Layer> <OutputRaster_asc> <nlcd270_asc>
# Description:
# ---------------------------------------------------------------------------
# Script to be used in ArcGIS as a Tool - User will need to setup parameters.
# Import arcpy module
import arcpy
import os
import sys
import string
from arcpy import env
arcpy.env.overwriteOutput = True
# Script arguments
Input_Raster_Folder = arcpy.GetParameterAsText(0)
# #Input_Raster_Folder = r"C:\Users\Dorn\SharePoint\WHCR Migration Stopover Habit - Dat\bio_30s_esri\bio"
Output_Raster_Folder = arcpy.GetParameterAsText(1)
# #OutputRaster_asc = arcpy.GetParameterAsText(1)
# #nlcd270_asc = arcpy.GetParameterAsText(2)
# if nlcd270_asc == '#' or not nlcd270_asc:
# nlcd270_asc = "C:\\Users\\Dorn\\SharePoint\\WHCR Migration Stopover
# Habit - Dat\\Maxent\\layers\\nlcd270.asc" # provide a default value if
# unspecified
Output_Template_Raster = arcpy.GetParameterAsText(2)
descTemplate = arcpy.Describe(Output_Template_Raster)
cellRaster = descTemplate.meanCellWidth
# arcpy.env.cellSize =Output_Template_Raster
# OutputPrefix
OutputPrefix = arcpy.GetParameterAsText(3)
# Preamble
arcpy.env.workspace = Input_Raster_Folder
tempEnvironment0 = arcpy.env.snapRaster
arcpy.env.snapRaster = Output_Template_Raster
tempEnvironment1 = arcpy.env.extent
arcpy.env.extent = Output_Template_Raster
# Process Layers
rList = arcpy.ListRasters()
count_rasters = len(rList)
i = 1
for r in rList:
arcpy.AddMessage(
"Processing Raster layer {0} of {1}.".format(i, count_rasters))
# Process: Resample
arcpy.Resample_management(r, "temp{0}".format(r), cellRaster, "MAJORITY")
# Process: Raster to ASCII
arcpy.RasterToASCII_conversion("temp{0}".format(
r), "{1}\\{2}{0}.asc".format(r, Output_Raster_Folder, OutputPrefix))
i = i+1
arcpy.AddMessage("New layer {0}{1}.asc created.".format(OutputPrefix, r))
arcpy.AddMessage("ASCii files created in {0}".format(Output_Raster_Folder))