Example #1
0
def privAddStaticAssignment(initAssignments=None,
                            odID=1,
                            objectID=None,
                            modelFile=None,
                            modelScale=VRV_DEFAULT_CESIUMMODELSCALE,
                            modelMinPxSize=VRV_DEFAULT_CESIUMMODELMINPXSIZE,
                            loc=None,
                            startTimeSec=None,
                            endTimeSec=None):

    # Replace backslash
    modelFile = replaceBackslashToSlash(modelFile)

    # assignment dataframe
    assignments = initDataframe('Assignments')

    dicLoc = loc2Dict(loc)

    assignments = assignments.append(
        {
            'odID': odID,
            'objectID': objectID,
            'modelFile': modelFile,
            'modelScale': modelScale,
            'modelMinPxSize': modelMinPxSize,
            'startTimeSec': startTimeSec,
            'startLat': dicLoc['lat'],
            'startLon': dicLoc['lon'],
            'startAltMeters': dicLoc['alt'],
            'endTimeSec': endTimeSec,
            'endLat': dicLoc['lat'],
            'endLon': dicLoc['lon'],
            'endAltMeters': dicLoc['alt'],
            'leafletColor': None,
            'leafletWeight': None,
            'leafletStyle': None,
            'leafletOpacity': None,
            'cesiumColor': None,
            'cesiumWeight': None,
            'cesiumStyle': None,
            'cesiumOpacity': None,
            'useArrows': None
        },
        ignore_index=True,
        sort=False)

    if (type(initAssignments) is pd.core.frame.DataFrame):
        assignments = pd.concat([initAssignments, assignments],
                                ignore_index=True)

    return assignments
