示例#1
0
def create_contours(container, document):
    """Create a KML file containing MMI contour lines.

    Args:
        container (ShakeMapOutputContainer): Results of model.conf.
        datadir (str): Path to data directory where output KMZ will be written.
        document (Element): LXML KML Document element.
    """
    # TODO - label contours? gx:labelVisibility doesn't seem to be working...

    folder = document.newfolder(name='Contours', visibility=0)
    mmi_line_styles = create_line_styles()
    pgm_line_style = skml.Style(linestyle=skml.LineStyle(width=3))
    ic = skml.IconStyle(scale=0)

    component = list(container.getComponents())[0]
    imts = container.getIMTs(component)
    for imt in imts:
        line_strings = contour(container.getIMTGrids(imt, component), imt,
                               DEFAULT_FILTER_SIZE, None)
        # make a folder for the contours
        imt_folder = folder.newfolder(name='%s Contours' % imt,
                                      visibility=0)

        for line_string in line_strings:
            if imt == 'MMI':
                val = '%.1f' % line_string['properties']['value']
            else:
                val = '%g' % line_string['properties']['value']
            line_list = []
            for segment in line_string['geometry']['coordinates']:
                ctext = []
                for vertex in segment:
                    ctext.append((vertex[0], vertex[1]))
                ls = skml.LineString(coords=ctext)
                line_list.append(ls)
                lc = len(ctext)
                if lc < 10:
                    dopts = []
                elif (ctext[0][0] == ctext[-1][0] and
                      ctext[0][1] == ctext[-1][1]):
                    if lc < 30:
                        dopts = [0, int(lc/2)]
                    elif lc < 60:
                        dopts = [0, int(lc/3), int(2*lc/3)]
                    else:
                        dopts = [0, int(lc/4), int(lc/2), int(3*lc/4)]
                else:
                    dopts = [int(lc/2)]
                for i in dopts:
                    p = imt_folder.newpoint(name=val, coords=[ctext[i]],
                                            visibility=0)
                    p.style.iconstyle = ic
            mg = imt_folder.newmultigeometry(geometries=line_list,
                                             visibility=0,
                                             name="%s %s" % (imt, val))
            if imt == 'MMI':
                mg.style = mmi_line_styles[val]
            else:
                mg.style = pgm_line_style
示例#2
0
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
示例#3
0
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
示例#4
0
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
示例#5
0
def create_polygons(container, document):

    component = container.getComponents('MMI')
    if len(component) == 0:
        return
    component = component[0]
    gdict = container.getIMTGrids("MMI", component)
    fgrid = median_filter(gdict['mean'], size=10)
    cont_min = np.floor(np.min(fgrid)) - 0.5
    if cont_min < 0:
        cont_min = 0.5
    cont_max = np.ceil(np.max(fgrid)) + 0.5
    if cont_max > 10.5:
        cont_max = 10.5
    contour_levels = np.arange(cont_min, cont_max, 1, dtype=np.double)
    gjson = pcontour(fgrid,
                     gdict['mean_metadata']['dx'],
                     gdict['mean_metadata']['dy'],
                     gdict['mean_metadata']['xmin'],
                     gdict['mean_metadata']['ymax'],
                     contour_levels, 4, 0)

    folder = document.newfolder(name="MMI Polygons")

    for feature in gjson['features']:
        cv = feature['properties']['value']
        f = folder.newfolder(name="MMI %g Polygons" % cv)
        color = color_hash["%g" % cv]
        name = "MMI %g Polygon" % cv
        s = skml.PolyStyle(fill=1, outline=0, color=color,
                           colormode='normal')
        for plist in feature['geometry']['coordinates']:
            ib = []
            for i, coords in enumerate(plist):
                if i == 0:
                    ob = coords
                else:
                    ib.append(coords)
            p = f.newpolygon(outerboundaryis=ob, innerboundaryis=ib,
                             name=name, visibility=0)
            p.style.polystyle = s

    # Make the polygon labels
    cont_min = np.floor(np.min(fgrid))
    cont_max = np.ceil(np.max(fgrid))
    contour_levels = np.arange(cont_min, cont_max, 1, dtype=np.double)
    gjson = pcontour(fgrid,
                     gdict['mean_metadata']['dx'],
                     gdict['mean_metadata']['dy'],
                     gdict['mean_metadata']['xmin'],
                     gdict['mean_metadata']['ymax'],
                     contour_levels, 2, 0)

    f = folder.newfolder(name="MMI Labels")
    ic = skml.IconStyle(scale=0)
    for feature in gjson['features']:
        cv = "%g" % feature['properties']['value']
        if cv.endswith(".5"):
            continue
        for coords in feature['geometry']['coordinates']:
            lc = len(coords)
            if lc < 150:
                continue
            if coords[0][0] == coords[-1][0] and coords[0][1] == coords[-1][1]:
                if lc < 500:
                    dopts = [0, int(lc/2)]
                elif lc < 1000:
                    dopts = [0, int(lc/3), int(2*lc/3)]
                else:
                    dopts = [0, int(lc/4), int(lc/2), int(3*lc/4)]
            else:
                dopts = [int(lc/2)]
            for i in dopts:
                p = f.newpoint(name=arabic2roman[cv], coords=[coords[i]],
                               visibility=0)
                p.style.iconstyle = ic
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')
示例#9
0
    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)
示例#10
0
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