Ejemplo n.º 1
0
def CornerEstimationWithoutOffsets(packet):
    ''' Corner estimation without Offsets '''
    try:
        sensorLatitude = packet.SensorLatitude
        sensorLongitude = packet.SensorLongitude
        sensorTrueAltitude = packet.SensorTrueAltitude
        frameCenterLat = packet.FrameCenterLatitude
        frameCenterLon = packet.FrameCenterLongitude
        frameCenterElevation = packet.FrameCenterElevation
        sensorVerticalFOV = packet.SensorVerticalFieldOfView
        sensorHorizontalFOV = packet.SensorHorizontalFieldOfView
        headingAngle = packet.PlatformHeadingAngle
        sensorRelativeAzimut = packet.SensorRelativeAzimuthAngle
        targetWidth = packet.targetWidth
        slantRange = packet.SlantRange

        # If target width = 0 (occurs on some platforms), compute it with the slate range.
        # Otherwise it leaves the footprint as a point.
        # In some case targetWidth don't have value then equal to 0
        if targetWidth is None:
            targetWidth = 0
        if targetWidth == 0 and slantRange != 0:
            targetWidth = 2.0 * slantRange * \
                tan(radians(sensorHorizontalFOV / 2.0))
        elif targetWidth == 0 and slantRange == 0:
            # default target width to not leave footprint as a point.
            targetWidth = defaultTargetWidth
            qgsu.showUserAndLogMessage(
                QCoreApplication.translate(
                    "QgsFmvUtils", "Target width unknown, defaults to: " +
                    str(targetWidth) + "m."))

        # compute distance to ground
        if frameCenterElevation != 0:
            sensorGroundAltitude = sensorTrueAltitude - frameCenterElevation
        else:
            qgsu.showUserAndLogMessage(
                QCoreApplication.translate(
                    "QgsFmvUtils",
                    "Sensor ground elevation narrowed to true altitude: " +
                    str(sensorTrueAltitude) + "m."))
            sensorGroundAltitude = sensorTrueAltitude

        if sensorLatitude == 0:
            return False

        if sensorLongitude is None or sensorLatitude is None:
            return False

        initialPoint = (sensorLongitude, sensorLatitude)

        if frameCenterLon is None or frameCenterLat is None:
            return False

        destPoint = (frameCenterLon, frameCenterLat)

        distance = sphere.distance(initialPoint, destPoint)
        if distance == 0:
            return False

        if sensorVerticalFOV > 0 and sensorHorizontalFOV > sensorVerticalFOV:
            aspectRatio = sensorVerticalFOV / sensorHorizontalFOV

        else:
            aspectRatio = 0.75

        value2 = (headingAngle + sensorRelativeAzimut) % 360.0  # Heading
        value3 = targetWidth / 2.0

        value5 = sqrt(pow(distance, 2.0) + pow(sensorGroundAltitude, 2.0))
        value6 = targetWidth * aspectRatio / 2.0

        degrees = rad2deg(atan(value3 / distance))

        value8 = rad2deg(atan(distance / sensorGroundAltitude))
        value9 = rad2deg(atan(value6 / value5))
        value10 = value8 + value9
        value11 = sensorGroundAltitude * tan(radians(value10))
        value12 = value8 - value9
        value13 = sensorGroundAltitude * tan(radians(value12))
        value14 = distance - value13
        value15 = value11 - distance
        value16 = value3 - value14 * tan(radians(degrees))
        value17 = value3 + value15 * tan(radians(degrees))
        distance2 = sqrt(pow(value14, 2.0) + pow(value16, 2.0))
        value19 = sqrt(pow(value15, 2.0) + pow(value17, 2.0))
        value20 = rad2deg(atan(value16 / value14))
        value21 = rad2deg(atan(value17 / value15))

        # CP Up Left
        bearing = (value2 + 360.0 - value21) % 360.0
        cornerPointUL = list(
            reversed(sphere.destination(destPoint, value19, bearing)))

        # CP Up Right
        bearing = (value2 + value21) % 360.0
        cornerPointUR = list(
            reversed(sphere.destination(destPoint, value19, bearing)))

        # CP Low Right
        bearing = (value2 + 180.0 - value20) % 360.0
        cornerPointLR = list(
            reversed(sphere.destination(destPoint, distance2, bearing)))

        # CP Low Left
        bearing = (value2 + 180.0 + value20) % 360.0
        cornerPointLL = list(
            reversed(sphere.destination(destPoint, distance2, bearing)))

        if hasElevationModel():
            pCornerPointUL = GetLine3DIntersectionWithDEM(
                GetSensor(), cornerPointUL)
            pCornerPointUR = GetLine3DIntersectionWithDEM(
                GetSensor(), cornerPointUR)
            pCornerPointLR = GetLine3DIntersectionWithDEM(
                GetSensor(), cornerPointLR)
            pCornerPointLL = GetLine3DIntersectionWithDEM(
                GetSensor(), cornerPointLL)

            UpdateFootPrintData(packet, pCornerPointUL, pCornerPointUR,
                                pCornerPointLR, pCornerPointLL,
                                hasElevationModel())

            UpdateBeamsData(packet, pCornerPointUL,
                            pCornerPointUR, pCornerPointLR, pCornerPointLL,
                            hasElevationModel())

        else:
            UpdateFootPrintData(packet, cornerPointUL, cornerPointUR,
                                cornerPointLR, cornerPointLL,
                                hasElevationModel())

            UpdateBeamsData(packet, cornerPointUL, cornerPointUR,
                            cornerPointLR, cornerPointLL, hasElevationModel())

        SetGCPsToGeoTransform(cornerPointUL, cornerPointUR, cornerPointLR,
                              cornerPointLL, frameCenterLon, frameCenterLat)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate(
                "QgsFmvUtils", "CornerEstimationWithoutOffsets failed! : "),
            str(e))
        return False

    return True