Example #2
0
def privGetShapepoints3D(
        odID=1,
        objectID=None,
        modelFile=None,
        startTimeSec=0.0,
        startLoc=None,
        endLoc=None,
        takeoffSpeedMPS=None,
        cruiseSpeedMPS=None,
        landSpeedMPS=None,
        cruiseAltMetersAGL=None,
        routeType='square',
        climbRateMPS=None,
        descentRateMPS=None,
        earliestLandTime=-1,
        loiterPosition='arrivalAtAlt',
        leafletColor=config['VRV_DEFAULT_LEAFLETARCCOLOR'],
        leafletWeight=config['VRV_DEFAULT_LEAFLETARCWEIGHT'],
        leafletStyle=config['VRV_DEFAULT_LEAFLETARCSTYLE'],
        leafletOpacity=config['VRV_DEFAULT_LEAFLETARCOPACITY'],
        leafletCurveType=config['VRV_DEFAULT_ARCCURVETYPE'],
        leafletCurvature=config['VRV_DEFAULT_ARCCURVATURE'],
        useArrows=True,
        modelScale=config['VRV_DEFAULT_CESIUMMODELSCALE'],
        modelMinPxSize=config['VRV_DEFAULT_CESIUMMODELMINPXSIZE'],
        cesiumColor=config['VRV_DEFAULT_CESIUMPATHCOLOR'],
        cesiumWeight=config['VRV_DEFAULT_CESIUMPATHWEIGHT'],
        cesiumStyle=config['VRV_DEFAULT_CESIUMPATHSTYLE'],
        cesiumOpacity=config['VRV_DEFAULT_CESIUMPATHOPACITY'],
        ganttColor=config['VRV_DEFAULT_GANTTCOLOR'],
        ganttColorLoiter=config['VRV_DEFAULT_GANTTCOLORLOITER'],
        popupText=None):

    # Replace backslash
    modelFile = replaceBackslashToSlash(modelFile)

    # Ensure leading slash
    modelFile = addHeadSlash(modelFile)

    # Generate flight profile without loitering
    flight = buildNoLoiteringFlight(routeType, startLoc, cruiseAltMetersAGL,
                                    endLoc, takeoffSpeedMPS, climbRateMPS,
                                    cruiseSpeedMPS, landSpeedMPS,
                                    descentRateMPS)

    # Calculate loiter time
    [totalTime, groundDistance, flightDistance] = getTimeDistFromFlight(flight)
    remainLoiterTime = 0
    if (earliestLandTime - startTimeSec > totalTime):
        remainLoiterTime = earliestLandTime - startTimeSec - totalTime
    else:
        remainLoiterTime = 0

    # Add loiter given loiter position
    flight = addLoiterTimeToFlight(flight=flight,
                                   loiterPosition=loiterPosition,
                                   loiterTime=remainLoiterTime)

    # Build assignments dataframe
    assignments = privInitDataframe('assignments')
    for i in range(1, len(flight)):
        # For all segments in flight profile, loitering happens AFTER arrival at that position
        assignments = assignments.append(
            {
                'odID': odID,
                'objectID': objectID,
                'modelFile': modelFile,
                'startTimeSec':
                startTimeSec + flight.iloc[i - 1]['pathEndTimeSec'],
                'startLat': flight.iloc[i - 1]['lat'],
                'startLon': flight.iloc[i - 1]['lon'],
                'startAltMeters': flight.iloc[i - 1]['altAGL'],
                'endTimeSec':
                startTimeSec + flight.iloc[i]['pathStartTimeSec'],
                'endLat': flight.iloc[i]['lat'],
                'endLon': flight.iloc[i]['lon'],
                'endAltMeters': flight.iloc[i]['altAGL'],
                'leafletColor': leafletColor,
                'leafletWeight': leafletWeight,
                'leafletStyle': leafletStyle,
                'leafletOpacity': leafletOpacity,
                'leafletCurveType': leafletCurveType,
                'leafletCurvature': leafletCurvature,
                'useArrows': useArrows,
                'modelScale': modelScale,
                'modelMinPxSize': modelMinPxSize,
                'cesiumColor': stripCesiumColor(cesiumColor),
                'cesiumWeight': cesiumWeight,
                'cesiumStyle': cesiumStyle,
                'cesiumOpacity': cesiumOpacity,
                'ganttColor': ganttColor,
                'popupText': popupText,
                'startElevMeters': None,
                'endElevMeters': None,
                'wayname': None,
                'waycategory': None,
                'surface': None,
                'waytype': None,
                'steepness': None,
                'tollway': None
            },
            ignore_index=True)

        # If they need loitering, add the line of loitering
        if (flight.iloc[i]['loiterTime'] != 0):
            assignments = assignments.append(
                {
                    'odID':
                    odID,
                    'objectID':
                    objectID,
                    'modelFile':
                    modelFile,
                    'startTimeSec':
                    startTimeSec + flight.iloc[i]['pathStartTimeSec'],
                    'startLat':
                    flight.iloc[i]['lat'],
                    'startLon':
                    flight.iloc[i]['lon'],
                    'startAltMeters':
                    flight.iloc[i]['altAGL'],
                    'endTimeSec':
                    startTimeSec + flight.iloc[i]['pathEndTimeSec'],
                    'endLat':
                    flight.iloc[i]['lat'],
                    'endLon':
                    flight.iloc[i]['lon'],
                    'endAltMeters':
                    flight.iloc[i]['altAGL'],
                    'leafletColor':
                    leafletColor,
                    'leafletWeight':
                    leafletWeight,
                    'leafletStyle':
                    leafletStyle,
                    'leafletOpacity':
                    leafletOpacity,
                    'leafletCurveType':
                    leafletCurveType,
                    'leafletCurvature':
                    leafletCurvature,
                    'useArrows':
                    useArrows,
                    'modelScale':
                    modelScale,
                    'modelMinPxSize':
                    modelMinPxSize,
                    'cesiumColor':
                    stripCesiumColor(cesiumColor),
                    'cesiumWeight':
                    cesiumWeight,
                    'cesiumStyle':
                    cesiumStyle,
                    'cesiumOpacity':
                    cesiumOpacity,
                    'ganttColor':
                    ganttColorLoiter,
                    'popupText':
                    popupText,
                    'startElevMeters':
                    None,
                    'endElevMeters':
                    None,
                    'wayname':
                    None,
                    'waycategory':
                    None,
                    'surface':
                    None,
                    'waytype':
                    None,
                    'steepness':
                    None,
                    'tollway':
                    None
                },
                ignore_index=True)

    return assignments
