Exemple #1
0
def UpdateLayers(packet, parent=None, mosaic=False):
    ''' Update Layers Values '''
    global frameCenterElevation
    global sensorLatitude
    global sensorLongitude
    global sensorTrueAltitude

    frameCenterLat = packet.GetFrameCenterLatitude()
    frameCenterLon = packet.GetFrameCenterLongitude()
    frameCenterElevation = packet.GetFrameCenterElevation()
    sensorLatitude = packet.GetSensorLatitude()
    sensorLongitude = packet.GetSensorLongitude()
    sensorTrueAltitude = packet.GetSensorTrueAltitude()

    UpdatePlatformData(packet)
    UpdateTrajectoryData(packet)
    UpdateFrameCenterData(packet)

    OffsetLat1 = packet.GetOffsetCornerLatitudePoint1()
    LatitudePoint1Full = packet.GetCornerLatitudePoint1Full()

    if OffsetLat1 is not None and LatitudePoint1Full is None:
        CornerEstimationWithOffsets(packet)
        if mosaic:
            georeferencingVideo(parent)
        return

    if OffsetLat1 is None and LatitudePoint1Full is None:
        CornerEstimationWithoutOffsets(packet)
        if mosaic:
            georeferencingVideo(parent)
        return

    cornerPointUL = [
        packet.GetCornerLatitudePoint1Full(),
        packet.GetCornerLongitudePoint1Full()
    ]

    if None in cornerPointUL:
        return

    cornerPointUR = [
        packet.GetCornerLatitudePoint2Full(),
        packet.GetCornerLongitudePoint2Full()
    ]

    if None in cornerPointUR:
        return

    cornerPointLR = [
        packet.GetCornerLatitudePoint3Full(),
        packet.GetCornerLongitudePoint3Full()
    ]

    if None in cornerPointLR:
        return

    cornerPointLL = [
        packet.GetCornerLatitudePoint4Full(),
        packet.GetCornerLongitudePoint4Full()
    ]

    if None in cornerPointLL:
        return

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

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

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

    if mosaic:
        georeferencingVideo(parent)
    return
Exemple #2
0
def UpdateLayers(packet, parent=None, mosaic=False):
    ''' Update Layers Values '''

    global frameCenterElevation, sensorLatitude, sensorLongitude, sensorTrueAltitude

    frameCenterLat = packet.FrameCenterLatitude
    frameCenterLon = packet.FrameCenterLongitude
    frameCenterElevation = packet.FrameCenterElevation
    sensorLatitude = packet.SensorLatitude
    sensorLongitude = packet.SensorLongitude
    sensorTrueAltitude = packet.SensorTrueAltitude
    OffsetLat1 = packet.OffsetCornerLatitudePoint1
    LatitudePoint1Full = packet.CornerLatitudePoint1Full

    UpdatePlatformData(packet, hasElevationModel())
    UpdateTrajectoryData(packet, hasElevationModel())
    UpdateFrameCenterData(packet, hasElevationModel())
    UpdateFrameAxisData(packet, hasElevationModel())

    if OffsetLat1 is not None and LatitudePoint1Full is None:
        CornerEstimationWithOffsets(packet)
        if mosaic:
            georeferencingVideo(parent)

    elif OffsetLat1 is None and LatitudePoint1Full is None:
        CornerEstimationWithoutOffsets(packet)
        if mosaic:
            georeferencingVideo(parent)

    else:
        cornerPointUL = [
            packet.CornerLatitudePoint1Full, packet.CornerLongitudePoint1Full
        ]
        if None in cornerPointUL:
            return

        cornerPointUR = [
            packet.CornerLatitudePoint2Full, packet.CornerLongitudePoint2Full
        ]
        if None in cornerPointUR:
            return

        cornerPointLR = [
            packet.CornerLatitudePoint3Full, packet.CornerLongitudePoint3Full
        ]

        if None in cornerPointLR:
            return

        cornerPointLL = [
            packet.CornerLatitudePoint4Full, packet.CornerLongitudePoint4Full
        ]

        if None in cornerPointLL:
            return
        UpdateFootPrintData(packet, cornerPointUL, cornerPointUR,
                            cornerPointLR, cornerPointLL, hasElevationModel())

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

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

        if mosaic:
            georeferencingVideo(parent)

    # recenter map on platform
    if centerMode == 1:
        lyr = qgsu.selectLayerByName(Platform_lyr)
        iface.mapCanvas().setExtent(lyr.extent())
    # recenter map on footprint
    elif centerMode == 2:
        lyr = qgsu.selectLayerByName(Footprint_lyr)
        iface.mapCanvas().setExtent(lyr.extent())
    # recenter map on target
    elif centerMode == 3:
        lyr = qgsu.selectLayerByName(FrameCenter_lyr)
        iface.mapCanvas().setExtent(lyr.extent())

    iface.mapCanvas().refresh()
    return
