示例#1
0
    def write_point_attributes(self, fow, frc, bear, lfrcnp, reserved):
        """Writes 2 bytes point attributes to the stream

        Parameters
        ----------
        fow :
            form of way (3 bits)
        frc : int
            functional road class (3 bits)
        bear : int
            Bearing (5 bits)
        lfrcnp : int
            Lowest FRC to next point or offset flags (3 bits)
        reserved : int
            mostly reserved for future use or Orientation/SideOfRoad (2 bits)
        """
        if bear < 0 or bear >= 360:
            raise ValueError(
                "Bearing angle requires 0 <= x < 360 but %s is given" % bear
            )
        bear = (bear - BEAR_SECTOR / 2) / BEAR_SECTOR
        bear = j_round(bear)
        fow = fow & 0b111
        frc = frc & 0b111
        bear = bear & 0b11111
        lfrcnp = lfrcnp & 0b111
        reserved = reserved & 0b11
        byte_int = fow + (frc << 3) + (reserved << 6)
        self.write(int_to_bytes(byte_int, size=1, signed=False))
        byte_int = bear + (lfrcnp << 5)
        self.write(int_to_bytes(byte_int, size=1, signed=False))
示例#2
0
def _create_offset_el(doc, el_loc):

    if el_loc.poffs > 0:
        poffs = j_round(float(el_loc.points[0].dnp) * el_loc.poffs)
    else:
        poffs = 0

    if hasattr(el_loc, "noffs") and el_loc.noffs > 0:
        noffs = j_round(float(el_loc.points[-2].dnp) * el_loc.noffs)
    else:
        noffs = 0

    el_offset = doc.createElement("Offsets")
    el_offset.appendChild(_create_data_el(doc, "PosOff", poffs))
    el_offset.appendChild(_create_data_el(doc, "NegOff", noffs))
    return el_offset
示例#3
0
    def write_coords_relative(self, lon, lat, prev_lon, prev_lat):
        """Writes the relative coordinates to the stream, 4 bytes

        Parameters
        ----------
        lon : float
            Longitude to be written
        lat : float
            Latitude to be written
        prev_lon : float
            Previous Longitude
        prev_lat : float
            Previous Latitude
        """
        rel_lon = j_round(DECA_MICRO_DEG_FACTOR * (lon - prev_lon))
        rel_lat = j_round(DECA_MICRO_DEG_FACTOR * (lat - prev_lat))
        self.write(int_to_bytes(rel_lon, size=2) + int_to_bytes(rel_lat, size=2))
示例#4
0
    def write_dnp(self, dnp):
        """Writes distance to next point to the stream, 1 byte

        Parameters
        ----------
        dnp : int
            distance to next point
        """
        interval = float(dnp) / DISTANCE_PER_INTERVAL - 0.5
        interval = j_round(interval)
        self.write(int_to_bytes(interval, size=1, signed=False))
示例#5
0
    def read_dnp(self):
        """Reads distance to next point from the buffer, 1 byte

        Returns
        -------
        dnp : int
            Distance to next point
        """
        interval = bytes_to_int(self.read(1), signed=False)
        dnp = (float(interval) + 0.5) * DISTANCE_PER_INTERVAL
        dnp = j_round(dnp)
        return dnp
示例#6
0
    def write_offset(self, offset):
        """Writes offset rate to the stream, 1 byte

        Parameters
        ----------
        offset : float
            offset rate in [0,1] range
        """
        if offset < 0 or offset >= 1:
            raise ValueError("offset requires 0 <= x < 1 but %s is given" % offset)
        elif offset == 0:
            bucket_index = 0
        else:
            bucket_index = float(offset) * 256 - 0.5
            bucket_index = j_round(bucket_index)
        self.write(int_to_bytes(bucket_index, size=1, signed=False))
示例#7
0
def deg_to_int(deg, resolution=24):
    r"""converts degree coordinate into integer

    .. math::
        \mathrm{int} = 0.5 \times \mathop{\mathrm{sgn}}(\mathrm{deg}) +
            \frac{\mathrm{deg} \times 2^{\mathrm{resolution}}}{360^{\circ}}

    Parameters
    ----------
    deg : float
        Coordinate Degree
    resolution: int
        Resolution bits of this integer, default: 3 bytes = 24

    Returns
    -------
    val : int
        Coordinate value in integer
    """
    val = sgn(deg) * 0.5 + float(deg * (1 << resolution)) / 360.0
    return j_round(val)
示例#8
0
    def read_point_attributes(self):
        """Reads point attributes from the buffer, 2 bytes

        Returns
        -------
        fow : int
            form of way (3 bits)
        frc : int
            functional road class (3 bits)
        bear : int
            Bearing (5 bits)
        lfrcnp : int
            Lowest FRC to next point or offset flags (3 bits)
        reserved : int
            mostly reserved for future use or Orientation/SideOfRoad (2 bits)
        """
        first_b, second_b = self.read(2)
        fow = first_b & 0b111
        frc = (first_b >> 3) & 0b111
        reserved = (first_b >> 6) & 0b11
        bear = (second_b & 0b11111) * BEAR_SECTOR + BEAR_SECTOR / 2
        bear = j_round(bear)
        lfrcnp = (second_b >> 5) & 0b111
        return fow, frc, bear, lfrcnp, reserved