Example #3
0
def privGetShapepoints2D(
        odID=1,
        objectID=None,
        modelFile=None,
        startLoc=None,
        endLoc=None,
        startTimeSec=0.0,
        expDurationSec=None,
        routeType='euclidean2D',
        speedMPS=None,
        leafletColor=config['VRV_DEFAULT_LEAFLETARCCOLOR'],
        leafletWeight=config['VRV_DEFAULT_LEAFLETARCWEIGHT'],
        leafletStyle=config['VRV_DEFAULT_LEAFLETARCSTYLE'],
        leafletOpacity=config['VRV_DEFAULT_LEAFLETARCOPACITY'],
        leafletCurveType=config['VRV_DEFAULT_ARCCURVETYPE'],
        leafletCurvature=config['VRV_DEFAULT_ARCCURVATURE'],
        useArrows=True,
        modelScale=config['VRV_DEFAULT_CESIUMMODELSCALE'],
        modelMinPxSize=config['VRV_DEFAULT_CESIUMMODELMINPXSIZE'],
        cesiumColor=config['VRV_DEFAULT_CESIUMPATHCOLOR'],
        cesiumWeight=config['VRV_DEFAULT_CESIUMPATHWEIGHT'],
        cesiumStyle=config['VRV_DEFAULT_CESIUMPATHSTYLE'],
        cesiumOpacity=config['VRV_DEFAULT_CESIUMPATHOPACITY'],
        ganttColor=config['VRV_DEFAULT_GANTTCOLOR'],
        popupText=None,
        dataProvider=None,
        dataProviderArgs=None):

    # Replace backslash
    modelFile = replaceBackslashToSlash(modelFile)

    # Ensure leading slash
    modelFile = addHeadSlash(modelFile)

    try:
        dataProvider = dataProvider.lower()
    except:
        pass

    try:
        routeType = routeType.lower()
    except:
        pass

    if (startLoc != endLoc):
        extras = {}
        if (routeType == 'euclidean2d'):
            [path, time,
             dist] = _eucGetShapepointsTimeDist(startLoc, endLoc, speedMPS,
                                                expDurationSec)
        elif (routeType == 'manhattan'):
            [path, time,
             dist] = _manGetShapepointsTimeDist(startLoc, endLoc, speedMPS,
                                                expDurationSec)
        elif (routeType == 'fastest'
              and dataProviderDictionary[dataProvider] == 'pgrouting'):
            databaseName = dataProviderArgs['databaseName']
            [path, time,
             dist] = pgrGetShapepointsTimeDist(startLoc, endLoc, databaseName)
        elif (routeType == 'fastest'
              and dataProviderDictionary[dataProvider] == 'osrm-online'):
            [path, time, dist] = osrmGetShapepointsTimeDist(startLoc, endLoc)
        elif (routeType in ['fastest', 'shortest', 'pedestrian']
              and dataProviderDictionary[dataProvider] == 'mapquest'):
            APIkey = dataProviderArgs['APIkey']
            [path, time,
             dist] = mqGetShapepointsTimeDist(startLoc, endLoc, routeType,
                                              APIkey)
        elif (routeType
              in ['fastest', 'pedestrian', 'cycling', 'truck', 'wheelchair']
              and dataProviderDictionary[dataProvider] == 'ors-online'):
            APIkey = dataProviderArgs['APIkey']
            if ('requestExtras' in dataProviderArgs.keys()):
                requestExtras = dataProviderArgs['requestExtras']
            else:
                requestExtras = True
            [path, extras, time,
             dist] = orsGetShapepointsTimeDist(startLoc, endLoc, routeType,
                                               APIkey, requestExtras)
        elif (routeType in ['fastest', 'pedestrian', 'cycling', 'truck']
              and dataProviderDictionary[dataProvider] == 'ors-local'):
            port = dataProviderArgs['port']
            if ('requestExtras' in dataProviderArgs.keys()):
                requestExtras = dataProviderArgs['requestExtras']
            else:
                requestExtras = True
            [path, extras, time,
             dist] = orsLocalGetShapepointsTimeDist(startLoc, endLoc,
                                                    routeType, port,
                                                    requestExtras)
        else:
            return

        # Check if the original point is too far away from the actual start point of the shapepoints from query
        distOri = geoDistance2D(startLoc, path[0])
        if (distOri >= config['VRV_DEFAULT_DISTANCE_ERROR_TOLERANCE']
            ):  # Go back to 10m after testing
            print(
                "Message: The origin point (lat: %s, lon: %s) is %.1f meters away from the road. You might find a gap between the origin point and the route."
                % (startLoc[0], startLoc[1], distOri))

        # Check if the actual end point is too far away from destination point
        distDes = geoDistance2D(path[-1], endLoc)
        if (distDes >= config['VRV_DEFAULT_DISTANCE_ERROR_TOLERANCE']
            ):  # Go back to 10m after testing
            print(
                "Message: The destination point (lat: %s, lon: %s) is %.1f meters away from the road. You might find a gap between destination point and the route."
                % (endLoc[0], endLoc[1], distDes))

        # convert distance to accumulated distance
        accDist = []
        accDist.append(0)
        for i in range(1, len(dist)):
            accDist.append(accDist[i - 1] + dist[i])

        # If `expDurationSec` is provided, override `speedMPS` and datasource, otherwise, if `speedMPS` is provided, override datasource
        if (expDurationSec != None):
            [newTime, newDist] = distributeTimeDist(path, expDurationSec)
            time = newTime
            dist = newDist
        elif (speedMPS != None and expDurationSec == None):
            newExpDurationSec = accDist[len(accDist) - 1] / speedMPS
            [newTime, newDist] = distributeTimeDist(path, newExpDurationSec)
            time = newTime
            dist = newDist

        # convert time to accumulated time
        accTime = []
        accTime.append(startTimeSec)
        for i in range(1, len(dist)):
            accTime.append(accTime[i - 1] + time[i])

        # For maintainability, convert locs into dictionary
        dicPath = locs2Dict(path)

        # shapepoint dataframe
        assignments = privInitDataframe('Assignments')

        # generate assignments
        for i in range(1, len(path)):
            if (i - 1) in extras:
                startElev = extras[i -
                                   1]['elev'] if 'elev' in extras[i -
                                                                  1] else None
                wayname = extras[i]['wayname'] if 'wayname' in extras[
                    i] else None
                waycategory = extras[i][
                    'waycategory'] if 'waycategory' in extras[i] else None
                surface = extras[i]['surface'] if 'surface' in extras[
                    i] else None
                waytype = extras[i]['waytype'] if 'waytype' in extras[
                    i] else None
                steepness = extras[i]['steepness'] if 'steepness' in extras[
                    i] else None
                tollway = extras[i]['tollway'] if 'tollway' in extras[
                    i] else None
            else:
                startElev = None
                wayname = None
                waycategory = None
                surface = None
                waytype = None
                steepness = None
                tollway = None

            if i in extras:
                endElev = extras[i]['elev'] if 'elev' in extras[i] else None
            else:
                endElev = None

            assignments = assignments.append(
                {
                    'odID': odID,
                    'objectID': objectID,
                    'modelFile': modelFile,
                    'startTimeSec': accTime[i - 1],
                    'startLat': dicPath[i - 1]['lat'],
                    'startLon': dicPath[i - 1]['lon'],
                    'startAltMeters': dicPath[i - 1]['alt'],
                    'endTimeSec': accTime[i],
                    'endLat': dicPath[i]['lat'],
                    'endLon': dicPath[i]['lon'],
                    'endAltMeters': dicPath[i]['alt'],
                    'leafletColor': leafletColor,
                    'leafletWeight': leafletWeight,
                    'leafletStyle': leafletStyle,
                    'leafletCurveType': leafletCurveType,
                    'leafletCurvature': leafletCurvature,
                    'useArrows': useArrows,
                    'leafletOpacity': leafletOpacity,
                    'modelScale': modelScale,
                    'modelMinPxSize': modelMinPxSize,
                    'cesiumColor': stripCesiumColor(cesiumColor),
                    'cesiumWeight': cesiumWeight,
                    'cesiumStyle': cesiumStyle,
                    'cesiumOpacity': cesiumOpacity,
                    'ganttColor': ganttColor,
                    'popupText': popupText,
                    'startElevMeters': startElev,
                    'endElevMeters': endElev,
                    'wayname': wayname,
                    'waycategory': waycategory,
                    'surface': surface,
                    'waytype': waytype,
                    'steepness': steepness,
                    'tollway': tollway
                },
                ignore_index=True)
    else:
        # For maintainability, convert locs into dictionary
        dicStartLoc = loc2Dict(startLoc)

        if (dataProviderDictionary[dataProvider] == 'ors-online'):
            [[lat, lon, elev]] = orsGetElevation([startLoc],
                                                 dataProviderArgs['APIkey'])
        else:
            elev = None

        assignments = privInitDataframe('Assignments')
        assignments = assignments.append(
            {
                'odID':
                odID,
                'objectID':
                objectID,
                'modelFile':
                modelFile,
                'startTimeSec':
                startTimeSec,
                'startLat':
                dicStartLoc['lat'],
                'startLon':
                dicStartLoc['lon'],
                'startAltMeters':
                dicStartLoc['alt'],
                'endTimeSec':
                expDurationSec + startTimeSec if
                (expDurationSec is not None) else startTimeSec,
                'endLat':
                dicStartLoc['lat'],
                'endLon':
                dicStartLoc['lon'],
                'endAltMeters':
                dicStartLoc['alt'],
                'leafletColor':
                leafletColor,
                'leafletWeight':
                leafletWeight,
                'leafletStyle':
                leafletStyle,
                'leafletCurveType':
                leafletCurveType,
                'leafletCurvature':
                leafletCurvature,
                'useArrows':
                useArrows,
                'leafletOpacity':
                leafletOpacity,
                'modelScale':
                modelScale,
                'modelMinPxSize':
                modelMinPxSize,
                'cesiumColor':
                stripCesiumColor(cesiumColor),
                'cesiumWeight':
                cesiumWeight,
                'cesiumStyle':
                cesiumStyle,
                'cesiumOpacity':
                cesiumOpacity,
                'ganttColor':
                ganttColor,
                'popupText':
                popupText,
                'startElevMeters':
                elev,
                'endElevMeters':
                elev,
                'wayname':
                None,
                'waycategory':
                None,
                'surface':
                None,
                'waytype':
                None,
                'steepness':
                None,
                'tollway':
                None
            },
            ignore_index=True)

    return assignments
