1. Space Time Visualization Using Python
I- 190
State Hwy 31
Delaware St
Python Script:
# arcpy
import arcpy
# environment and parameters for the tool
arcpy.env.workspace = arcpy.GetParameterAsText(0)
GPSinFeature = arcpy.GetParameterAsText(1)
DateTimeS = arcpy.GetParameterAsText(2)
OutOut4 = arcpy.GetParameterAsText(3)
#set local variable
FieldName1 = "hour"
eldPrecision = 9
FieldName2 = minute
eldPrecision = 9
FieldName3 = second
eldPrecision = 9
FieldName4 = TimeXAll
FieldName5 = TimeXMin
FieldName7 = TimeSec
# add feild 3 times for three new elds (in gps
shapele)
arcpy.AddField_management(GPSinFeature,
FieldName1, LONG, eldPrecision)
arcpy.AddField_management(GPSinFeature,
FieldName2, LONG, eldPrecision)
arcpy.AddField_management(GPSinFeature,
FieldName3, LONG, eldPrecision)
# calculate time
# creat a refrence eld which includes just
time not date
arcpy.AddField_management(GPSinFeature
, FieldName4, TEXT, eldPrecision)
# New: Convert any type of date eld to one
standard date eld
arcpy.ConvertTimeField_management
(GPSinFeature,DateTimeS,yyyy-MM-dd
HH:mm:ss;1033;;,HHMMSS,TEXT,
yyyyMMddHHmmss)
# New: copy the hh:mm:ss part of the
Standard DateTimeS (just created)
to the eld just created (TimeXAll)
arcpy.CalculateField_management
(GPSinFeature,TimeXAll,Mid( [HHMMSS],
9, 14),VB,#)
# add a eld to be able to copy the source
for minute
arcpy.AddField_management(GPSinFeature,
FieldName5, TEXT, eldPrecision)
# New: calculate the source eld for minute and
sec
arcpy.CalculateField_management(GPSin
Feature,TimeXMin,Right( [TimeXAll], 4)
,VB,#)#calculate hour
arcpy.CalculateField_management
(GPSinFeature,hour,Left( [TimeXAll], 2)
,VB,#)#calculate min
arcpy.CalculateField_management
(GPSinFeature,
minute,Left( [TimeXMin], 2),VB,#)
#calculate sec
arcpy.CalculateField_management
(GPSinFeature,second,Right( [TimeXMin]
, 2),VB,#)
# create a eld for time based on seconds
arcpy.AddField_management
(GPSinFeature, FieldName7, LONG,
eldPrecision)
#add hour + minute+ sec and calculate
the time based on sec
arcpy.CalculateField_management
(GPSinFeature,TimeSec,[hour] *3600
+ [minute]*60 + [second],VB,#)
# points to lines
#parameters
outFeature = Line_ready.shp
outFeature2 = splited
sortField = TimeSec
radious = 2 Meter
# create line based on sort led
arcpy.PointsToLine_management
(GPSinFeature, outFeature, , sortField)
#spilit line based on point with .09 radious
arcpy.SplitLineAtPoint_management
(outFeature,GPSinFeature, outFeature2
, radious)
# extract two numbers based on time and
make two elds
#in order to do that we need to copy
sample.shp and use it in spatial join script
# Set local variables
outFeatureClass = ForSpatial
# Execute FeatureClassToFeatureClass
arcpy.FeatureClassToFeatureClass_
conversion(GPSinFeature, arcpy.env.
workspace, outFeatureClass)
#parameters for spatial join
OutPut3 = MinMaxSec
inFeature8 = splited.shp
# Replace a layer/table view name with a
path to a dataset (which can be a layer le)
or create the layer/table view within the script
# The following inputs are layers or table views
: splited, 5
arcpy.SpatialJoin_analysis(inFeature8,
GPSinFeature,OutPut3,JOIN_ONE_TO_ONE,
KEEP_ALL,max max true false
false 50 Double 0 0 ,Max,#,ForSpatial.shp,
TimeSec,-1,-1;min min true false false 50
Double 0 0 ,Min,#,ForSpatial.shp,TimeSec
,-1,-1,INTERSECT,#,#)
Sheridan Dr State Hwy 324
Main St
I- 90
Shawnee Rd
River Rd
Saunders Settlement
State Hwy 265
State Hwy 266
State Hwy 182
Harlem Rd
Erie Ave
Townline Rd
Main St
State Hwy 198
Main St
Main St
# feature to 3d
arcpy.CheckOutExtension('3D')
# parameters
arcpy.FeatureTo3DByAttribute_3d
(MinMaxSec.shp,OutOut4,min,max)
PrimaryRoads
Destinations
GPS Track
Water
Erie County Block Groups
Miles
0.25 0.5 1 1.5 2