摘要
LayerTime 对象可用于访问启用了时间属性的图层管理操作。
说明
LayerTime 对象提供用于在时间图层中存储并配置时间的信息。可在 ArcMap、ArcScene 或 ArcGlobe 的图层属性 对话框的时间选项卡中设置时间属性。
图层上的时间属性为只读。可通过 UpdateLayerTime 函数使用图层 (.lyr) 文件或其他包含时间信息的地图文档中的图层替换图层属性 对话框中时间选项卡内的所有可用属性。
时间信息(诸如与要素相关联的时间值字段、数据的开始和结束时间字段,以及表示步长间隔等的时间字段),不仅可用于获取已启用时间的图层的时间属性信息,而且还能用于执行动态的数据管理和分析任务。下面的示例一说明了如何通过 startTime 和 endTime 获取时间图层的时间范围。下方示例二说明了如何使用时间字段格式化时间查询,选择一组基于时间的要素,并将这些要素保存在独立的要素类中。也可以使用时间信息确保所选要素的时间处于图层的开始时间与结束时间之间。
此外,也可以同时使用多个 LayerTime 属性在时间图层中进行数据循环。示例三说明了如何使用 timeStepInterval 属性浏览基于时间的数据,并根据不同时间步长的有效要素生成栅格表面。注意:timeStepInterval 属性返回 EsriTimeDelta 对象。
属性
属性 | 说明 | 数据类型 |
daylightSavings (只读) | Indicates whether the time values in the time field of the time-enabled layer were collected while observing Daylight Saving Time rules in the input time zone. | Boolean |
displayDataCumulatively (只读) | Indicates whether or not data in the time-enabled layer is displayed cumulatively in the display. | Boolean |
endTime (只读) | Gets the end date and time for a time-enabled layer. | DateTime |
endTimeField (只读) | The name of the field containing the end time values. End time field is used along with the start time field to store start and end time values for features that are valid for a certain duration. | String |
isTimeEnabled (只读) | Indicates whether or not time is enabled on the layer. | Boolean |
startTime (只读) | Gets the start date and time for a time-enabled layer. | DateTime |
startTimeField (只读) | The name of the field containing the time values. This field is used for features that are valid at a particular instant in time. | String |
timeFormat (只读) | The format in which the time values were stored in the input time field. The time format is important when formulating a time query. | String |
timeOffset (只读) | The time offset applied to the time values in your data. This value is a EsriTimeDelta object and is used to iterate over a period of time (for example, 2 days, 1 month, and so on). | EsriTimeDelta |
timeStepInterval (只读) | The time-step interval defines the granularity of the temporal data. The time-step interval can be thought of as how often the time values were recorded in your data. This value is a EsriTimeDelta object and is used to iterate over a period of time (for example, 2 days, 1 month, and so on). | EsriTimeDelta |
timeZone (只读) | The Time Zone set on the time-enabled layer. | String |
代码示例
LayerTime 示例 1
以下脚本首先测试图层文件是否支持时间以及是否已设置时间属性。然后使用时间信息(开始时间和结束时间)计算已启用时间属性的图层的时间范围。
import arcpy, datetime
lyr = arcpy.mapping.Layer(r'C:\Project\Data\Time\TemperatureWithTime.lyr')
if lyr.supports("TIME"):
lyrTime = lyr.time
if lyr.time.isTimeEnabled:
startTime = lyrTime.startTime
endTime = lyrTime.endTime
timeDelta = endTime - startTime
print "Start Time: " + str(startTime)
print "End Time: " + str(endTime)
print "Time Extent: " + str(timeDelta)
else:
print "No time properties have been set on the layer"
else:
print "Time is not supported on this layer"
LayerTime 示例 2
以下脚本将根据特定有效时间段的输入要素创建一个要素类,同时确保所选时间在时间图层的时间范围(开始时间和结束时间)之内。
import arcpy, datetime
output_GDB = r"C:\Project\Output\Output.gdb"
lyr = arcpy.mapping.Layer(r"C:\Project\Data\Time\TimeLayer.lyr")
lyrTime = lyr.time
# Set the time for which you want to select features in the time-enabled layer
timeSelection = datetime.datetime(2009, 9, 10, 12, 0)
# Get the start and end time of the time enabled layer
startTime = lyrTime.startTime
endTime = lyrTime.endTime
# Get the time field containing the time values associated with data in the time-enabled layer
timeField = str(lyrTime.startTimeField)
# Check to see if the time for which you want to select features lies within the start and end time of the time enabled layer
if (timeSelection < startTime or timeSelection > endTime):
print "The time specified for selecting features is not within the time extent of the layer"
else:
# Formulate the time query
timeQuery = "\"" + timeField + "\"" + "= date '" + str(timeSelection) + "'"
# Process: Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(lyr, output_GDB, "timeSubset", timeQuery, "", "")
LayerTime 示例 3
以下脚本使用时间信息(开始时间、结束时间和时间步长间隔)浏览时间图层中的数据,以便根据各时间步长的有效点要素生成栅格表面,栅格并保存在镶嵌数据集中。
import arcpy, datetime
# Check out the ArcGIS Spatial Analyst for using the IDW interpolation tool
arcpy.CheckOutExtension("spatial")
# Get the layer time properties
lyr = arcpy.mapping.Layer(r"C:\Project\Data\Time\TimeLayer.lyr")
lyrTime = lyr.time
# Calculate the number of iterations based on the time extent and timestep interval
startTime = lyrTime.startTime
endTime = lyrTime.endTime
timeExtent = endTime - startTime
timeStepInterval = lyrTime.timeStepInterval
iterations = timeExtent.days / timeStepInterval.interval
# Get the time field containing the time values associated
# with the data in the time-enabled layer
startTimeField = str(lyrTime.startTimeField)
# Specify the output mosaic dataset to which the interpolated rasters will be added
outputMosaicDataset = r"C:\Project\Output\Output.gdb\outputMosaicDataset"
i = 0
while i <= iterations:
# Formulate the time query and increment the time by the timeStepInterval
currentTime = str(startTime + (i*timeStepInterval))
timeQuery = "\"" + startTimeField + "\"" + " = date '" + currentTime + "'"
# Create an in-memory feature layer containing points that are valid at each timestep
tempFeatureLyr = "tempTimeLayer" + str(i)
arcpy.MakeFeatureLayer_management(lyr, tempFeatureLyr, timeQuery)
# Create an interpolated raster surface using the points valid at each timestep
outRaster = r"C:\Project\Output\Output.gdb\raster" + str(i)
print outRaster
arcpy.gp.Idw_sa(tempFeatureLyr, "Temperature", outRaster)
# Add the newly created raster surface to a Mosaic Dataset
arcpy.AddRastersToMosaicDataset_management(outputMosaicDataset, "Raster Dataset", outRaster)
i = i + 1
# Calculate the statistics on the output Mosaic Dataset for
# classifying your data after new rasters are added
arcpy.CalculateStatistics_management(outputMosaicDataset,"1","1","#")