Example #4
0
def privGetShapepoints2D(odID=1,
                         objectID=None,
                         modelFile=None,
                         startLoc=None,
                         endLoc=None,
                         startTimeSec=0.0,
                         expDurationSec=None,
                         routeType='euclidean2D',
                         speedMPS=None,
                         leafletColor=VRV_DEFAULT_LEAFLETARCCOLOR,
                         leafletWeight=VRV_DEFAULT_LEAFLETARCWEIGHT,
                         leafletStyle=VRV_DEFAULT_LEAFLETARCSTYLE,
                         leafletOpacity=VRV_DEFAULT_LEAFLETARCOPACITY,
                         useArrows=True,
                         modelScale=VRV_DEFAULT_CESIUMMODELSCALE,
                         modelMinPxSize=VRV_DEFAULT_CESIUMMODELMINPXSIZE,
                         cesiumColor=VRV_DEFAULT_CESIUMPATHCOLOR,
                         cesiumWeight=VRV_DEFAULT_CESIUMPATHWEIGHT,
                         cesiumStyle=VRV_DEFAULT_CESIUMPATHSTYLE,
                         cesiumOpacity=VRV_DEFAULT_CESIUMPATHOPACITY,
                         dataProvider=None,
                         dataProviderArgs=None):

    # Replace backslash
    modelFile = replaceBackslashToSlash(modelFile)

    try:
        dataProvider = dataProvider.lower()
    except:
        pass

    try:
        routeType = routeType.lower()
    except:
        pass

    if (startLoc != endLoc):
        if (routeType == 'euclidean2d'):
            [path, time,
             dist] = _eucGetShapepointsTimeDist(startLoc, endLoc, speedMPS,
                                                expDurationSec)
        elif (routeType == 'manhattan'):
            [path, time,
             dist] = _manGetShapepointsTimeDist(startLoc, endLoc, speedMPS,
                                                expDurationSec)
        elif (routeType == 'fastest'
              and dataProviderDictionary[dataProvider] == 'pgrouting'):
            databaseName = dataProviderArgs['databaseName']
            [path, time,
             dist] = pgrGetShapepointsTimeDist(startLoc, endLoc, databaseName)
        elif (routeType == 'fastest'
              and dataProviderDictionary[dataProvider] == 'osrm-online'):
            [path, time, dist] = osrmGetShapepointsTimeDist(startLoc, endLoc)
        elif (routeType in ['fastest', 'shortest', 'pedestrian']
              and dataProviderDictionary[dataProvider] == 'mapquest'):
            APIkey = dataProviderArgs['APIkey']
            [path, time,
             dist] = mqGetShapepointsTimeDist(startLoc, endLoc, routeType,
                                              APIkey)
        elif (routeType in ['fastest', 'pedestrian', 'cycling', 'truck']
              and dataProviderDictionary[dataProvider] == 'ors-online'):
            APIkey = dataProviderArgs['APIkey']
            [path, time,
             dist] = orsGetShapepointsTimeDist(startLoc, endLoc, routeType,
                                               APIkey)
        else:
            return

        # Check if the original point is too far away from the actual start point of the shapepoints from query
        distOri = geoDistance2D(startLoc, path[0])
        if (distOri >= VRV_DEFAULT_DISTANCE_ERROR_TOLERANCE
            ):  # Go back to 10m after testing
            print(
                "Message: The origin point (lat: %s, lon: %s) is %.1f meters away from the road. You might find a gap between the origin point and the route."
                % (startLoc[0], startLoc[1], distOri))

        # Check if the actual end point is too far away from destination point
        distDes = geoDistance2D(path[-1], endLoc)
        if (distDes >= VRV_DEFAULT_DISTANCE_ERROR_TOLERANCE
            ):  # Go back to 10m after testing
            print(
                "Message: The destination point (lat: %s, lon: %s) is %.1f meters away from the road. You might find a gap between destination point and the route."
                % (endLoc[0], endLoc[1], distDes))

        # convert distance to accumulated distance
        accDist = []
        accDist.append(0)
        for i in range(1, len(dist)):
            accDist.append(accDist[i - 1] + dist[i])

        # If `expDurationSec` is provided, override `speedMPS` and datasource, otherwise, if `speedMPS` is provided, override datasource
        if (expDurationSec != None):
            [newTime, newDist] = distributeTimeDist(path, expDurationSec)
            time = newTime
            dist = newDist
        elif (speedMPS != None and expDurationSec == None):
            newExpDurationSec = accDist[len(accDist) - 1] / speedMPS
            [newTime, newDist] = distributeTimeDist(path, newExpDurationSec)
            time = newTime
            dist = newDist

        # convert time to accumulated time
        accTime = []
        accTime.append(startTimeSec)
        for i in range(1, len(dist)):
            accTime.append(accTime[i - 1] + time[i])

        # For maintainability, convert locs into dictionary
        dicPath = locs2Dict(path)

        # shapepoint dataframe
        assignments = initDataframe('Assignments')

        # generate assignments
        for i in range(1, len(path)):
            assignments = assignments.append(
                {
                    'odID': odID,
                    'objectID': objectID,
                    'modelFile': modelFile,
                    'startTimeSec': accTime[i - 1],
                    'startLat': dicPath[i - 1]['lat'],
                    'startLon': dicPath[i - 1]['lon'],
                    'startAltMeters': dicPath[i - 1]['alt'],
                    'endTimeSec': accTime[i],
                    'endLat': dicPath[i]['lat'],
                    'endLon': dicPath[i]['lon'],
                    'endAltMeters': dicPath[i]['alt'],
                    'leafletColor': leafletColor,
                    'leafletWeight': leafletWeight,
                    'leafletStyle': leafletStyle,
                    'useArrows': useArrows,
                    'leafletOpacity': leafletOpacity,
                    'modelScale': modelScale,
                    'modelMinPxSize': modelMinPxSize,
                    'cesiumColor': cesiumColor,
                    'cesiumWeight': cesiumWeight,
                    'cesiumStyle': cesiumStyle,
                    'cesiumOpacity': cesiumOpacity
                },
                ignore_index=True)
    else:
        # For maintainability, convert locs into dictionary
        dicStartLoc = loc2Dict(startLoc)

        assignments = initDataframe('Assignments')
        assignments = assignments.append(
            {
                'odID':
                odID,
                'objectID':
                objectID,
                'modelFile':
                modelFile,
                'startTimeSec':
                startTimeSec,
                'startLat':
                dicStartLoc['lat'],
                'startLon':
                dicStartLoc['lon'],
                'startAltMeters':
                dicStartLoc['alt'],
                'endTimeSec':
                expDurationSec + startTimeSec if
                (expDurationSec is not None) else startTimeSec,
                'endLat':
                dicStartLoc['lat'],
                'endLon':
                dicStartLoc['lon'],
                'endAltMeters':
                dicStartLoc['alt'],
                'leafletColor':
                leafletColor,
                'leafletWeight':
                leafletWeight,
                'leafletStyle':
                leafletStyle,
                'useArrows':
                useArrows,
                'leafletOpacity':
                leafletOpacity,
                'modelScale':
                modelScale,
                'modelMinPxSize':
                modelMinPxSize,
                'cesiumColor':
                cesiumColor,
                'cesiumWeight':
                cesiumWeight,
                'cesiumStyle':
                cesiumStyle,
                'cesiumOpacity':
                cesiumOpacity
            },
            ignore_index=True)

    return assignments
