# import arcinfo
# Import arcpy module
import arcpy
from arcpy import env # Analysis environment
from arcpy.sa import *
arcpy.env.overwriteOutput = True #enable output
# Import sys, os, glob modules
import sys
sys.path.append('C:/Python26/ArcGIS10.0/Lib/')
import os
import glob
# Set Geoprocessing environments
env.scratchWorkspace = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\workspace/"
env.workspace = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\workspace/"
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
# inputdir
inDir = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_input/"
OutDir = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_output/"
OutDir2 = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_output2/"
# scan files to process
fileList = glob.glob(inDir + "pt*.asc")
# filename starts at
fileStart = fileList[0].rfind('\\')+1
#loop
for inPut in fileList:
print("processing " + inPut[fileStart::1])
#input
inPutWater = inDir + inPut[fileStart::1]
outPut = OutDir + "water_goed" + inPut[fileStart+2:-4:1]
outPut2 = OutDir2 + "water_fout" + inPut[fileStart+2:-4:1]
# Script arguments
Blok_asc = arcpy.GetParameterAsText(3)
if Blok_asc == '#' or not Blok_asc:
Blok_asc = "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_input/"
Select_no_value_area = arcpy.GetParameterAsText(0)
if Select_no_value_area == '#' or not Select_no_value_area:
Select_no_value_area = "\"GRIDCODE\" = 1" # provide a default value if unspecified
Area = arcpy.GetParameterAsText(1)
if Area == '#' or not Area:
Area = "10 Unknown" # provide a default value if unspecified
Select_areas_ = arcpy.GetParameterAsText(2)
if Select_areas_ == '#' or not Select_areas_:
Select_areas_ = "\"F_AREA\" > 40" # provide a default value if unspecified
# Local variables:
# ASCIITo_01301 = env.workspace + "/Blok_asc.asc"
Output_raster = env.workspace + "/ASCIITo_asc9.asc"
ASCIITo_asc9 = env.workspace + "/Blok_asc.asc"
RasterT_IsNull_2_shp = env.workspace + "/Output_raster.shp"
RasterT_IsNull_1_Select = env.workspace + "/Select_no_value_area.asc"
Output_Feature_Class__2_ = env.workspace + "/RasterT_IsNull_1_Select.shp"
Output_Feature_Class = env.workspace + "/Output_Feature_Class__2_.shp"
# output
Output_Feature_Class__3_ = OutDir + "/output.shp"
# Process: ASCII to Raster
arcpy.ASCIIToRaster_conversion(Blok_asc, ASCIITo_asc9, "INTEGER")
# Process: Is Null
arcpy.gp.IsNull_sa(ASCIITo_asc9, Output_raster)
# Process: Raster to Polygon
arcpy.RasterToPolygon_conversion(Output_raster, Block_asc, "NO_SIMPLIFY", "VALUE")
# Process: Select
arcpy.Select_analysis(Block_asc, RasterT_IsNull_1_Select, Select_no_value_area)
# Process: Calculate Areas
arcpy.CalculateAreas_stats(RasterT_IsNull_1_Select, Output_Feature_Class__2_)
# Process: Select (2)
arcpy.Select_analysis(Output_Feature_Class__2_, Output_Feature_Class, Select_areas_)
# Process: Eliminate Polygon Part
arcpy.EliminatePolygonPart_management(Output_Feature_Class, Output_Feature_Class__3_, "AREA", Area, "0", "CONTAINED_ONLY")
if isEmpty(Output_Feature_Class__3_):
arcpy.Copy_management(Output_Feature_Class__3_, outPut, "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_output/")
else:
arcpy.Copy_management(Output_Feature_Class__3_, outPut2, "t:\U12002_Afstuderen_Daisy_en_Tiemco\Praktijk_water]\Test_1_DS\No_value_areas\Py_output2/")