Example #1
0
 def createConnector(self, fromLink, fromLane, toLink, toLane, lanes,
                     **kwargs):
     """ Create a new connector in the model.
         Input: from link, from lane, to link, to lane, attributes
         Output: Added <link> element to <links> element.
     """
     num = self._getNewNum('link')
     defaults = {'assumSpeedOncom': '60.00000', 'costPerKm': '0.00000',
                 'direction': 'ALL',
                 'displayType': self._getDefaultNum('displayType'),
                 'emergStopDist': '5.00000', 'gradient': '0.00000',
                 'hasOvtLn': 'false', 'isPedArea': 'false',
                 'linkBehavType': self._getDefaultNum('linkBehaviorType'),
                 'linkEvalAct': 'false',
                 'linkEvalSegLen': '10.00000', 'lnChgDist': '200.00000',
                 'lnChgDistIsPerLn': 'false',
                 'lnChgEvalAct': 'true', 'lookAheadDistOvt': '250.00000',
                 'mesoFollowUpGap': '0.00000', 'mesoSpeed': '50.00000',
                 'mesoSpeedModel': 'VEHICLEBASED', 'name': '',
                 'ovtOnlyPT': 'false', 'ovtSpeedFact': '1.300000',
                 'showClsfValues': 'true', 'showLinkBar': 'true',
                 'showVeh': 'true', 'surch1': '0.00000',
                 'surch2': '0.00000', 'thickness': '0.00000',
                 'vehRecAct': 'true', 'no': num}
     data = self.data
     a = {k: str(kwargs.get(k, v)) for k, v in defaults.items()}
     etree.SubElement(data.xpath('./links')[0], 'link', attrib=a)
     fromAttr = {'lane': str(fromLink) + ' ' + str(fromLane),
                 'pos': kwargs.get('fromPos', self.getLinkLength(fromLink))}
     self._setChild('no', a['no'], 'fromLinkEndPt', fromAttr)
     self._setChild('no', a['no'], 'geometry', None)
     self._setChild('no', a['no'], 'points3D', None, '/geometry')
     fromGeo = self.getGeometries(fromLink)[-2:]
     fromPoint = [(v['x'], v['y'], v['zOffset']) for v in fromGeo]
     clockwise, fromDist = self.connectorLocation(fromLink, fromLane, lanes)
     fromPoint = geo.offsetParallel(fromPoint, fromDist,
                                    clockwise=clockwise)
     toGeo = self.getGeometries(toLink)[:2]
     toPoint = [(v['x'], v['y'], v['zOffset']) for v in toGeo]
     clockwise, toDist = self.connectorLocation(toLink, toLane, lanes)
     toPoint = geo.offsetParallel(toPoint, toDist, clockwise=clockwise)
     point3D = kwargs.get('point3D', [fromPoint[-1], toPoint[0]])
     self.addGeometry(a['no'], point3D)
     self._setChild('no', a['no'], 'lanes', None)
     # Check number of lanes doesn't exceed the number of from/to lanes
     if (len(self.getLanes(fromLink)) >= lanes and
             len(self.getLanes(toLink)) >= lanes):
         for lane in range(lanes):
             self._setChild('no', a['no'], 'lane', None, '/lanes')
     else:
         raise ValueError('Number of lanes exceeds number of from/to lanes')
     toAttr = {'lane': str(toLink) + ' ' + str(toLane),
               'pos': kwargs.get('toPos', '0.0000')}
     self._setChild('no', a['no'], 'toLinkEndPt', toAttr)
     self._getParams()
     return self.getConnector(a['no'])
Example #2
0
 def nodesToXY(self, attr):
     """ Process links dictionary to calculate proper XY coordinates.
         Input: links dictionary
         Output: updated links dictionary with xy dictionary
     """
     width = self.v.defaultWidth
     nodes = attr['nodes']
     point3D = attr['point3D'] = [self.nodeToScaledMeters(n) for n in nodes]
     # Parallel
     if not self.isOneway(attr):
         dist = attr['offset'] * width
         point3D = geo.offsetParallel(point3D, dist)
     # Endpoints / Turns
     if nodes[0] in self.intersections:
         dist = self.getCrossStreets(nodes[0], nodes[1]) * width
         point3D[0] = geo.offsetEndpoint(point3D, dist)
     if nodes[-1] in self.intersections:
         dist = self.getCrossStreets(nodes[-1], nodes[-2]) * width
         point3D[-1] = geo.offsetEndpoint(point3D, dist, beginning=False)
     # Turn dictionary only for ways pointing toward the intersection
     attr['turns'] = self.calcTurns(nodes[-1], nodes[-2])
     attr['point3D'] = [stringify(i) for i in point3D]
     return attr
Example #3
0
 def nodesToXY(self, attr):
     """ Process links dictionary to calculate proper XY coordinates.
         Input: links dictionary
         Output: updated links dictionary with xy dictionary
     """
     width = self.v.defaultWidth
     nodes = attr['nodes']
     point3D = attr['point3D'] = [self.nodeToScaledMeters(n) for n in nodes]
     # Parallel
     if not self.isOneway(attr):
         dist = attr['offset'] * width
         point3D = geo.offsetParallel(point3D, dist)
     # Endpoints / Turns
     if nodes[0] in self.intersections:
         dist = self.getCrossStreets(nodes[0], nodes[1]) * width
         point3D[0] = geo.offsetEndpoint(point3D, dist)
     if nodes[-1] in self.intersections:
         dist = self.getCrossStreets(nodes[-1], nodes[-2]) * width
         point3D[-1] = geo.offsetEndpoint(point3D, dist, beginning=False)
     # Turn dictionary only for ways pointing toward the intersection
     attr['turns'] = self.calcTurns(nodes[-1], nodes[-2])
     attr['point3D'] = [stringify(i) for i in point3D]
     return attr