Example #5
0
def createCesium(assignments=None,
                 nodes=None,
                 startDate=None,
                 startTime='08:00:00',
                 postBuffer=30,
                 cesiumDir=None,
                 problemDir=None,
                 nodeColor=None,
                 nodeStyle=None,
                 pathColor=None,
                 pathWeight=None,
                 pathStyle=None,
                 pathOpacity=None):
    """
	This function generates several files required to view a solution in Cesium. The function requires assignments and/or nodes dataframes as input. 

	Parameters
	----------
	assignments: :ref:`Assignments`, Conditional, `assignments` and `nodes` can not be None at the same time
		An :ref:`Assignments` dataframe describing vehicle movement over time.  The assignments will be displayed as routes/paths in Cesium.  If a 3D model is defined in the `modelFile` column of the assignments dataframe, this object will also be displayed.
	nodes: :ref:`Nodes`, Conditional, `assignments` and `nodes` can not be None at the same time
		A :ref:`Nodes` dataframe describing the locations of nodes.  These nodes will be displayed on the map in Cesium.  
	startDate: string, Optional, format is "YYYY-MM-DD", default as today
		Defines the start date to be displayed in Cesium.
	startTime: string, Optional, format is "HH:MM:SS", default as '08:00:00'
		Defines the time at which the Cesium video begins, on the start date.
	postBuffer: int, Optional, default as 30
		Specifies the additional time (in seconds) that the Cesium video will continue to run after the last assignment is completed. 
	cesiumDir: string, Required, default as None
		This should be the full absolute path to the directory where Cesium is installed. For example, for Windows it might be "D:/Cesium"; for Linux it might be "/home/user/Cesium".
	problemDir: string, Required, default as None
		The path name of the generated problem directory. This path is relative to the root of Cesium. For example, if `cesiumDir = '/home/user/Cesium'` and `problemDir = 'veroviz/problems/TSP'` then the files will be generated in the directory `'/home/user/Cesium/veroviz/problems/TSP'`.
	nodeColor: string, Optional, default as None
		Overrides the `cesiumColor` column of the input `nodes` dataframe.  This will define the color of all nodes displayed in Cesium.  See :ref:`Cesium Style` for the collection of available colors. 
	nodeStyle: string, Optional, default as None
		Overrides the `cesiumIconType` column of the input `nodes` dataframe.  Currently, the only option is 'pin'.
	pathColor: string, Optional, default as None
		Overrides the `cesiumColor` column of the input `assignments` dataframe.  This will define the color of all arcs displayed in Cesium.  See :ref:`Cesium Style` for the collection of available colors.
	pathWeight: int, Optional, default as None
		Overrides the `cesiumWeight` column of the input `assignments` dataframe. This will define the weight (in pixels) of all arcs displayed in Cesium. See :ref:`Cesium Style` for more information.
	pathStyle: string, Optional, default as None
		Overrides the `cesiumStyle` column of the input `assignments` dataframe. This will define the style of all arcs displayed in Cesium. See :ref:`Cesium Style` for available options.
	pathOpacity: float in [0, 1], Optional, default as None
		Overrides the `cesiumOpacity` column of the input `assignments` dataframe.  This will define the opacity of all arcs displayed in Cesium.  See :ref:`Cesium Style` for more information.

	Return
	------
	N/A

	Note
	----
	This function generates the following files within the directory specified by input argument `problemDir`:

	- [problemDir].vrv (where [problemDir] is replaced by the value of `problemDir`);
	- config.js
	- displayNodes.js
	- displayPath.js
	- routes.czml

	Instructions for starting Cesium are provided at https://veroviz.org/documentation.html

	Example
	--------
	Import veroviz and check the latest version.
		>>> import veroviz as vrv
		>>> import os

		>>> vrv.checkVersion()
		
	Create two nodes.
		>>> myNodes = vrv.createNodesFromLocs(
		...     locs = [[42.1538, -78.4253],
		...             [42.6343, -78.1146]])
		>>> myNodes

	Move the truck from one node to the other.
		>>> myAssignments = vrv.getShapepoints2D(
		...     odID           = 0,
		...     objectID       = 'truck',
		...     modelFile      = 'veroviz/models/ub_truck.gltf',
		...     modelScale     = 80, 
		...     modelMinPxSize = 20, 
		...     startLoc       = list(myNodes.loc[0][['lat', 'lon']].values),
		...     endLoc         = list(myNodes.loc[1][['lat', 'lon']].values),
		...     routeType      = 'euclidean2D',
		...     dataProvider   = None,
		...     speedMPS       = vrv.convertSpeed(55, 'miles', 'hr', 'm', 's'))	
		
	Create Cesium output.
		>>> vrv.createCesium(
		...     assignments = myAssignments, 
		...     nodes       = myNodes, 
		...     startTime   = '08:00:00', 
		...     cesiumDir   = os.environ['CESIUMDIR'],
		...     problemDir  = 'createCesium_example')
	"""

    # validation
    [valFlag, errorMsg,
     warningMsg] = valCreateCesium(assignments, nodes, startDate, startTime,
                                   postBuffer, cesiumDir, problemDir,
                                   nodeColor, pathColor, pathWeight, pathStyle,
                                   pathOpacity)
    if (not valFlag):
        print(errorMsg)
        return
    elif (VRV_SETTING_SHOWWARNINGMESSAGE and warningMsg != ""):
        print(warningMsg)

    # Set default start date as today
    if (startDate is None):
        startDate = datetime.date.today()

    # Some modification about slashes:
    # cesiumDir - no tail slash
    # problemDir - no head slash and no tail slash
    # Change all backslash to slash
    cesiumDir = delTailSlash(cesiumDir)
    problemDir = delTailSlash(problemDir)
    problemDir = delHeadSlash(problemDir)
    cesiumDir = replaceBackslashToSlash(cesiumDir)
    problemDir = replaceBackslashToSlash(problemDir)

    # In case the problemDir does not exist
    fullDir = '%s/%s' % (cesiumDir, problemDir)
    if not os.path.exists(fullDir):
        os.makedirs(fullDir, exist_ok=True)

    # Mission duration, from time zero to endtime+postBuffer
    availStart = _getCesiumTime(startDate, startTime, 0)
    availEnd = _getCesiumTime(startDate, startTime,
                              (max(assignments['endTimeSec']) + postBuffer))

    # Decode Assignments dataframe to a Path dataframe (with details of a path) and a list of Assignments dataframes, and generate .js and .czml files
    [path, lstSubAssignments] = _getPathsDetails(assignments)
    lstNonStationarySubAssignments = deconstructAssignments(
        assignments=assignments, includeVerticalFlag=True)

    # Update 'intervalStart' and 'intervalEnd' to cesiumTime
    for i in path.index:
        path.at[i,
                'intervalStart'] = _getCesiumTime(startDate, startTime,
                                                  path.at[i, 'startTimeSec'])
        path.at[i, 'intervalEnd'] = _getCesiumTime(
            startDate, startTime, path.at[i, 'endTimeSec']) if (
                path.at[i, 'endTimeSec'] >= 0) else availEnd
    path.drop(columns=['startTimeSec', 'endTimeSec'])

    # Write problem selector
    _writeSelector(fullDir, problemDir)

    # Write Configs
    mapBoundary = getMapBoundary(nodes=nodes, arcs=assignments, locs=None)
    _writeConfigs(mapBoundary, availStart, path, fullDir, problemDir)

    # Write Nodes
    if (nodes is not None):
        _writeNodes(nodes, nodeColor, fullDir)

    # Write Assignments
    if (len(path) > 0):
        _writeAssignmentsJS(lstNonStationarySubAssignments, pathColor,
                            pathWeight, pathStyle, pathOpacity, fullDir)
        _writeAssignmentsCZML(path, lstSubAssignments, availStart, availEnd,
                              fullDir)

    return
