##Add GSE_AllContours3D Featureclass to map. mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd)[0] FeatureClassToAdd = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\Contours_Daily_20130625_20130731.gdb\WSE_AllContours3D" InSymbologyLayer = "G:\Documents\GIS\HydstraData\Template_Contours.lyr" TempLayer = "WSE_Contours" # Make a layer from the feature class arcpy.MakeFeatureLayer_management(FeatureClassToAdd,TempLayer) addLayer = arcpy.mapping.Layer(TempLayer) arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE") arcpy.ApplySymbologyFromLayer_management(addLayer, InSymbologyLayer) arcpy.RefreshTOC()
Solved! Go to Solution.
import arcpy
import arcpy.mapping
import datetime
import os
arcpy.env.overwriteOutput = True
##Add GSE_AllContours3D Featureclass to map.
mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
FeatureClassToAdd = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\Contours_Daily_20130625_20130731.gdb\WSE_AllContours3D"
InSymbologyLayer = "G:\Documents\GIS\HydstraData\Template_Contours.lyr"
TempLayer = "WSE_Contours"
# Make a layer from the feature class
arcpy.MakeFeatureLayer_management(FeatureClassToAdd,TempLayer)
addLayer = arcpy.mapping.Layer(TempLayer)
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
for lyr in arcpy.mapping.ListLayers(mxd, "WSE_Contours", df):
arcpy.ApplySymbologyFromLayer_management(lyr, InSymbologyLayer)
arcpy.RefreshTOC()
mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, "WSE_Contours", df)
addLayer = arcpy.mapping.Layer(TempLayer) arcpy.ApplySymbologyFromLayer_management(addLayer, InSymbologyLayer) arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
import arcpy
import arcpy.mapping
import datetime
import os
def AddContours(DataType,LayerFileNameAndLocation):
Contours_lyr = arcpy.mapping.Layer(LayerFileNameAndLocation)
Contours_lyr.replaceDataSource(GeoDatabaseNameAndLocation,"NONE",DataType + "_AllContours3D")
if Contours_lyr.supports("LABELCLASSES"):
arcpy.AddMessage("LABELCLASSES are supported.")
Contours_lyr.labelClasses[0].expression = "[Contour]"
Contours_lyr.showLabels = True
if Contours_lyr.symbologyType == "GRADUATED_COLORS":
arcpy.AddMessage("GRADUATED_COLORS are supported.")
##Create a List of unique Contour values.
SortedContours = unique_values(Contours_lyr, "Contour")
arcpy.AddMessage(SortedContours)
LowestContour = SortedContours[0]
HighestContour = SortedContours[-1]
ContourInterval = SortedContours[1] - SortedContours[0]
TotalContours = len(SortedContours)
arcpy.AddMessage("Lowest contour: " + str(LowestContour))
arcpy.AddMessage("Highest contour: " + str(HighestContour))
arcpy.AddMessage("Contour Interval: " + str(ContourInterval))
arcpy.AddMessage("Number of Contours: " + str(TotalContours))
##Insert an additional contour before Lowest Contour.
SortedContours.insert(0,LowestContour - ContourInterval)
##arcpy.AddMessage(SortedContours)
##Increment Total Contours by 1.
TotalContours = TotalContours + 1
##Assign classBreakValues to SortedContours.
Contours_lyr.symbology.classBreakValues = SortedContours
##Reclassify Color Ramp.
Contours_lyr.symbology.reclassify()
##Create a string List of Sorted Contours for layer labels.
LabelList = [str(int(i)) for i in SortedContours]
##arcpy.AddMessage(LabelList)
##Delete first variable in LabelList.
##NOTE: This is important because the classBreakLabels MUST be one less than the classBreakValues.
del LabelList[0]
##arcpy.AddMessage(LabelList)
Contours_lyr.symbology.classBreakLabels = LabelList
arcpy.mapping.AddLayer(df,Contours_lyr,"BOTTOM")
return;
def unique_values(table, field):
with arcpy.da.SearchCursor(table, [field]) as cursor:
return sorted({row[0] for row in cursor})
GeoDatabaseNameAndLocation = arcpy.GetParameterAsText(0)
LayerFileNameAndLocation_Wells = arcpy.GetParameterAsText(1)
LayerFileNameAndLocation_WSE_Contours = arcpy.GetParameterAsText(2)
LayerFileNameAndLocation_DTW_Contours = arcpy.GetParameterAsText(3)
arcpy.env.overwriteOutput = True
##GeoDatabaseNameAndLocation = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\Contours_Daily_20130625_20130731.gdb"
##LayerFileNameAndLocation_Wells = "G:\Documents\GIS\HydstraData\Template_WellPoints.lyr"
##LayerFileNameAndLocation_WSE_Contours = "G:\Documents\GIS\HydstraData\Template_WSE_Contours.lyr"
##LayerFileNameAndLocation_DTW_Contours = "G:\Documents\GIS\HydstraData\Template_DTW_Contours.lyr"
GeoDatabaseName = os.path.basename(GeoDatabaseNameAndLocation)
GeoDatabaseLocation = os.path.dirname(GeoDatabaseNameAndLocation)
##Split GeoDatabaseName and get variables for later use.
GeoDatabaseSplitParts = GeoDatabaseName.split("_")
TimeInterval = GeoDatabaseSplitParts[1]
arcpy.AddMessage(TimeInterval)
StartTime = GeoDatabaseSplitParts[2]
arcpy.AddMessage(StartTime)
EndTime = GeoDatabaseSplitParts[3][:8]
arcpy.AddMessage(EndTime)
##Determine the TimeWindowUnits.
if TimeInterval == "Daily":
TimeWindowUnits = "DAYS"
elif TimeInterval == "Weekly":
TimeWindowUnits = "WEEKS"
elif TimeInterval == "Monthly":
TimeWindowUnits = "MONTHS"
elif TimeInterval == "Annually":
TimeWindowUnits = "YEARS"
arcpy.AddMessage(TimeWindowUnits)
##Reference the Current map document.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.env.workspace = GeoDatabaseLocation
##Add WellPoints Featureclass to map.
arcpy.AddMessage("Adding WellPoints Featureclass to map.")
##WellPtsLyrFile = os.path.join(LayerFileLocation,"Template_WellPoints.lyr")
Wells_lyr = arcpy.mapping.Layer(LayerFileNameAndLocation_Wells)
##Replace the Layer DataSource.
Wells_lyr.replaceDataSource(GeoDatabaseNameAndLocation,"NONE","WellPoints")
##Show labels for WellPoints.
if Wells_lyr.supports("LABELCLASSES"):
Wells_lyr.labelClasses[0].expression = "[StateWellNumber]"
Wells_lyr.showLabels = True
arcpy.mapping.AddLayer(df, Wells_lyr, "TOP")
ContoursToAdd = AddContours("WSE",LayerFileNameAndLocation_WSE_Contours)
ContoursToAdd = AddContours("DTW",LayerFileNameAndLocation_DTW_Contours)
if Wells_lyr.supports("TIME"):
arcpy.AddMessage("TIME is supported.")
lyrTime = Wells_lyr.time
if Wells_lyr.time.isTimeEnabled:
arcpy.AddMessage("TIME is enabled.")
else:
arcpy.AddMessage("TIME is NOT enabled.")
else:
arcpy.AddMessage("TIME is NOT supported.")
StartTime = datetime.datetime.strptime(StartTime,"%Y%m%d")
EndTime = datetime.datetime.strptime(EndTime,"%Y%m%d")
df.time.resetTimeExtent()
df.time.currentTime = StartTime
df.time.startTime = StartTime
df.time.endTime = EndTime
df.time.timeWindowUnits = TimeWindowUnits
df.time.timeWindow = 0
##Turn off the "DTW_Contours" layer.
arcpy.mapping.Layer("DTW_Contours").visible = False
arcpy.RefreshTOC()
arcpy.RefreshActiveView()