Example #4
0
    def nodesToXY(self, attr):
        """ Process links dictionary to calculate proper XY coordinates.
            Input: links dictionary
            Output: updated links dictionary with xy dictionary
        """
        width = self.v.defaultWidth
        nodes = attr['nodes']
        #print "#######", nodes
        point3D = attr['point3D'] = [self.nodeToScaledMeters(n) for n in nodes]
        #print point3D

        # Parallel
        if not self.isOneway(attr):
            dist = attr['offset'] * width
            #print "###", point3D
            #print nodes
            #tt = geo.offsetEndpoint(point3D, 1.0)
            #print tt
            #print "@@@", point3D
            '''tt = [[468.514244231,48.6922583583,0],
                  [468.069585906,89.8343879775,0],
                  [476.929403034,136.402838403,0]]
			'''
            point3D = geo.offsetParallel(point3D, dist)
            #point3D = geo.offsetParallel(point3D, dist)
        # Endpoints / Turns
        if nodes[0] in self.intersections:
            dist = self.getCrossStreets(nodes[0], nodes[1]) * width
            point3D[0] = geo.offsetEndpoint(point3D, dist)
        if nodes[-1] in self.intersections:
            dist = self.getCrossStreets(nodes[-1], nodes[-2]) * width
            point3D[-1] = geo.offsetEndpoint(point3D, dist, beginning=False)
        # Turn dictionary only for ways pointing toward the intersection
        attr['turns'] = self.calcTurns(nodes[-1], nodes[-2])
        attr['point3D'] = [stringify(i) for i in point3D]
        return attr
Example #5
0
 def createConnector(self, fromLink, fromLane, toLink, toLane, lanes,
                     **kwargs):
     """ Create a new connector in the model.
         Input: from link, from lane, to link, to lane, attributes
         Output: Added <link> element to <links> element.
     """
     num = self._getNewNum('link')
     defaults = {
         'assumSpeedOncom': '60.00000',
         'costPerKm': '0.00000',
         'direction': 'ALL',
         'displayType': self._getDefaultNum('displayType'),
         'emergStopDist': '5.00000',
         'gradient': '0.00000',
         'hasOvtLn': 'false',
         'isPedArea': 'false',
         'linkBehavType': self._getDefaultNum('linkBehaviorType'),
         'linkEvalAct': 'false',
         'linkEvalSegLen': '10.00000',
         'lnChgDist': '200.00000',
         'lnChgDistIsPerLn': 'false',
         'lnChgEvalAct': 'true',
         'lookAheadDistOvt': '250.00000',
         'mesoFollowUpGap': '0.00000',
         'mesoSpeed': '50.00000',
         'mesoSpeedModel': 'VEHICLEBASED',
         'name': '',
         'ovtOnlyPT': 'false',
         'ovtSpeedFact': '1.300000',
         'showClsfValues': 'true',
         'showLinkBar': 'true',
         'showVeh': 'true',
         'surch1': '0.00000',
         'surch2': '0.00000',
         'thickness': '0.00000',
         'vehRecAct': 'true',
         'no': num
     }
     data = self.data
     a = {k: str(kwargs.get(k, v)) for k, v in defaults.items()}
     etree.SubElement(data.xpath('./links')[0], 'link', attrib=a)
     fromAttr = {
         'lane': str(fromLink) + ' ' + str(fromLane),
         'pos': kwargs.get('fromPos', self.getLinkLength(fromLink))
     }
     self._setChild('no', a['no'], 'fromLinkEndPt', fromAttr)
     self._setChild('no', a['no'], 'geometry', None)
     self._setChild('no', a['no'], 'points3D', None, '/geometry')
     fromGeo = self.getGeometries(fromLink)[-2:]
     fromPoint = [(v['x'], v['y'], v['zOffset']) for v in fromGeo]
     clockwise, fromDist = self.connectorLocation(fromLink, fromLane, lanes)
     fromPoint = geo.offsetParallel(fromPoint,
                                    fromDist,
                                    clockwise=clockwise)
     toGeo = self.getGeometries(toLink)[:2]
     toPoint = [(v['x'], v['y'], v['zOffset']) for v in toGeo]
     clockwise, toDist = self.connectorLocation(toLink, toLane, lanes)
     toPoint = geo.offsetParallel(toPoint, toDist, clockwise=clockwise)
     point3D = kwargs.get('point3D', [fromPoint[-1], toPoint[0]])
     self.addGeometry(a['no'], point3D)
     self._setChild('no', a['no'], 'lanes', None)
     # Check number of lanes doesn't exceed the number of from/to lanes
     if (len(self.getLanes(fromLink)) >= lanes
             and len(self.getLanes(toLink)) >= lanes):
         for lane in range(lanes):
             self._setChild('no', a['no'], 'lane', None, '/lanes')
     else:
         raise ValueError('Number of lanes exceeds number of from/to lanes')
     toAttr = {
         'lane': str(toLink) + ' ' + str(toLane),
         'pos': kwargs.get('toPos', '0.0000')
     }
     self._setChild('no', a['no'], 'toLinkEndPt', toAttr)
     self._getParams()
     return self.getConnector(a['no'])