Exemple #3
0
def UpdateLayers(packet, parent=None, mosaic=False, group=None):
    ''' Update Layers Values '''
    gv.setGroupName(group)
    groupName = group
    # frameCenterLat = packet.FrameCenterLatitude
    # frameCenterLon = packet.FrameCenterLongitude
    gv.setFrameCenterElevation(packet.FrameCenterElevation)
    gv.setSensorLatitude(packet.SensorLatitude)
    gv.setSensorLongitude(packet.SensorLongitude)

    sensorTrueAltitude = packet.SensorTrueAltitude
    gv.setSensorTrueAltitude(sensorTrueAltitude)
    sensorRelativeElevationAngle = packet.SensorRelativeElevationAngle
    slantRange = packet.SlantRange
    OffsetLat1 = packet.OffsetCornerLatitudePoint1
    LatitudePoint1Full = packet.CornerLatitudePoint1Full

    UpdatePlatformData(packet, hasElevationModel())
    UpdateTrajectoryData(packet, hasElevationModel())

    frameCenterPoint = [
        packet.FrameCenterLatitude, packet.FrameCenterLongitude,
        packet.FrameCenterElevation
    ]

    # If no framcenter (f.i. horizontal target) don't comptute footprint,
    # beams and frame center
    if (frameCenterPoint[0] is None and frameCenterPoint[1] is None):
        gv.setTransform(None)
        return True

    # No framecenter altitude
    if (frameCenterPoint[2] is None):
        if (sensorRelativeElevationAngle is not None
                and slantRange is not None):
            frameCenterPoint[2] = sensorTrueAltitude - \
                sin(sensorRelativeElevationAngle) * slantRange
        else:
            frameCenterPoint[2] = 0.0

    # qgsu.showUserAndLogMessage("", "FC Alt:"+str(frameCenterPoint[2]), onlyLog=True)

    if OffsetLat1 is not None and LatitudePoint1Full is None:
        if hasElevationModel():
            frameCenterPoint = GetLine3DIntersectionWithDEM(
                GetSensor(), frameCenterPoint)

        CornerEstimationWithOffsets(packet)
        if mosaic:
            georeferencingVideo(parent)

    elif OffsetLat1 is None and LatitudePoint1Full is None:
        if hasElevationModel():
            frameCenterPoint = GetLine3DIntersectionWithDEM(
                GetSensor(), frameCenterPoint)

        CornerEstimationWithoutOffsets(packet)
        if mosaic:
            georeferencingVideo(parent)

    else:
        cornerPointUL = [
            packet.CornerLatitudePoint1Full, packet.CornerLongitudePoint1Full
        ]
        if None in cornerPointUL:
            return False

        cornerPointUR = [
            packet.CornerLatitudePoint2Full, packet.CornerLongitudePoint2Full
        ]
        if None in cornerPointUR:
            return False

        cornerPointLR = [
            packet.CornerLatitudePoint3Full, packet.CornerLongitudePoint3Full
        ]

        if None in cornerPointLR:
            return False

        cornerPointLL = [
            packet.CornerLatitudePoint4Full, packet.CornerLongitudePoint4Full
        ]

        if None in cornerPointLL:
            return False

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

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

        SetGCPsToGeoTransform(cornerPointUL, cornerPointUR, cornerPointLR,
                              cornerPointLL, frameCenterPoint[1],
                              frameCenterPoint[0], hasElevationModel())

        if mosaic:
            georeferencingVideo(parent)

    UpdateFrameCenterData(frameCenterPoint, hasElevationModel())
    UpdateFrameAxisData(packet.ImageSourceSensor, GetSensor(),
                        frameCenterPoint, hasElevationModel())

    # detect if we need a recenter or not. If Footprint and Platform fits in
    # 80% of the map, do not trigger recenter.
    f_lyr = qgsu.selectLayerByName(Footprint_lyr, groupName)
    p_lyr = qgsu.selectLayerByName(Platform_lyr, groupName)
    t_lyr = qgsu.selectLayerByName(FrameCenter_lyr, groupName)

    iface = gv.getIface()
    centerMode = gv.getCenterMode()

    if f_lyr is not None and p_lyr is not None and t_lyr is not None:
        f_lyr_out_extent = f_lyr.extent()
        p_lyr_out_extent = p_lyr.extent()
        t_lyr_out_extent = t_lyr.extent()

        # Default EPSG is 4326, f_lyr.crs().authid ()
        # Disable transform if we have the same projection wit layers anf
        # canvas
        epsg4326 = "EPSG:4326"
        curAuthId = iface.mapCanvas().mapSettings().destinationCrs().authid()

        if (curAuthId != epsg4326):
            xform = QgsCoordinateTransform(
                QgsCoordinateReferenceSystem(epsg4326),
                QgsCoordinateReferenceSystem(curAuthId),
                QgsProject().instance())

            transP = xform.transform(
                QgsPointXY(
                    list(p_lyr.getFeatures())[0].geometry().asPoint().x(),
                    list(p_lyr.getFeatures())[0].geometry().asPoint().y()))
            transT = xform.transform(
                QgsPointXY(
                    list(t_lyr.getFeatures())[0].geometry().asPoint().x(),
                    list(t_lyr.getFeatures())[0].geometry().asPoint().y()))

            rect = list(f_lyr.getFeatures())[0].geometry().boundingBox()
            rectLL = xform.transform(
                QgsPointXY(rect.xMinimum(), rect.yMinimum()))
            rectUR = xform.transform(
                QgsPointXY(rect.xMaximum(), rect.yMaximum()))

            f_lyr_out_extent = QgsRectangle(rectLL, rectUR)
            t_lyr_out_extent = QgsRectangle(transT.x(), transT.y(), transT.x(),
                                            transT.y())
            p_lyr_out_extent = QgsRectangle(transP.x(), transP.y(), transP.x(),
                                            transP.y())

        bValue = iface.mapCanvas().extent().xMaximum() - iface.mapCanvas(
        ).center().x()

        # create a detection buffer
        map_detec_buffer = iface.mapCanvas().extent().buffered(bValue * -0.7)

        # recenter map on platform
        if not map_detec_buffer.contains(p_lyr_out_extent) and centerMode == 1:
            # recenter map on platform
            iface.mapCanvas().setExtent(p_lyr_out_extent)
        # recenter map on footprint
        elif not map_detec_buffer.contains(
                f_lyr_out_extent) and centerMode == 2:
            # zoom a bit wider than the footprint itself
            iface.mapCanvas().setExtent(
                f_lyr_out_extent.buffered(f_lyr_out_extent.width() * 0.5))
        # recenter map on target
        elif not map_detec_buffer.contains(
                t_lyr_out_extent) and centerMode == 3:
            iface.mapCanvas().setExtent(t_lyr_out_extent)

        # Refresh Canvas
        iface.mapCanvas().refresh()

        return True