Ejemplo n.º 2
0
def CornerEstimationWithoutOffsets(packet):
    ''' Corner estimation without Offsets '''
    try:
        sensorLatitude = packet.GetSensorLatitude()
        sensorLongitude = packet.GetSensorLongitude()
        sensorTrueAltitude = packet.GetSensorTrueAltitude()
        frameCenterLat = packet.GetFrameCenterLatitude()
        frameCenterLon = packet.GetFrameCenterLongitude()
        sensorVerticalFOV = packet.GetSensorVerticalFieldOfView()
        sensorHorizontalFOV = packet.GetSensorHorizontalFieldOfView()
        headingAngle = packet.GetPlatformHeadingAngle()
        sensorRelativeAzimut = packet.GetSensorRelativeAzimuthAngle()
        targetWidth = packet.GettargetWidth()

        if sensorLatitude == 0:
            return False

        initialPoint = (sensorLongitude, sensorLatitude)
        destPoint = (frameCenterLon, frameCenterLat)

        distance = sphere.distance(initialPoint, destPoint)
        if distance == 0:
            return False

        if sensorVerticalFOV > 0 and sensorHorizontalFOV > sensorVerticalFOV:
            aspectRatio = sensorVerticalFOV / sensorHorizontalFOV

        else:
            aspectRatio = 0.75

        value2 = (headingAngle + sensorRelativeAzimut) % 360.0  # Heading
        value3 = targetWidth / 2.0

        value5 = sqrt(pow(distance, 2.0) + pow(sensorTrueAltitude, 2.0))
        value6 = targetWidth * aspectRatio / 2.0

        degrees = rad2deg(atan(value3 / distance))

        value8 = rad2deg(atan(distance / sensorTrueAltitude))
        value9 = rad2deg(atan(value6 / value5))
        value10 = value8 + value9
        value11 = sensorTrueAltitude * tan(radians(value10))
        value12 = value8 - value9
        value13 = sensorTrueAltitude * tan(radians(value12))
        value14 = distance - value13
        value15 = value11 - distance
        value16 = value3 - value14 * tan(radians(degrees))
        value17 = value3 + value15 * tan(radians(degrees))
        distance2 = sqrt(pow(value14, 2.0) + pow(value16, 2.0))
        value19 = sqrt(pow(value15, 2.0) + pow(value17, 2.0))
        value20 = rad2deg(atan(value16 / value14))
        value21 = rad2deg(atan(value17 / value15))

        # CP Up Left
        bearing = (value2 + 360.0 - value21) % 360.0
        cornerPointUL = sphere.destination(destPoint, value19, bearing)

        # TODO: Use Geopy?
        #         from geopy import Point
        #         from geopy.distance import distance, VincentyDistance
        #
        #         # given: lat1, lon1, bearing, distMiles
        #         lat2, lon2 = VincentyDistance(kilometers=value19).destination(Point(destPoint[1], destPoint[0]), bearing)

        # CP Up Right
        bearing = (value2 + value21) % 360.0
        cornerPointUR = sphere.destination(destPoint, value19, bearing)

        # CP Low Right
        bearing = (value2 + 180.0 - value20) % 360.0
        cornerPointLR = sphere.destination(destPoint, distance2, bearing)

        # CP Low Left
        bearing = (value2 + 180.0 + value20) % 360.0
        cornerPointLL = sphere.destination(destPoint, distance2, bearing)

        UpdateFootPrintData(cornerPointUL, cornerPointUR, cornerPointLR,
                            cornerPointLL)

        UpdateBeamsData(packet, cornerPointUL, cornerPointUR, cornerPointLR,
                        cornerPointLL)

        SetGCPsToGeoTransform(cornerPointUL, cornerPointUR, cornerPointLR,
                              cornerPointLL, frameCenterLon, frameCenterLat)
    except:
        return False

    return True