def create_overlay(container, datadir, document): """Create a KML file and intensity map. Args: container (ShakeMapOutputContainer): Results of model.conf. datadir (str): Path to data directory where output KMZ will be written. document (SubElement): KML document where the overlay tags should go. Returns: tuple: (Path to output KMZ file, Path to output overlay image) """ # create the overlay image file overlay_img_file = os.path.join(datadir, OVERLAY_IMG) geodict = create_overlay_image(container, overlay_img_file) if geodict is None: return None box = skml.LatLonBox(north=geodict.ymax, south=geodict.ymin, east=geodict.xmax, west=geodict.xmin) icon = skml.Icon(refreshinterval=300, refreshmode='onInterval', href=OVERLAY_IMG) document.newgroundoverlay(name='IntensityOverlay', color='ffffffff', draworder=0, latlonbox=box, icon=icon) return overlay_img_file
def place_legend(datadir, document): """Place the ShakeMap intensity legend in the upper left corner of the viewer's map. Args: datadir (str): Path to data directory where output KMZ will be written. document (Element): LXML KML Document element. Returns: str: Path to output intensity legend file. """ icon = skml.Icon(href=LEGEND) overlayxy = skml.OverlayXY(x=0, y=90, xunits='pixels', yunits='pixels') screenxy = skml.ScreenXY(x=5, y=1, xunits='pixels', yunits='fraction') size = skml.Size(x=0, y=0, xunits='pixels', yunits='pixels') document.newscreenoverlay(name='Intensity Legend', icon=icon, overlayxy=overlayxy, screenxy=screenxy, size=size) # we need to find the legend file and copy it to # the output directory this_dir, _ = os.path.split(__file__) data_path = os.path.join(this_dir, '..', 'data', 'mapping') legend_file = os.path.join(data_path, LEGEND) legdest = os.path.join(datadir, LEGEND) shutil.copyfile(legend_file, legdest) return legdest
def ConverttoKml(Input,Evt_df): kml = simplekml.Kml() for ind in Evt_df.index: pnt = kml.newpoint(name="", coords=[(Evt_df['Longitude'][ind], Evt_df['Latitude'][ind])]) pnt.iconstyle = simplekml.IconStyle(color=simplekml.Color.rgb(0, 255, 0), scale=0.4, heading=Evt_df['Heading'][ind] - 180, icon=simplekml.Icon(gxx=None, gxy=None, gxw=None, gxh=None, href='http://maps.google.com/mapfiles/kml/shapes/arrow.png'), hotspot=None) kml.save(OutputLogDirectory + EV_type + '_' + Input + '.kml') return
def makeKmlFile(self, level, tileIndex, force=False): '''Creates the KML file for a given image tile. Returns True if the file exists upon exit.''' KML = False # Helper names for getTilePath PNG = True # Paths for the kml and associated tif file tileKmlPath = self.getTilePath(level, tileIndex, KML) tileImagePath = self.getTilePath(level, tileIndex, PNG) imageFileName = os.path.basename(tileImagePath) # There should be no need to recreate the KML files! if os.path.exists(tileKmlPath) and not force: return True kml = simplekml.Kml() # Region for this file kml.document.region = self._makeKmlRegion(level, tileIndex) # Network links for lower level files if level > 0: levelDown = level - 1 indexList = self._getInputTiles(tileIndex) for index in indexList: sourceTilePath = self.getTilePath(levelDown, index, KML, isRelative=False) sourceTilePathRel = self.getTilePath(levelDown, index, KML, isRelative=True) if not os.path.exists(sourceTilePath): continue # Don't link to non-existant tiles netLink = kml.document.newnetworklink( name=index.getPostfix(), region=self._makeKmlRegion(levelDown, index)) netLink.link.href = sourceTilePathRel netLink.link.viewrefreshmode = simplekml.ViewRefreshMode.onrequest # Ground overlay kml.document.groundoverlay = kml.newgroundoverlay( icon=simplekml.Icon(href=imageFileName), latlonbox=self._getLatLonAltBox(level, tileIndex)) # Save the completed file kml.save(tileKmlPath) if not os.path.exists(tileKmlPath): raise Exception('Failed to create file ' + tileKmlPath) return tileKmlPath
def create_epicenter(container, document): """Place a star marker at earthquake epicenter. Args: container (ShakeMapOutputContainer): Results of model.conf. document (Element): LXML KML Document element. """ icon = skml.Icon(href=EPICENTER_URL) iconstyle = skml.IconStyle(icon=icon) style = skml.Style(iconstyle=iconstyle) info = container.getMetadata() lon = info['input']['event_information']['longitude'] lat = info['input']['event_information']['latitude'] point = document.newpoint(name='Earthquake Epicenter', coords=[(lon, lat)], visibility=0) point.style = style
def add_icon_style(document, icon_text, icon_scale, label_scale, color): """Create Style tag around Icon in KML. Args: document (Element): LXML KML Document element. icon_text (str): The name of the icon file. icon_scale (float): The icon scale. label_scale (float): The label scale. """ icon = skml.Icon(href=icon_text) icon_style = skml.IconStyle(scale="%.1f" % icon_scale, color=color, icon=icon) label_style = skml.LabelStyle(scale='%.1f' % label_scale) # list_style = skml.ListStyle(listitemtype='checkHideChildren') balloon_style = skml.BalloonStyle(text='$[description]') # style = skml.Style(iconstyle=icon_style, labelstyle=label_style, # liststyle=list_style, balloonstyle=balloon_style) style = skml.Style(iconstyle=icon_style, labelstyle=label_style, balloonstyle=balloon_style) return style
def process_tim_rf(input_rf_log, filename): temp1year = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMTime', 'year']) temp1month = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMTime', 'month']) temp1day = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMTime', 'day']) temp1hour = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMTime', 'hour']) temp1minute = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMTime', 'minute']) temp1second = floor(get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMTime', 'second']) / 1000) temp1microsec = (get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMTime', 'second']) % 1000) * 1000 temp1fulltime = datetime.datetime(temp1year, temp1month, temp1day, temp1hour, temp1minute, temp1second, temp1microsec) print(get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMRecord', 'msgHeader', 'myRFLevel'])) firsttim_id = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMRecord', 'timMsg', 'packetID']) first_sight_lat = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMLocation', 'coreData', 'lat']) / Loc_Factor first_sight_long = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMLocation', 'coreData', 'long']) / Loc_Factor first_sight_speed = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMLocation', 'coreData', 'speed']) first_sight_head = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMLocation', 'coreData', 'heading']) * Head_Factor #print(get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMTime'])) temp2year = get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMTime', 'year']) temp2month = get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMTime', 'month']) temp2day = get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMTime', 'day']) temp2hour = get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMTime', 'hour']) temp2minute = get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMTime', 'minute']) temp2second = floor(get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMTime', 'second']) / 1000) temp2microsec = (get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMTime', 'second']) % 1000) * 1000 temp2fulltime = datetime.datetime(temp2year, temp2month, temp2day, temp2hour, temp2minute, temp2second, temp2microsec) print(get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMRecord', 'msgHeader', 'myRFLevel'])) lasttim_id = get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMRecord', 'timMsg', 'packetID']) last_sight_lat = get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMLocation', 'coreData', 'lat']) / Loc_Factor last_sight_long = get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMLocation', 'coreData', 'long']) / Loc_Factor last_sight_speed = get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMLocation', 'coreData', 'speed']) last_sight_head = get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMLocation', 'coreData', 'heading']) * Head_Factor tim_refP_lat = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMRecord', 'timMsg', 'dataFrames', 0, 'msgId', 'roadSignID', 'position', 'lat']) / Loc_Factor tim_refP_long = get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMRecord', 'timMsg', 'dataFrames', 0, 'msgId', 'roadSignID', 'position', 'long']) / Loc_Factor traversersedtime = abs(temp1fulltime - temp2fulltime) # TODO - PacketID Read is reading 0x4E as "N" Need to Fix # print(input_rf_log.to_asn1()) # print("Rojer" + str(firsttim_id)) # print(get_val_at(input_rf_log, ['timRFList', 0, 'firstTIMRecord', 'timMsg', 'packetID'])) # print(lasttim_id) # print(get_val_at(input_rf_log, ['timRFList', 0, 'lastTIMRecord', 'timMsg', 'packetID'])) if firsttim_id == lasttim_id: if traversersedtime.total_seconds != 0: print("Valid TIM RF Log") # firstmap_id + filename # http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png kml = simplekml.Kml() pnt = kml.newpoint(name="", coords=[(tim_refP_long, tim_refP_lat)]) pnt.iconstyle = simplekml.IconStyle(scale=2, heading=0, icon=simplekml.Icon(gxx=None, gxy=None, gxw=None, gxh=None, href='http://maps.google.com/mapfiles/kml/paddle/T.png'), hotspot=None) pnt = kml.newpoint(name="", coords=[(first_sight_long, first_sight_lat)]) pnt.iconstyle = simplekml.IconStyle(color=simplekml.Color.rgb(0, 255, 0), scale=0.4, heading=first_sight_head - 180, icon=simplekml.Icon(gxx=None, gxy=None, gxw=None, gxh=None, href='http://maps.google.com/mapfiles/kml/shapes/arrow.png'), hotspot=None) pnt = kml.newpoint(name="", coords=[(last_sight_long, last_sight_lat)]) pnt.iconstyle = simplekml.IconStyle(color=simplekml.Color.rgb(0, 0, 255), scale=0.4, heading=last_sight_head - 180, icon=simplekml.Icon(gxx=None, gxy=None, gxw=None, gxh=None, href='http://maps.google.com/mapfiles/kml/shapes/arrow.png'), hotspot=None) temp_str = str(firsttim_id) temp_str = temp_str.replace("\\x", "") temp_str = temp_str.replace("b'", "") temp_str = temp_str.replace("'", "") print(str(firsttim_id)) print(temp_str) kml.save( OutputLogDirectory + '\\' + temp_str[0:2] + "_" + temp_str[-4:] + "_TIM_" + get_val_at(input_rf_log, ['asdSerialNumber']) + "_" + filename + '.kml') print("TIMRF -> BSM Heading in RF Log (Last):" + str(first_sight_head)) print("TIMRF ->BSM Heading in RF Log (Last):" + str(last_sight_head)) print("TIMRF ->BSM Speed in RF Log (Last):" + str(first_sight_speed)) print("TIMRF ->BSM Speed in RF Log (Last):" + str(last_sight_speed)) else: print("Invalid TIM RF Log. TIM RF Log Time Difference is 0.") else: print("Invalid TIM RF Log. First and Last TIM Entries have different TIM Messages")
def process_spat_rf(input_rf_log, filename): #print(input_rf_log.to_asn1()) #print(get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTTime'])) temp1year = get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTTime', 'year']) temp1month = get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTTime', 'month']) temp1day = get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTTime', 'day']) temp1hour = get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTTime', 'hour']) temp1minute = get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTTime', 'minute']) temp1second = floor(get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTTime', 'second']) / 1000) temp1microsec = (get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTTime', 'second']) % 1000) * 1000 temp1fulltime = datetime.datetime(temp1year, temp1month, temp1day, temp1hour, temp1minute, temp1second, temp1microsec) print(get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTRecord', 'msgHeader', 'myRFLevel'])) firstmap_id = get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTRecord', 'spatMsg', 'intersections', 0, 'id', 'id']) first_sight_lat = get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTLocation', 'coreData', 'lat']) / Loc_Factor first_sight_long = get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTLocation', 'coreData', 'long']) / Loc_Factor first_sight_speed = get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTLocation', 'coreData', 'speed']) first_sight_head = get_val_at(input_rf_log, ['spatRFList', 0, 'firstSPaTLocation', 'coreData', 'heading']) * Head_Factor #print(get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTTime'])) temp2year = get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTTime', 'year']) temp2month = get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTTime', 'month']) temp2day = get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTTime', 'day']) temp2hour = get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTTime', 'hour']) temp2minute = get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTTime', 'minute']) temp2second = floor(get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTTime', 'second']) / 1000) temp2microsec = (get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTTime', 'second']) % 1000) * 1000 temp2fulltime = datetime.datetime(temp2year, temp2month, temp2day, temp2hour, temp2minute, temp2second, temp2microsec) print(get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTRecord', 'msgHeader', 'myRFLevel'])) lastmap_id = get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTRecord', 'spatMsg', 'intersections', 0, 'id', 'id']) last_sight_lat = get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTLocation', 'coreData', 'lat']) / Loc_Factor last_sight_long = get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTLocation', 'coreData', 'long']) / Loc_Factor last_sight_speed = get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTLocation', 'coreData', 'speed']) last_sight_head = get_val_at(input_rf_log, ['spatRFList', 0, 'lastSPaTLocation', 'coreData', 'heading']) * Head_Factor traversersedtime = abs(temp1fulltime - temp2fulltime) if firstmap_id == lastmap_id: if traversersedtime.total_seconds != 0: print("Valid SPaT RF Log") SPaT_RSU_Pos = MAP_SPaT_DB_Cleaned[MAP_SPaT_DB_Cleaned.AstcId.eq(str(firstmap_id))] #print(SPaT_RSU_Pos) if SPaT_RSU_Pos.empty: print("No matching Intersection ID found in database.. Skipping..") else: SPaT_RSUL_lat = int(SPaT_RSU_Pos.iloc[0].RsuLocLatitude) / Loc_Factor SPaT_RSUL_long = int(SPaT_RSU_Pos.iloc[0].RsuLocLongitude) / Loc_Factor kml = simplekml.Kml() pnt = kml.newpoint(name="", coords=[(SPaT_RSUL_long, SPaT_RSUL_lat)]) pnt.iconstyle = simplekml.IconStyle(scale=2, heading=0, icon=simplekml.Icon(gxx=None, gxy=None, gxw=None, gxh=None, href='http://maps.google.com/mapfiles/kml/paddle/S.png'), hotspot=None) pnt = kml.newpoint(name="", coords=[(first_sight_long, first_sight_lat)]) pnt.iconstyle = simplekml.IconStyle(color=simplekml.Color.rgb(0, 255, 0), scale=0.4, heading=first_sight_head - 180, icon=simplekml.Icon(gxx=None, gxy=None, gxw=None, gxh=None, href='http://maps.google.com/mapfiles/kml/shapes/arrow.png'), hotspot=None) pnt = kml.newpoint(name="", coords=[(last_sight_long, last_sight_lat)]) pnt.iconstyle = simplekml.IconStyle(color=simplekml.Color.rgb(0, 0, 255), scale=0.4, heading=last_sight_head - 180, icon=simplekml.Icon(gxx=None, gxy=None, gxw=None, gxh=None, href='http://maps.google.com/mapfiles/kml/shapes/arrow.png'), hotspot=None) kml.save( OutputLogDirectory + '\\' + str(firstmap_id) + "_SPaT_" + get_val_at(input_rf_log, ['asdSerialNumber']) + "_" + filename + '.kml') print("SPaTRF -> BSM Heading in RF Log (Last):" + str(first_sight_head)) print("SPaTRF ->BSM Heading in RF Log (Last):" + str(last_sight_head)) print("SPaTRF ->BSM Speed in RF Log (Last):" + str(first_sight_speed)) print("SPaTRF ->BSM Speed in RF Log (Last):" + str(last_sight_speed)) else: print("Invalid SPaT RF Log. SPaT RF Log Time Difference is 0.") else: print("Invalid SPaT RF Log. First and Last SPaT Entries have different SPaT Messages")
def bc2kml(input_bc_file,filename): #print("Function that converts NYC BreadCrumb Log to KML File") totaldistance = 0 kml = simplekml.Kml() print("SerialNumber of BC Log: " + get_val_at(input_bc_file, ['asdSerialNumber'])) print("Resolution of Bread Crumbs in BC Log: " + get_val_at(input_bc_file, ['timeRecordResolution'])) bc = get_val_at(input_bc_file, ['locList']) numberofbc = len(bc) avgspeedlist = [] #print(input_bc_file.to_asn1()) for j in range(numberofbc): pnt = kml.newpoint(name="", coords=[(get_val_at(input_bc_file, ['locList', j, 'longitude'])/Loc_Factor, get_val_at(input_bc_file, ['locList', j, 'latitude'])/Loc_Factor)]) pnt.iconstyle = simplekml.IconStyle(color = simplekml.Color.rgb(255, 0, 0), scale=0.5, heading=0, icon=simplekml.Icon(gxx=None, gxy=None, gxw=None, gxh=None, href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png'), hotspot=None) #pnt.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/info-i.png' #pnt.style.iconstyle.color = simplekml.Color.rgb(255, 0, 0) # RGB values(255,255,0) if j > 0: tempdistance = distancecalc((get_val_at(input_bc_file, ['locList', j, 'latitude'])/Loc_Factor),(get_val_at(input_bc_file, ['locList', j, 'longitude'])/Loc_Factor),(get_val_at(input_bc_file, ['locList', j-1, 'latitude'])/10000000),(get_val_at(input_bc_file, ['locList', j-1, 'longitude'])/Loc_Factor)) totaldistance = totaldistance + tempdistance temp1year = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'year']) temp1month = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'month']) temp1day = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'day']) temp1hour = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'hour']) temp1minute = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'minute']) temp1second = floor(get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) / 1000) temp1microsec = (get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) % 1000) * 1000 temp1fulltime = datetime.datetime(temp1year, temp1month, temp1day, temp1hour, temp1minute, temp1second,temp1microsec) temp2year = get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'year']) temp2month = get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'month']) temp2day = get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'day']) temp2hour = get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'hour']) temp2minute = get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'minute']) temp2second = floor(get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'second']) / 1000) temp2microsec = (get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'second']) % 1000) * 1000 temp2fulltime = datetime.datetime(temp2year, temp2month, temp2day, temp2hour, temp2minute, temp2second,temp2microsec) temptraversersedtime = abs(temp1fulltime - temp2fulltime) if temptraversersedtime.total_seconds() != 0: tempavgspeed = round(tempdistance / temptraversersedtime.total_seconds(),5) avgspeedlist.append(tempavgspeed) else: print("Duplicate BC Log.. Avoid Divide by zero..") if j == 0: tempyear = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'year']) tempmonth = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'month']) tempday = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'day']) temphour = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'hour']) tempminute = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'minute']) tempsecond = floor(get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) / 1000) tempmicrosec = (get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) % 1000) * 1000 firstbctime = datetime.datetime(tempyear, tempmonth, tempday, temphour, tempminute, tempsecond, tempmicrosec) if j == (numberofbc-1): tempyear = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'year']) tempmonth = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'month']) tempday = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'day']) temphour = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'hour']) tempminute = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'minute']) tempsecond = floor(get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) / 1000) tempmicrosec = (get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) % 1000) * 1000 lastbctime = datetime.datetime(tempyear, tempmonth, tempday, temphour, tempminute, tempsecond, tempmicrosec) BCavgspeed = round(sum(avgspeedlist) / len(avgspeedlist),5) traversersedtime = abs(lastbctime - firstbctime) #print(traversersedtime.total_seconds()) kml.save(OutputLogDirectory + '\\' + get_val_at(input_bc_file, ['asdSerialNumber']) + "_" + filename + '.kml') print("TimeStamp of First BC Entry= " + str(firstbctime)) print("TimeStamp of Last BC Entry= " + str(lastbctime)) print("Total time between first and last BC= " + str(traversersedtime.total_seconds()) + "seconds") print("Total Distance travelled in BC Log (m): " + str(round(totaldistance,2)) + " m") print("Total Distance travelled in BC Log (km): " + str(round(totaldistance / 1000,2)) + " km" ) print("Average Speed in BC Log (mps): " + str(BCavgspeed) + " mps") print("Average Speed in BC Log (mph): " + str(round(BCavgspeed * 2.23694,2)) + " mph") pdf = FPDF(orientation='P', unit='mm', format='A4') pdf.add_page() pdf.set_font("Arial", size=10) pdf.cell(200, 10, txt="Processed File Name" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + filename, ln=1, align="L") pdf.cell(200, 10, txt="Processed File Type" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + "Bread Crumb Log", ln=1, align="L") pdf.cell(200, 10, txt="Processed File ASN Version" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + "J2735_NYC_03062020", ln=1, align="L") pdf.cell(200, 10, txt="Serial Number of ASD" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + get_val_at(input_bc_file, ['asdSerialNumber']), ln=1, align="L") pdf.cell(200, 10, txt="Resolution of Bread Crumbs" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + get_val_at(input_bc_file, ['timeRecordResolution']), ln=1, align="L") pdf.cell(200, 10, txt="TimeStamp of First BC Entry" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + str(firstbctime), ln=1, align="L") pdf.cell(200, 10, txt="TimeStamp of Last BC Entry" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + str(lastbctime), ln=1, align="L") pdf.cell(200, 10, txt="Total time between first and last BC" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + str(traversersedtime.total_seconds()) + "seconds", ln=1, align="L") pdf.cell(200, 10, txt="Total Distance travelled in BC Log (m)" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + str(round(totaldistance,2)) + " m", ln=1, align="L") pdf.cell(200, 10, txt="Total Distance travelled in BC Log (km)" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + str(round(totaldistance / 1000,2)) + " km", ln=1, align="L") pdf.cell(200, 10, txt="Average Speed in BC Log (mps)" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + str(BCavgspeed) + " mps", ln=1, align="L") pdf.cell(200, 10, txt="Average Speed in BC Log (mph)" + "\t" + "\t" + "\t" + "\t" + "\t" + ":" + "\t" + str(round(BCavgspeed * 2.23694,2)) + " mph", ln=1, align="L") pdf.output(OutputLogDirectory + '\\' + get_val_at(input_bc_file, ['asdSerialNumber']) + "_" + filename + '.pdf')
pid_trips = route.GetPatternIdTripDict() for pattern_id in pid_trips.keys(): trip = pid_trips[pattern_id][ 0] # Since we only want to map, any trip will do print trip["trip_id"], route["route_id"] if trip["direction_id"] == "1": direction = " (Reverse)" else: # direction = " (Forward)" direction = "" shape = gtfs.GetShape(trip["shape_id"]) coords = [(lon, lat) for (lat, lon, dist) in shape.points] name = route["route_short_name"] + ": " + route[ "route_long_name"] + direction line = routefolder.newlinestring(name=name, coords=coords) line.iconstyle = simplekml.IconStyle(icon=simplekml.Icon( href="http://maps.google.com/mapfiles/kml/pal2/icon13.png")) if "route_color" in route.keys() and route.route_color != '': color = "8F" + route.route_color else: color = "8F" + default_color line.linestyle = simplekml.LineStyle(width=4, color=color) stopfolder = routefolder.newfolder(name="Stops") for stop in trip.GetPattern(): coords = [(stop.stop_lon, stop.stop_lat)] stopfolder.newpoint(coords=coords, name=stop.stop_name) # TODO: Stops not in any route #orphan_stops = kml.newfolder(name="Unused Stops") # Possible TODO: handle multiple instances of same stop kml.save("test.kml", False)
def bc2kml(input_bc_file,filename): #print("Function that converts NYC BreadCrumb Log to KML File") totaldistance = 0 kml = simplekml.Kml() # print("SerialNumber of BC Log: " + get_val_at(input_bc_file, ['asdSerialNumber'])) # print("Resolution of Bread Crumbs in BC Log: " + get_val_at(input_bc_file, ['timeRecordResolution'])) bc = get_val_at(input_bc_file, ['locList']) numberofbc = len(bc) avgspeedlist = [] #print(input_bc_file.to_asn1()) for j in range(numberofbc): pnt = kml.newpoint(name="", coords=[(get_val_at(input_bc_file, ['locList', j, 'longitude'])/Loc_Factor, get_val_at(input_bc_file, ['locList', j, 'latitude'])/Loc_Factor)]) pnt.iconstyle = simplekml.IconStyle(color = simplekml.Color.rgb(255, 0, 0), scale=0.5, heading=0, icon=simplekml.Icon(gxx=None, gxy=None, gxw=None, gxh=None, href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png'), hotspot=None) #pnt.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/info-i.png' #pnt.style.iconstyle.color = simplekml.Color.rgb(255, 0, 0) # RGB values(255,255,0) if j > 0: tempdistance = distancecalc((get_val_at(input_bc_file, ['locList', j, 'latitude'])/Loc_Factor),(get_val_at(input_bc_file, ['locList', j, 'longitude'])/Loc_Factor),(get_val_at(input_bc_file, ['locList', j-1, 'latitude'])/10000000),(get_val_at(input_bc_file, ['locList', j-1, 'longitude'])/Loc_Factor)) totaldistance = totaldistance + tempdistance temp1year = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'year']) temp1month = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'month']) temp1day = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'day']) temp1hour = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'hour']) temp1minute = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'minute']) temp1second = floor(get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) / 1000) temp1microsec = (get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) % 1000) * 1000 temp1fulltime = datetime.datetime(temp1year, temp1month, temp1day, temp1hour, temp1minute, temp1second,temp1microsec) temp2year = get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'year']) temp2month = get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'month']) temp2day = get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'day']) temp2hour = get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'hour']) temp2minute = get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'minute']) temp2second = floor(get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'second']) / 1000) temp2microsec = (get_val_at(input_bc_file, ['locList', j-1, 'timeStamp', 'second']) % 1000) * 1000 temp2fulltime = datetime.datetime(temp2year, temp2month, temp2day, temp2hour, temp2minute, temp2second,temp2microsec) temptraversersedtime = abs(temp1fulltime - temp2fulltime) if temptraversersedtime.total_seconds() != 0: tempavgspeed = round(tempdistance / temptraversersedtime.total_seconds(),5) avgspeedlist.append(tempavgspeed) else: print("Duplicate BC Log.. Avoid Divide by zero..") if j == 0: tempyear = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'year']) tempmonth = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'month']) tempday = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'day']) temphour = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'hour']) tempminute = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'minute']) tempsecond = floor(get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) / 1000) tempmicrosec = (get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) % 1000) * 1000 firstbctime = datetime.datetime(tempyear, tempmonth, tempday, temphour, tempminute, tempsecond, tempmicrosec) if j == (numberofbc-1): tempyear = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'year']) tempmonth = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'month']) tempday = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'day']) temphour = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'hour']) tempminute = get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'minute']) tempsecond = floor(get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) / 1000) tempmicrosec = (get_val_at(input_bc_file, ['locList', j, 'timeStamp', 'second']) % 1000) * 1000 lastbctime = datetime.datetime(tempyear, tempmonth, tempday, temphour, tempminute, tempsecond, tempmicrosec) BCavgspeed = round(sum(avgspeedlist) / len(avgspeedlist),5) traversersedtime = abs(lastbctime - firstbctime) #print(traversersedtime.total_seconds()) kml.save(OutputLogDirectory + '\\' + get_val_at(input_bc_file, ['asdSerialNumber']) + "_" + filename + '.kml') return