Saturday, July 8, 2017

Python - Video Creation by automation of images

This script is created to create a video by automation of images generated from the facility processing.


import arcpy
import datetime
import os

mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "New Data Frame")[0]
timeLayer = arcpy.mapping.Layer(r"C:\Project\Data\Accidents.lyr")
arcpy.mapping.AddLayer(df, timeLayer, "AUTO_ARRANGE")
df.time.resetTimeExtent()
df.time.timeWindowUnits = "DAYS"
df.time.timeWindow = 7
df.time.currentTime = datetime.datetime(2008, 10, 1)
endTime = datetime.datetime(2008, 10, 31)
interval = arcpy.time.EsriTimeDelta(1, 'weeks')

while df.time.currentTime <= endTime:
    # An example str(newTime) would be: "2008-01-29 02:19:59"
    # The following line splits the string at the space and takes the first
    # item in the resulting string.
    fileName = str(df.time.currentTime).split(" ")[0] + ".png"
    arcpy.mapping.ExportToPNG(mxd, os.path.join(r"C:\Project\Output", fileName))
    df.time.currentTime = df.time.currentTime + interval
del mxd, timeLayer


# Local variables:
v41 = "G:\\BEMIS\\CSSEWS\\Animation\\41"
Animation3_avi = "G:\\BEMIS\\CSSEWS\\Animation\\41\\Animation3.avi"

# Process: Raster To Video
arcpy.RasterToVideo_conversion(v41, Animation3_avi, "JPG", "Microsoft Video 1", "TIME", "168", "50")

No comments:

Post a Comment