text: #G:\NHLD\GIS_DATA\NHLD_GIS_Data_FINAL\Arcpy_Scripts\NHLD_GIS_01_Lakeset_Point_ExtractElevVal_CopyLakeset_JoinRastVal_ElmIslands_CalcPA_MBG_CalcW.py
  
  # -*- coding: utf-8 -*-
  # ---------------------------------------------------------------------------
  # test.py
  # Created on: 2016-10-19 15:58:49.00000
  #   (generated by ArcGIS/ModelBuilder)
  # Description:
  # ---------------------------------------------------------------------------
  
  # Set the necessary product code
  # import arcinfo
  
  
  # Import arcpy module
  import arcpy
  arcpy.env.overwriteOutput=True
  
  # Check out any necessary licenses
  arcpy.CheckOutExtension("spatial")
  
  print("Local Variables Defined")
  # Local variables:
  Loc = "G"
  NHLDandBuffLakes = Loc+ ":\\NHLD\\GIS_DATA\\NHLD_GIS_Data_FINAL\\NHLDandBuffLakes\\NHLDandBuffLakes_Rev2.shp"
  NHLD_DEMs_1_3_mosaic_img = Loc+ ":\\NHLD\\GIS_DATA\\NHLD_GIS_Data_FINAL\\NHLD_DEM\\NHLD_DEMs_1_3_mosaic.img"
  NHLDandBuffLakes_InsidePoint_shp = Loc+ ":\\NHLD\\GIS_DATA\\NHLD_GIS_Data_FINAL\\NHLDandBuffLakes\\NHLDandBuffLakes_InsidePoint.shp"
  NHLDandBuffLakes_InsidePoint_ElevVal_shp = Loc+ ":\\NHLD\\GIS_DATA\\NHLD_GIS_Data_FINAL\\NHLDandBuffLakes\\NHLDandBuffLakes_InsidePoint_ElevVal.shp"
  NHLDandBuffLakes_ElevVal_shp = Loc+ ":\\NHLD\\GIS_DATA\\NHLD_GIS_Data_FINAL\\NHLDandBuffLakes\\NHLDandBuffLakes_ElevVal.shp"
  NHLDandBuffLakes_ElevVal_ElmIslands_shp = Loc+ ":\\NHLD\\GIS_DATA\\NHLD_GIS_Data_FINAL\\NHLDandBuffLakes\\NHLDandBuffLakes_ElevVal_ElmIslands.shp"
  NHLDandBuffLakes_ElevVal_ElmIslands_MBG_box_shp = Loc+ ":\\NHLD\\GIS_DATA\\NHLD_GIS_Data_FINAL\\NHLDandBuffLakes\\NHLDandBuffLakes_ElevVal_ElmIslands_MBG_box.shp"
  NHLDandBuffLakes_ElevVal_ElmIslands_MBG_shp = Loc+ ":\\NHLD\\GIS_DATA\\NHLD_GIS_Data_FINAL\\NHLDandBuffLakes\\NHLDandBuffLakes_ElevVal_ElmIslands_MBG.shp"
  
  # One issue that came to mind was that the elevation values taken from the DEM could potentially on an island within the lake.
  # However, the final lakeset has holes within the lake polygons so when asked to perform FeatureToPoint "INSIDE"
  # it will never be on an island. The elevations reported will for sure be representative of the lake water level at the aquisition time of the DEM data
  
  print("Process: Feature To Point")
  # Process: Feature To Point
  arcpy.FeatureToPoint_management(NHLDandBuffLakes, NHLDandBuffLakes_InsidePoint_shp, "INSIDE")
  
  print("Process: Extract Values to Points")
  # Process: Extract Values to Points
  arcpy.gp.ExtractValuesToPoints_sa(NHLDandBuffLakes_InsidePoint_shp, NHLD_DEMs_1_3_mosaic_img, NHLDandBuffLakes_InsidePoint_ElevVal_shp, "NONE", "VALUE_ONLY")
  
  print("Process: Copy Features (_ElevVal)")
  # Process: Copy Features
  arcpy.CopyFeatures_management(NHLDandBuffLakes, NHLDandBuffLakes_ElevVal_shp, "", "0", "0", "0")
  
  print("Process: Join Field (RASTERVALU)")
  # Process: Join Field
  arcpy.JoinField_management(NHLDandBuffLakes_ElevVal_shp, "Permanent_", NHLDandBuffLakes_InsidePoint_ElevVal_shp, "Permanent_", "RASTERVALU")
  
  print("Process: Eliminate Polygon Part (_ElmIslands)")
  # Process: Eliminate Polygon Part (Eliminate Lake Islands, also creates solid polygon without interior holes) (Lakes on islands within lakes will be removed in later script)
  arcpy.EliminatePolygonPart_management(NHLDandBuffLakes_ElevVal_shp, NHLDandBuffLakes_ElevVal_ElmIslands_shp, "PERCENT", "", "99.9", "CONTAINED_ONLY")
  
  print("Calc New Perim, Area, WALA after islands have been removed from the lake shapes")
  #Add Field Perim_m_1
  # Process: Add Field
  arcpy.AddField_management(NHLDandBuffLakes_ElevVal_ElmIslands_shp, "Perim_m_1", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
  #Calc Field Perim_m_1
  arcpy.CalculateField_management(NHLDandBuffLakes_ElevVal_ElmIslands_shp, "Perim_m_1","!shape.geodesicLength@meters!","PYTHON_9.3")
  
  #Add Field Area_m2_1
  arcpy.AddField_management(NHLDandBuffLakes_ElevVal_ElmIslands_shp, "Area_m2_1", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
  #Calc Field Area_m2_1
  arcpy.CalculateField_management(NHLDandBuffLakes_ElevVal_ElmIslands_shp, "Area_m2_1","!shape.geodesicArea@squaremeters!","PYTHON_9.3")
  
  #Add Field WALA_1
  arcpy.AddField_management(NHLDandBuffLakes_ElevVal_ElmIslands_shp, "WALA_1", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
  #Calc WALA_1
  arcpy.CalculateField_management(NHLDandBuffLakes_ElevVal_ElmIslands_shp, "WALA_1","[WALA_0] *([Area_m2_0]/ [Area_m2_1])", "VB", "") #IF Area_m2_1 > Area_m2_0 then WALA_1 < WALA_0
  
  
  print("Process: Minimum Bounding Geometry")
  # Process: Minimum Bounding Geometry
  arcpy.MinimumBoundingGeometry_management(NHLDandBuffLakes_ElevVal_ElmIslands_shp, NHLDandBuffLakes_ElevVal_ElmIslands_MBG_box_shp, "RECTANGLE_BY_WIDTH", "NONE", "", "MBG_FIELDS")
  
  print("Process: Copy Features (_MBG)")
  # Process: Copy Features
  arcpy.CopyFeatures_management(NHLDandBuffLakes_ElevVal_ElmIslands_shp, NHLDandBuffLakes_ElevVal_ElmIslands_MBG_shp, "", "0", "0", "0")
  
  print("Process: Join Field (MBG_Width;MBG_Length)")
  # Process: Join Field
  arcpy.JoinField_management(NHLDandBuffLakes_ElevVal_ElmIslands_MBG_shp, "Permanent_", NHLDandBuffLakes_ElevVal_ElmIslands_MBG_box_shp, "Permanent_", "MBG_Width;MBG_Length")
  
  print("Process: Width_m_est")
  #Add Field Width_m_est
  arcpy.AddField_management(NHLDandBuffLakes_ElevVal_ElmIslands_MBG_shp, "Width_m_1", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
  #Calc Width_m_est
  arcpy.CalculateField_management(NHLDandBuffLakes_ElevVal_ElmIslands_MBG_shp, "Width_m_1", "( [Perim_m_1] /3.14)*( [Area_m2_1] /(( [Perim_m_1] ^2)/(4*3.14)))", "VB", "") #width_est = width(perim)*(Area/Area(perim)) #Using Area and perim of lake, makes to a circular lake and estimates the width
  
  print("Script Completed")