sumolib.sensors.inductive_loop
Library for reading and storing Inductive Loop detector representations and measurements.
1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 2# Copyright (C) 2010-2026 German Aerospace Center (DLR) and others. 3# This program and the accompanying materials are made available under the 4# terms of the Eclipse Public License 2.0 which is available at 5# https://www.eclipse.org/legal/epl-2.0/ 6# This Source Code may also be made available under the following Secondary 7# Licenses when the conditions for such availability set forth in the Eclipse 8# Public License 2.0 are satisfied: GNU General Public License, version 2 9# or later which is available at 10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 12 13# @file inductive_loop.py 14# @author Daniel Krajzewicz 15# @author Michael Behrisch 16# @author Jakob Erdmann 17# @date 2010-02-18 18 19""" 20Library for reading and storing Inductive Loop detector representations and 21 measurements. 22""" 23from __future__ import absolute_import 24 25from xml.sax import handler, parse 26 27 28class InductiveLoop: 29 30 def __init__(self, id, lane, pos, frequency=60, file="NUL", friendlyPos=True, vTypes=""): 31 self.id = id 32 self.lane = lane 33 self.pos = pos 34 self.frequency = frequency 35 self.file = file 36 self.friendlyPos = friendlyPos 37 self.vTypes = vTypes 38 39 def toXML(self): 40 return '<e1Detector id="%s" lane="%s" pos="%s" freq="%s" file="%s" friendlyPos="%s" vTypes="%s"/>' % ( 41 self.id, self.lane, self.pos, self.frequency, self.file, self.friendlyPos, self.vTypes) 42 43 44class InductiveLoopReader(handler.ContentHandler): 45 46 def __init__(self): 47 self._id2il = {} 48 self._ils = [] 49 self._lastIL = None 50 self.attributes = {} 51 52 def startElement(self, name, attrs): 53 if name == 'e1Detector': 54 poi = InductiveLoop(attrs['id'], attrs['lane'], float( 55 attrs['pos']), float(attrs['freq']), attrs['file']) 56 self._id2il[poi.id] = poi 57 self._ils.append(poi) 58 self._lastIL = poi 59 if name == 'param' and self._lastIL is not None: 60 self._lastIL.attributes[attrs['key']] = attrs['value'] 61 62 def endElement(self, name): 63 if name == 'e1Detector': 64 self._lastIL = None 65 66 67def read(filename): 68 ils = InductiveLoopReader() 69 parse(filename, ils) 70 return ils._ils
class
InductiveLoop:
29class InductiveLoop: 30 31 def __init__(self, id, lane, pos, frequency=60, file="NUL", friendlyPos=True, vTypes=""): 32 self.id = id 33 self.lane = lane 34 self.pos = pos 35 self.frequency = frequency 36 self.file = file 37 self.friendlyPos = friendlyPos 38 self.vTypes = vTypes 39 40 def toXML(self): 41 return '<e1Detector id="%s" lane="%s" pos="%s" freq="%s" file="%s" friendlyPos="%s" vTypes="%s"/>' % ( 42 self.id, self.lane, self.pos, self.frequency, self.file, self.friendlyPos, self.vTypes)
class
InductiveLoopReader(xml.sax.handler.ContentHandler):
45class InductiveLoopReader(handler.ContentHandler): 46 47 def __init__(self): 48 self._id2il = {} 49 self._ils = [] 50 self._lastIL = None 51 self.attributes = {} 52 53 def startElement(self, name, attrs): 54 if name == 'e1Detector': 55 poi = InductiveLoop(attrs['id'], attrs['lane'], float( 56 attrs['pos']), float(attrs['freq']), attrs['file']) 57 self._id2il[poi.id] = poi 58 self._ils.append(poi) 59 self._lastIL = poi 60 if name == 'param' and self._lastIL is not None: 61 self._lastIL.attributes[attrs['key']] = attrs['value'] 62 63 def endElement(self, name): 64 if name == 'e1Detector': 65 self._lastIL = None
Interface for receiving logical document content events.
This is the main callback interface in SAX, and the one most important to applications. The order of events in this interface mirrors the order of the information in the document.
def
startElement(self, name, attrs):
53 def startElement(self, name, attrs): 54 if name == 'e1Detector': 55 poi = InductiveLoop(attrs['id'], attrs['lane'], float( 56 attrs['pos']), float(attrs['freq']), attrs['file']) 57 self._id2il[poi.id] = poi 58 self._ils.append(poi) 59 self._lastIL = poi 60 if name == 'param' and self._lastIL is not None: 61 self._lastIL.attributes[attrs['key']] = attrs['value']
Signals the start of an element in non-namespace mode.
The name parameter contains the raw XML 1.0 name of the element type as a string and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.
def
read(filename):