def privAddStaticAssignment(
        initAssignments=None,
        odID=1,
        objectID=None,
        modelFile=None,
        modelScale=config['VRV_DEFAULT_CESIUMMODELSCALE'],
        modelMinPxSize=config['VRV_DEFAULT_CESIUMMODELMINPXSIZE'],
        loc=None,
        startTimeSec=None,
        endTimeSec=None,
        ganttColor=config['VRV_DEFAULT_GANTTCOLOR'],
        popupText=None):

    # Replace backslash
    modelFile = replaceBackslashToSlash(modelFile)

    # Ensure leading slash
    modelFile = addHeadSlash(modelFile)

    # assignment dataframe
    assignments = privInitDataframe('Assignments')

    dicLoc = loc2Dict(loc)

    assignments = assignments.append(
        {
            'odID': odID,
            'objectID': objectID,
            'modelFile': modelFile,
            'modelScale': modelScale,
            'modelMinPxSize': modelMinPxSize,
            'startTimeSec': startTimeSec,
            'startLat': dicLoc['lat'],
            'startLon': dicLoc['lon'],
            'startAltMeters': dicLoc['alt'],
            'endTimeSec': endTimeSec,
            'endLat': dicLoc['lat'],
            'endLon': dicLoc['lon'],
            'endAltMeters': dicLoc['alt'],
            'ganttColor': ganttColor,
            'popupText': popupText,
            'leafletColor': None,
            'leafletWeight': None,
            'leafletStyle': None,
            'leafletOpacity': None,
            'leafletCurveType': None,
            'leafletCurvature': None,
            'cesiumColor': None,
            'cesiumWeight': None,
            'cesiumStyle': None,
            'cesiumOpacity': None,
            'useArrows': None,
            'startElevMeters': None,
            'endElevMeters': None,
            'wayname': None,
            'waycategory': None,
            'surface': None,
            'waytype': None,
            'steepness': None,
            'tollway': None
        },
        ignore_index=True,
        sort=False)

    if (type(initAssignments) is pd.core.frame.DataFrame):
        assignments = pd.concat([initAssignments, assignments],
                                ignore_index=True)

    return assignments