# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Polygons_to_Thiessen_v2.py
# Created on: 2018-05-05 18:31:27.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: Polygons_to_Thiessen_v2 <Input_Polygons> <Inside> <Final_Output>
# Description:
# Polygons --> centroids --> Thiessen Polygons
# ---------------------------------------------------------------------------

# Set the necessary product code
# import arcinfo


# Import arcpy module
import arcpy

# Script arguments
Input_Polygons = arcpy.GetParameterAsText(0)

Inside = arcpy.GetParameterAsText(1)
if Inside == '#' or not Inside:
    Inside = True # provide a default value if unspecified

Final_Output = arcpy.GetParameterAsText(2)

# Local variables:
Output_Centroids = ""
ThiessanPolygons = ""
Polygonal_Bounday = ""

# Set Geoprocessing environments
arcpy.env.outputCoordinateSystem = "GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"
arcpy.env.cellSize = "MAXOF"
arcpy.env.geographicTransformations = ""
arcpy.env.mask = Polygonal_Bounday

# Process: Create Centroids
arcpy.FeatureToPoint_management(Input_Polygons, Output_Centroids, Inside)

# Process: Create Thiessen Polygons
arcpy.CreateThiessenPolygons_analysis(Output_Centroids, ThiessanPolygons, "ONLY_FID")

# Process: Dissolve
arcpy.Dissolve_management(Input_Polygons, Polygonal_Bounday, "", "", "MULTI_PART", "DISSOLVE_LINES")

# Process: Clip
arcpy.Clip_analysis(ThiessanPolygons, Polygonal_Bounday, Final_Output, "")

