Esempio n. 1
0
def RemoveAllDrawPolygonOnMap():
    ''' Remove all features on Polygon Layer '''
    polyLyr = qgsu.selectLayerByName(Polygon_lyr)
    if polyLyr is None:
        return
    polyLyr.startEditing()
    polyLyr.dataProvider().truncate()
    CommonLayer(polyLyr)
    return
Esempio n. 2
0
def UpdateTrajectoryData(packet):
    ''' Update Trajectory Values '''
    global tLastLon
    global tLastLat

    lat = packet.GetSensorLatitude()
    lon = packet.GetSensorLongitude()
    alt = packet.GetSensorTrueAltitude()

    try:
        if tLastLon == 0.0 and tLastLat == 0.0:
            tLastLon = lon
            tLastLat = lat
        else:
            # little check to see if telemetry data are plausible before
            # drawing.

            distance = sphere.distance((tLastLon, tLastLat), (lon, lat))
            if distance > 1000:  # 1 km is the best value for prevent draw trajectory when start video again
                return
    except Exception:
        None

    tLastLon = lon
    tLastLat = lat
    trajectoryLyr = qgsu.selectLayerByName(Trajectory_lyr)

    try:
        if all(v is not None for v in [trajectoryLyr, lat, lon, alt]):
            trajectoryLyr.startEditing()
            f = QgsFeature()
            if trajectoryLyr.featureCount() == 0:
                f.setAttributes([lon, lat, alt])
                surface = QgsGeometry.fromPolylineXY(
                    [QgsPointXY(lon, lat),
                     QgsPointXY(lon, lat)])
                f.setGeometry(surface)
                trajectoryLyr.addFeatures([f])

            else:
                f_last = trajectoryLyr.getFeature(trajectoryLyr.featureCount())
                f.setAttributes([lon, lat, alt])
                surface = QgsGeometry.fromPolylineXY([
                    QgsPointXY(lon, lat),
                    QgsPointXY(f_last.attribute(0), f_last.attribute(1))
                ])
                f.setGeometry(surface)
                trajectoryLyr.addFeatures([f])

            CommonLayer(trajectoryLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvUtils",
                                       "Failed Update Trajectory Layer! : "),
            str(e))
    return
Esempio n. 3
0
def UpdateFrameAxisData(packet, ele):
    ''' Update Frame Axis Values '''
    global crtSensorSrc2

    imgSS = packet.ImageSourceSensor
    lat = packet.SensorLatitude
    lon = packet.SensorLongitude
    alt = packet.SensorTrueAltitude
    fc_lat = packet.FrameCenterLatitude
    fc_lon = packet.FrameCenterLongitude
    fc_alt = packet.FrameCenterElevation

    frameaxisLyr = qgsu.selectLayerByName(FrameAxis_lyr)

    try:
        if all(v is not None
               for v in [frameaxisLyr, lat, lon, alt, fc_lat, fc_lon]):
            if (imgSS != crtSensorSrc2):
                SetDefaultFrameAxisStyle(frameaxisLyr, imgSS)
                crtSensorSrc2 = imgSS
            frameaxisLyr.startEditing()
            if frameaxisLyr.featureCount() == 0:
                f = QgsFeature()
                f.setAttributes([lon, lat, alt, fc_lon, fc_lat, fc_alt])
                f.setGeometry(
                    QgsLineString(QgsPoint(lon, lat, alt),
                                  QgsPoint(fc_lon, fc_lat, fc_alt)))
                frameaxisLyr.addFeatures([f])
            else:
                frameaxisLyr.dataProvider().changeAttributeValues({
                    1: {
                        0: lon,
                        1: lat,
                        2: alt,
                        3: fc_lon,
                        4: fc_lat,
                        5: fc_alt
                    }
                })
                frameaxisLyr.dataProvider().changeGeometryValues({
                    1:
                    QgsGeometry(
                        QgsLineString(QgsPoint(lon, lat, alt),
                                      QgsPoint(fc_lon, fc_lat, fc_alt)))
                })

            CommonLayer(frameaxisLyr)
            # 3D Style
            if ele:
                SetDefaultFrameAxis3DStyle(frameaxisLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvUtils",
                                       "Failed Update Frame axis Layer! : "),
            str(e))
    return
Esempio n. 4
0
def RemoveAllDrawLineOnMap():
    ''' Remove all features on Line Layer '''
    lineLyr = qgsu.selectLayerByName(Line_lyr)
    if lineLyr is None:
        return
    lineLyr.startEditing()
    lineLyr.dataProvider().truncate()
    CommonLayer(lineLyr)
    return
Esempio n. 5
0
def RemoveVideoLayers():
    ''' Remove Video Layers '''
    try:
        QgsProject.instance().removeMapLayer(
            qgsu.selectLayerByName(Platform_lyr).id())
    except Exception:
        None
    try:
        QgsProject.instance().removeMapLayer(
            qgsu.selectLayerByName(Beams_lyr).id())
    except Exception:
        None
    try:
        QgsProject.instance().removeMapLayer(
            qgsu.selectLayerByName(Footprint_lyr).id())
    except Exception:
        None
    try:
        QgsProject.instance().removeMapLayer(
            qgsu.selectLayerByName(Trajectory_lyr).id())
    except Exception:
        None
    try:
        QgsProject.instance().removeMapLayer(
            qgsu.selectLayerByName(FrameCenter_lyr).id())
    except Exception:
        None
    try:
        QgsProject.instance().removeMapLayer(
            qgsu.selectLayerByName(FrameAxis_lyr).id())
    except Exception:
        None
    try:
        QgsProject.instance().removeMapLayer(
            qgsu.selectLayerByName(Point_lyr).id())
    except Exception:
        None
    try:
        QgsProject.instance().removeMapLayer(
            qgsu.selectLayerByName(Line_lyr).id())
    except Exception:
        None
    try:
        QgsProject.instance().removeMapLayer(
            qgsu.selectLayerByName(Polygon_lyr).id())
    except Exception:
        None
    iface.mapCanvas().refresh()
    return
Esempio n. 6
0
def RemoveLastDrawPointOnMap():
    ''' Remove Last features on Point Layer '''
    pointLyr = qgsu.selectLayerByName(Point_lyr)
    if pointLyr is None:
        return
    pointLyr.startEditing()
    listOfIds = [feat.id() for feat in pointLyr.getFeatures()]
    pointLyr.deleteFeature(listOfIds[-1])
    CommonLayer(pointLyr)
    return
Esempio n. 7
0
def RemoveLastDrawPolygonOnMap():
    '''  Remove Last Feature on Polygon Layer '''
    polyLyr = qgsu.selectLayerByName(Polygon_lyr, groupName)
    if polyLyr is None:
        return
    polyLyr.startEditing()
    listOfIds = [feat.id() for feat in polyLyr.getFeatures()]
    if listOfIds:
        polyLyr.deleteFeature(listOfIds[-1])
        CommonLayer(polyLyr)
    return
Esempio n. 8
0
def CreateVideoLayers():
    ''' Create Video Layers '''
    if qgsu.selectLayerByName(Footprint_lyr) is None:
        lyr_footprint = newPolygonsLayer(
            None,
            ["Corner Longitude Point 1",
             "Corner Latitude Point 1",
             "Corner Longitude Point 2",
             "Corner Latitude Point 2",
             "Corner Longitude Point 3",
             "Corner Latitude Point 3",
             "Corner Longitude Point 4",
             "Corner Latitude Point 4"],
            'EPSG:4326',
            Footprint_lyr)
        SetDefaultFootprintStyle(lyr_footprint)
        addLayerNoCrsDialog(lyr_footprint)

    if qgsu.selectLayerByName(Beams_lyr) is None:
        lyr_beams = newLinesLayer(
            None,
            ["longitude",
             "latitude",
             "altitude",
             "Corner Longitude",
             "Corner Latitude"],
            'EPSG:4326',
            Beams_lyr)
        SetDefaultBeamsStyle(lyr_beams)
        addLayerNoCrsDialog(lyr_beams)

    if qgsu.selectLayerByName(Trajectory_lyr) is None:
        lyr_Trajectory = newLinesLayer(
            None,
            ["longitude", "latitude", "altitude"], 'EPSG:4326', Trajectory_lyr)
        SetDefaultTrajectoryStyle(lyr_Trajectory)
        addLayerNoCrsDialog(lyr_Trajectory)

    if qgsu.selectLayerByName(Platform_lyr) is None:
        lyr_platform = newPointsLayer(
            None,
            ["longitude", "latitude", "altitude"], 'EPSG:4326', Platform_lyr)
        SetDefaultPlatformStyle(lyr_platform)
        addLayerNoCrsDialog(lyr_platform)

    if qgsu.selectLayerByName(Point_lyr) is None:
        lyr_point = newPointsLayer(
            None, ["longitude", "latitude", "altitude"], 'EPSG:4326', Point_lyr)
        SetDefaultPointStyle(lyr_point)
        addLayerNoCrsDialog(lyr_point)

    if qgsu.selectLayerByName(Line_lyr) is None:
        lyr_line = newLinesLayer(
            None, ["longitude", "latitude", "altitude"], 'EPSG:4326', Line_lyr)
        SetDefaultLineStyle(lyr_line)
        addLayerNoCrsDialog(lyr_line)

    QApplication.processEvents()
    return
Esempio n. 9
0
def AddDrawPointOnMap(pointIndex, Longitude, Latitude, Altitude):
    '''  add pin point on the map '''
    pointLyr = qgsu.selectLayerByName(Point_lyr, groupName)
    if pointLyr is None:
        return
    pointLyr.startEditing()
    feature = QgsFeature()
    feature.setAttributes([pointIndex, Longitude, Latitude, Altitude])
    p = QgsPointXY()
    p.set(Longitude, Latitude)
    feature.setGeometry(QgsGeometry.fromPointXY(p))
    pointLyr.addFeatures([feature])
    CommonLayer(pointLyr)
    return
Esempio n. 10
0
def UpdatePlatformData(packet):
    ''' Update PlatForm Values '''
    global crtPltTailNum
    lat = packet.GetSensorLatitude()
    lon = packet.GetSensorLongitude()
    alt = packet.GetSensorTrueAltitude()
    PlatformHeading = packet.GetPlatformHeadingAngle()
    platformTailNumber = packet.GetPlatformTailNumber()
    platformLyr = qgsu.selectLayerByName(Platform_lyr)

    try:
        if all(v is not None
               for v in [platformLyr, lat, lon, alt, PlatformHeading]):
            if platformTailNumber != crtPltTailNum:
                SetDefaultPlatformStyle(platformLyr, platformTailNumber)
                crtPltTailNum = platformTailNumber

            platformLyr.startEditing()
            platformLyr.renderer().symbol().setAngle(float(PlatformHeading))

            if platformLyr.featureCount() == 0:
                feature = QgsFeature()
                feature.setAttributes([lon, lat, alt])
                p = QgsPointXY()
                p.set(lon, lat)
                geom = QgsGeometry.fromPointXY(p)
                feature.setGeometry(geom)
                platformLyr.addFeatures([feature])

            else:
                platformLyr.beginEditCommand(
                    "ChangeGeometry + ChangeAttribute")
                fetId = 1
                attrib = {0: lon, 1: lat, 2: alt}
                platformLyr.dataProvider().changeAttributeValues(
                    {fetId: attrib})

                platformLyr.dataProvider().changeGeometryValues(
                    {1: QgsGeometry.fromPointXY(QgsPointXY(lon, lat))})
                platformLyr.endEditCommand()

            CommonLayer(platformLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvUtils",
                                       "Failed Update Platform Layer! : "),
            str(e))

    return
Esempio n. 11
0
def UpdateFrameAxisData(imgSS, sensor, framecenter, ele):
    ''' Update Frame Axis Values '''
    global crtSensorSrc2, groupName, frameAxisMarker

    lat = sensor[0]
    lon = sensor[1]
    alt = sensor[2]
    fc_lat = framecenter[0]
    fc_lon = framecenter[1]
    fc_alt = framecenter[2]

    frameaxisLyr = qgsu.selectLayerByName(FrameAxis_lyr, groupName)

    try:
        if all(
            v is not None for v in [
                frameaxisLyr,
                lat,
                lon,
                alt,
                fc_lat,
                fc_lon]):
            if(imgSS != crtSensorSrc2):
                SetDefaultFrameAxisStyle(frameaxisLyr, imgSS)
                crtSensorSrc2 = imgSS
            frameaxisLyr.startEditing()
            if frameaxisLyr.featureCount() == 0:
                f = QgsFeature()
                f.setAttributes(
                    [lon, lat, alt, fc_lon, fc_lat, fc_alt])
                f.setGeometry(
                    QgsLineString(
                        QgsPoint(
                            lon, lat, alt), QgsPoint(
                            fc_lon, fc_lat, fc_alt)))
                frameaxisLyr.addFeatures([f])
            else:
                frameaxisLyr.dataProvider().changeAttributeValues(
                    {1: {0: lon, 1: lat, 2: alt, 3: fc_lon, 4: fc_lat, 5: fc_alt}})
                frameaxisLyr.dataProvider().changeGeometryValues({1: QgsGeometry(
                    QgsLineString(QgsPoint(lon, lat, alt), QgsPoint(fc_lon, fc_lat, fc_alt)))})

            CommonLayer(frameaxisLyr)
            # 3D Style
            if ele:
                SetDefaultFrameAxis3DStyle(frameaxisLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(QCoreApplication.translate(
            "QgsFmvUtils", "Failed Update Frame axis Layer! : "), str(e))
Esempio n. 12
0
def UpdatePlatformData(packet, ele):
    ''' Update PlatForm Values '''
    global crtPltTailNum, groupName

    lat = packet.SensorLatitude
    lon = packet.SensorLongitude
    alt = packet.SensorTrueAltitude
    PlatformHeading = packet.PlatformHeadingAngle
    platformTailNumber = packet.PlatformTailNumber
    platformLyr = qgsu.selectLayerByName(Platform_lyr, groupName)

    try:
        if all(v is not None
               for v in [platformLyr, lat, lon, alt, PlatformHeading]):
            if platformTailNumber != crtPltTailNum:
                SetDefaultPlatformStyle(platformLyr, platformTailNumber)
                crtPltTailNum = platformTailNumber

            platformLyr.startEditing()
            platformLyr.renderer().symbol().setAngle(float(PlatformHeading))

            if platformLyr.featureCount() == 0:
                feature = QgsFeature()
                feature.setAttributes([lon, lat, alt])
                feature.setGeometry(QgsPoint(lon, lat, alt))
                platformLyr.addFeatures([feature])

            else:
                platformLyr.dataProvider().changeAttributeValues(
                    {1: {
                        0: lon,
                        1: lat,
                        2: alt
                    }})

                platformLyr.dataProvider().changeGeometryValues(
                    {1: QgsGeometry(QgsPoint(lon, lat, alt))})

            CommonLayer(platformLyr)
            # 3D Style
            if ele:
                SetDefaultPlatform3DStyle(platformLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvUtils",
                                       "Failed Update Platform Layer! : "),
            str(e))

    return
Esempio n. 13
0
def AddDrawPolygonOnMap(poly_coordinates):
    ''' Add Polygon Layer '''
    polyLyr = qgsu.selectLayerByName(Polygon_lyr, groupName)
    if polyLyr is None:
        return
    polyLyr.startEditing()
    feature = QgsFeature()
    point = QPointF()
    # create  float polygon --> construcet out of 'point'

    list_polygon = QPolygonF()
    for x in range(0, len(poly_coordinates)):
        if x % 2 == 0:
            point.setX(poly_coordinates[x])
            point.setY(poly_coordinates[x + 1])
            list_polygon.append(point)
    point.setX(poly_coordinates[0])
    point.setY(poly_coordinates[1])
    list_polygon.append(point)

    geomP = QgsGeometry.fromQPolygonF(list_polygon)
    feature.setGeometry(geomP)

    # Calculate Area WSG84 (Meters)
    area_wsg84 = QgsDistanceArea()
    area_wsg84.setSourceCrs(
        QgsCoordinateReferenceSystem.fromOgcWmsCrs('EPSG:4326'),
        _layerreg.transformContext())
    if (area_wsg84.sourceCrs().isGeographic()):
        area_wsg84.setEllipsoid(area_wsg84.sourceCrs().ellipsoidAcronym())

    # Calculate Centroid
    try:
        centroid = feature.geometry().centroid().asPoint()
    except Exception:
        iface.vectorLayerTools().stopEditing(polyLyr, False)
        return False

    feature.setAttributes([
        centroid.x(),
        centroid.y(), 0.0,
        area_wsg84.measurePolygon(geomP.asPolygon()[0])
    ])

    polyLyr.addFeatures([feature])

    CommonLayer(polyLyr)
    return True
Esempio n. 14
0
def UpdateFrameCenterData(packet, ele):
    ''' Update FrameCenter Values '''
    lat = packet.FrameCenterLatitude
    lon = packet.FrameCenterLongitude
    alt = packet.FrameCenterElevation
    if packet.FrameCenterElevation == None:
        alt = 0.0

    global groupName
    frameCenterLyr = qgsu.selectLayerByName(FrameCenter_lyr, groupName)

    try:
        if all(v is not None for v in [frameCenterLyr, lat, lon, alt]):
            frameCenterLyr.startEditing()

            if frameCenterLyr.featureCount() == 0:
                feature = QgsFeature()
                feature.setAttributes([lon, lat, alt])
                p = QgsPointXY()
                p.set(lon, lat)
                feature.setGeometry(QgsGeometry.fromPointXY(p))
                frameCenterLyr.addFeatures([feature])

            else:
                frameCenterLyr.dataProvider().changeAttributeValues(
                    {1: {
                        0: lon,
                        1: lat,
                        2: alt
                    }})

                frameCenterLyr.dataProvider().changeGeometryValues(
                    {1: QgsGeometry.fromPointXY(QgsPointXY(lon, lat))})

            CommonLayer(frameCenterLyr)
            # 3D Style
            if ele:
                SetDefaultFrameCenter3DStyle(frameCenterLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvUtils",
                                       "Failed Update Frame Center Layer! : "),
            str(e))

    return
Esempio n. 15
0
def UpdateTrajectoryData(packet, ele):
    ''' Update Trajectory Values '''
    lat = packet.SensorLatitude
    lon = packet.SensorLongitude
    alt = packet.SensorTrueAltitude

    global groupName
    trajectoryLyr = qgsu.selectLayerByName(Trajectory_lyr, groupName)

    try:
        if all(v is not None for v in [trajectoryLyr, lat, lon, alt]):
            trajectoryLyr.startEditing()
            f = QgsFeature()
            if trajectoryLyr.featureCount() == 0:
                f.setAttributes(
                    [lon, lat, alt])
                f.setGeometry(
                    QgsLineString(
                        QgsPoint(
                            lon, lat, alt), QgsPoint(
                            lon, lat, alt)))
                trajectoryLyr.addFeatures([f])

            else:
                f_last = trajectoryLyr.getFeature(trajectoryLyr.featureCount())
                f.setAttributes([lon, lat, alt])
                f.setGeometry(
                    QgsLineString(
                        QgsPoint(
                            lon,
                            lat,
                            alt),
                        QgsPoint(
                            f_last.attribute(0),
                            f_last.attribute(1),
                            f_last.attribute(2))))
                trajectoryLyr.addFeatures([f])

            CommonLayer(trajectoryLyr)
            # 3D Style
            if ele:
                SetDefaultTrajectory3DStyle(trajectoryLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(QCoreApplication.translate(
            "QgsFmvUtils", "Failed Update Trajectory Layer! : "), str(e))
Esempio n. 16
0
def UpdateFrameAxisData(packet):
    ''' Update Frame Axis Values '''
    global crtSensorSrc2

    imgSS = packet.ImageSourceSensor
    lat = packet.SensorLatitude
    lon = packet.SensorLongitude
    alt = packet.SensorTrueAltitude
    fc_lat = packet.FrameCenterLatitude
    fc_lon = packet.FrameCenterLongitude
    # fc_alt = packet.FrameCenterElevation

    frameaxisLyr = qgsu.selectLayerByName(FrameAxis_lyr)

    try:
        if all(v is not None for v in [frameaxisLyr, lat, lon, alt, fc_lat, fc_lon]):
            if(imgSS != crtSensorSrc2):
                SetDefaultFrameAxisStyle(frameaxisLyr, imgSS)
                crtSensorSrc2 = imgSS
            frameaxisLyr.startEditing()
            if frameaxisLyr.featureCount() == 0:
                f = QgsFeature()
                f.setAttributes(
                    [lon, lat, alt, fc_lon, fc_lat])
                surface = QgsGeometry.fromPolylineXY(
                    [QgsPointXY(lon, lat), QgsPointXY(fc_lon, fc_lat)])
                f.setGeometry(surface)
                frameaxisLyr.addFeatures([f])
            else:
                frameaxisLyr.beginEditCommand(
                    "ChangeGeometry + ChangeAttribute")
                fetId = 1
                attrib = {0: lon, 1: lat, 2: alt,
                          3: fc_lon, 4: fc_lat}
                frameaxisLyr.dataProvider().changeAttributeValues(
                    {fetId: attrib})
                frameaxisLyr.dataProvider().changeGeometryValues(
                    {fetId: QgsGeometry.fromPolylineXY([QgsPointXY(lon, lat), QgsPointXY(fc_lon, fc_lat)])})
                frameaxisLyr.endEditCommand()

            CommonLayer(frameaxisLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(QCoreApplication.translate(
            "QgsFmvUtils", "Failed Update Frameaxis Layer! : "), str(e))
    return
Esempio n. 17
0
def UpdateFrameCenterData(packet):
    ''' Update FrameCenter Values '''
    lat = packet.GetFrameCenterLatitude()
    lon = packet.GetFrameCenterLongitude()
    alt = packet.GetFrameCenterElevation()
    PlatformHeading = packet.GetPlatformHeadingAngle()
    frameCenterLyr = qgsu.selectLayerByName(FrameCenter_lyr)

    try:
        if all(v is not None
               for v in [frameCenterLyr, lat, lon, alt, PlatformHeading]):
            frameCenterLyr.startEditing()
            frameCenterLyr.renderer().symbol().setAngle(float(PlatformHeading))

            if frameCenterLyr.featureCount() == 0:
                feature = QgsFeature()
                feature.setAttributes([lon, lat, alt])
                p = QgsPointXY()
                p.set(lon, lat)
                geom = QgsGeometry.fromPointXY(p)
                feature.setGeometry(geom)
                frameCenterLyr.addFeatures([feature])

            else:
                frameCenterLyr.beginEditCommand(
                    "ChangeGeometry + ChangeAttribute")
                fetId = 1
                attrib = {0: lon, 1: lat, 2: alt}
                frameCenterLyr.dataProvider().changeAttributeValues(
                    {fetId: attrib})

                frameCenterLyr.dataProvider().changeGeometryValues(
                    {1: QgsGeometry.fromPointXY(QgsPointXY(lon, lat))})
                frameCenterLyr.endEditCommand()

            CommonLayer(frameCenterLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvUtils",
                                       "Failed Update Frame Center Layer! : "),
            str(e))

    return
Esempio n. 18
0
def UpdateTrajectoryData(packet):
    ''' Update Trajectory Values '''
    lat = packet.GetSensorLatitude()
    lon = packet.GetSensorLongitude()
    alt = packet.GetSensorTrueAltitude()

    #qgsu.showUserAndLogMessage("QgsFmvUtils", 'UpdateTrajectoryData: lon:' + str(lon) + ' lat:'+str(lat) + ' alt:'+str(alt), onlyLog=True)

    trajectoryLyr = qgsu.selectLayerByName(Trajectory_lyr)

    try:
        if trajectoryLyr is not None:
            trajectoryLyr.startEditing()
            f = QgsFeature()
            if trajectoryLyr.featureCount() == 0:
                f.setAttributes([lon, lat, alt])
                surface = QgsGeometry.fromPolylineXY(
                    [QgsPointXY(lon, lat),
                     QgsPointXY(lon, lat)])
                f.setGeometry(surface)
                trajectoryLyr.addFeatures([f])

            else:
                f_last = trajectoryLyr.getFeature(trajectoryLyr.featureCount())
                f.setAttributes([lon, lat, alt])
                surface = QgsGeometry.fromPolylineXY([
                    QgsPointXY(lon, lat),
                    QgsPointXY(f_last.attribute(0), f_last.attribute(1))
                ])
                f.setGeometry(surface)
                trajectoryLyr.addFeatures([f])

            CommonLayer(trajectoryLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvUtils",
                                       "Failed Update Trajectory Layer! : "),
            str(e))
    return
Esempio n. 19
0
def AddDrawLineOnMap(drawLines):
    '''  add Line on the map '''

    RemoveAllDrawLineOnMap()
    linelyr = qgsu.selectLayerByName(Line_lyr, groupName)
    if linelyr is None:
        return

    linelyr.startEditing()
    for k, v in groupby(drawLines, key=lambda x: x == [None, None, None]):
        points = []
        if k is False:
            list1 = list(v)
            for i in range(0, len(list1)):
                pt = QgsPointXY(list1[i][0], list1[i][1])
                points.append(pt)
            polyline = QgsGeometry.fromPolylineXY(points)
            f = QgsFeature()
            f.setGeometry(polyline)
            linelyr.addFeatures([f])

    CommonLayer(linelyr)
    return
Esempio n. 20
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
Esempio n. 21
0
def UpdateFootPrintData(cornerPointUL, cornerPointUR, cornerPointLR,
                        cornerPointLL):
    ''' Update Footprint Values '''
    footprintLyr = qgsu.selectLayerByName(Footprint_lyr)

    try:
        if footprintLyr is not None:
            footprintLyr.startEditing()
            if footprintLyr.featureCount() == 0:
                feature = QgsFeature()
                feature.setAttributes([
                    cornerPointUL[1], cornerPointUL[0], cornerPointUR[1],
                    cornerPointUR[0], cornerPointLR[1], cornerPointLR[0],
                    cornerPointLL[1], cornerPointLL[0]
                ])
                surface = QgsGeometry.fromPolygonXY([[
                    QgsPointXY(cornerPointUL[1], cornerPointUL[0]),
                    QgsPointXY(cornerPointUR[1], cornerPointUR[0]),
                    QgsPointXY(cornerPointLR[1], cornerPointLR[0]),
                    QgsPointXY(cornerPointLL[1], cornerPointLL[0]),
                    QgsPointXY(cornerPointUL[1], cornerPointUL[0])
                ]])
                feature.setGeometry(surface)
                footprintLyr.addFeatures([feature])
            else:
                footprintLyr.beginEditCommand(
                    "ChangeGeometry + ChangeAttribute")
                fetId = 1
                attrib = {
                    0: cornerPointUL[1],
                    1: cornerPointUL[0],
                    2: cornerPointUR[1],
                    3: cornerPointUR[0],
                    4: cornerPointLR[1],
                    5: cornerPointLR[0],
                    6: cornerPointLL[1],
                    7: cornerPointLL[0]
                }

                footprintLyr.dataProvider().changeAttributeValues(
                    {fetId: attrib})

                footprintLyr.dataProvider().changeGeometryValues({
                    fetId:
                    QgsGeometry.fromPolygonXY([[
                        QgsPointXY(cornerPointUL[1], cornerPointUL[0]),
                        QgsPointXY(cornerPointUR[1], cornerPointUR[0]),
                        QgsPointXY(cornerPointLR[1], cornerPointLR[0]),
                        QgsPointXY(cornerPointLL[1], cornerPointLL[0]),
                        QgsPointXY(cornerPointUL[1], cornerPointUL[0])
                    ]])
                })
            footprintLyr.endEditCommand()

            CommonLayer(footprintLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvUtils",
                                       "Failed Update FootPrint Layer! : "),
            str(e))
    return
Esempio n. 22
0
def UpdateBeamsData(packet, cornerPointUL, cornerPointUR, cornerPointLR,
                    cornerPointLL):
    ''' Update Beams Values '''
    lat = packet.GetSensorLatitude()
    lon = packet.GetSensorLongitude()
    alt = packet.GetSensorTrueAltitude()

    beamsLyr = qgsu.selectLayerByName(Beams_lyr)

    try:
        if beamsLyr is not None:
            beamsLyr.startEditing()
            if beamsLyr.featureCount() == 0:

                # UL
                featureUL = QgsFeature()
                featureUL.setAttributes(
                    [lon, lat, alt, cornerPointUL[1], cornerPointUL[0]])
                surface = QgsGeometry.fromPolylineXY([
                    QgsPointXY(lon, lat),
                    QgsPointXY(cornerPointUL[1], cornerPointUL[0])
                ])
                featureUL.setGeometry(surface)
                beamsLyr.addFeatures([featureUL])
                # UR
                featureUR = QgsFeature()
                featureUR.setAttributes(
                    [lon, lat, alt, cornerPointUR[1], cornerPointUR[0]])
                surface = QgsGeometry.fromPolylineXY([
                    QgsPointXY(lon, lat),
                    QgsPointXY(cornerPointUR[1], cornerPointUR[0])
                ])
                featureUR.setGeometry(surface)
                beamsLyr.addFeatures([featureUR])
                # LR
                featureLR = QgsFeature()
                featureLR.setAttributes(
                    [lon, lat, alt, cornerPointLR[1], cornerPointLR[0]])
                surface = QgsGeometry.fromPolylineXY([
                    QgsPointXY(lon, lat),
                    QgsPointXY(cornerPointLR[1], cornerPointLR[0])
                ])
                featureLR.setGeometry(surface)
                beamsLyr.addFeatures([featureLR])
                # LL
                featureLL = QgsFeature()
                featureLL.setAttributes(
                    [lon, lat, alt, cornerPointLL[1], cornerPointLL[0]])
                surface = QgsGeometry.fromPolylineXY([
                    QgsPointXY(lon, lat),
                    QgsPointXY(cornerPointLL[1], cornerPointLL[0])
                ])
                featureLL.setGeometry(surface)
                beamsLyr.addFeatures([featureLL])

            else:
                beamsLyr.beginEditCommand("ChangeGeometry + ChangeAttribute")
                # UL
                fetId = 1
                attrib = {
                    0: lon,
                    1: lat,
                    2: alt,
                    3: cornerPointUL[1],
                    4: cornerPointUL[0]
                }
                beamsLyr.dataProvider().changeAttributeValues({fetId: attrib})
                beamsLyr.dataProvider().changeGeometryValues({
                    fetId:
                    QgsGeometry.fromPolylineXY([
                        QgsPointXY(lon, lat),
                        QgsPointXY(cornerPointUL[1], cornerPointUL[0])
                    ])
                })
                # UR
                fetId = 2
                attrib = {
                    0: lon,
                    1: lat,
                    2: alt,
                    3: cornerPointUR[1],
                    4: cornerPointUR[0]
                }
                beamsLyr.dataProvider().changeAttributeValues({fetId: attrib})
                beamsLyr.dataProvider().changeGeometryValues({
                    fetId:
                    QgsGeometry.fromPolylineXY([
                        QgsPointXY(lon, lat),
                        QgsPointXY(cornerPointUR[1], cornerPointUR[0])
                    ])
                })
                # LR
                fetId = 3
                attrib = {
                    0: lon,
                    1: lat,
                    2: alt,
                    3: cornerPointLR[1],
                    4: cornerPointLR[0]
                }
                beamsLyr.dataProvider().changeAttributeValues({fetId: attrib})
                beamsLyr.dataProvider().changeGeometryValues({
                    fetId:
                    QgsGeometry.fromPolylineXY([
                        QgsPointXY(lon, lat),
                        QgsPointXY(cornerPointLR[1], cornerPointLR[0])
                    ])
                })
                # LL
                fetId = 4
                attrib = {
                    0: lon,
                    1: lat,
                    2: alt,
                    3: cornerPointLL[1],
                    4: cornerPointLL[0]
                }
                beamsLyr.dataProvider().changeAttributeValues({fetId: attrib})
                beamsLyr.dataProvider().changeGeometryValues({
                    fetId:
                    QgsGeometry.fromPolylineXY([
                        QgsPointXY(lon, lat),
                        QgsPointXY(cornerPointLL[1], cornerPointLL[0])
                    ])
                })

                beamsLyr.endEditCommand()

            CommonLayer(beamsLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvUtils",
                                       "Failed Update Beams Layer! : "),
            str(e))
    return
Esempio n. 23
0
def CreateVideoLayers(ele, name):
    ''' Create Video Layers '''
    global groupName
    groupName = name

    if qgsu.selectLayerByName(Footprint_lyr, groupName) is None:
        lyr_footprint = newPolygonsLayer(None, [
            "Corner Longitude Point 1", "Corner Latitude Point 1",
            "Corner Longitude Point 2", "Corner Latitude Point 2",
            "Corner Longitude Point 3", "Corner Latitude Point 3",
            "Corner Longitude Point 4", "Corner Latitude Point 4"
        ], epsg, Footprint_lyr)
        SetDefaultFootprintStyle(lyr_footprint)
        addLayerNoCrsDialog(lyr_footprint, group=groupName)

        # 3D Style
        if ele:
            SetDefaultFootprint3DStyle(lyr_footprint)

    if qgsu.selectLayerByName(Beams_lyr, groupName) is None:
        lyr_beams = newLinesLayer(None, [
            "longitude", "latitude", "altitude", "Corner Longitude",
            "Corner Latitude"
        ], epsg, Beams_lyr, LineZ)
        SetDefaultBeamsStyle(lyr_beams)
        addLayerNoCrsDialog(lyr_beams, group=groupName)
        # 3D Style
        if ele:
            SetDefaultBeams3DStyle(lyr_beams)

    if qgsu.selectLayerByName(Trajectory_lyr, groupName) is None:
        lyr_Trajectory = newLinesLayer(None,
                                       ["longitude", "latitude", "altitude"],
                                       epsg, Trajectory_lyr, LineZ)
        SetDefaultTrajectoryStyle(lyr_Trajectory)
        addLayerNoCrsDialog(lyr_Trajectory, group=groupName)
        # 3D Style
        if ele:
            SetDefaultTrajectory3DStyle(lyr_Trajectory)

    if qgsu.selectLayerByName(FrameAxis_lyr, groupName) is None:
        lyr_frameaxis = newLinesLayer(None, [
            "longitude", "latitude", "altitude", "Corner Longitude",
            "Corner Latitude", "Corner altitude"
        ], epsg, FrameAxis_lyr, LineZ)
        SetDefaultFrameAxisStyle(lyr_frameaxis)
        addLayerNoCrsDialog(lyr_frameaxis, group=groupName)
        # 3D Style
        if ele:
            SetDefaultFrameAxis3DStyle(lyr_frameaxis)

    if qgsu.selectLayerByName(Platform_lyr, groupName) is None:
        lyr_platform = newPointsLayer(None,
                                      ["longitude", "latitude", "altitude"],
                                      epsg, Platform_lyr, PointZ)
        SetDefaultPlatformStyle(lyr_platform)
        addLayerNoCrsDialog(lyr_platform, group=groupName)
        # 3D Style
        if ele:
            SetDefaultPlatform3DStyle(lyr_platform)

    if qgsu.selectLayerByName(Point_lyr, groupName) is None:
        lyr_point = newPointsLayer(
            None, ["number", "longitude", "latitude", "altitude"], epsg,
            Point_lyr)
        SetDefaultPointStyle(lyr_point)
        addLayerNoCrsDialog(lyr_point, group=groupName)

    if qgsu.selectLayerByName(FrameCenter_lyr, groupName) is None:
        lyr_framecenter = newPointsLayer(None,
                                         ["longitude", "latitude", "altitude"],
                                         epsg, FrameCenter_lyr)
        SetDefaultFrameCenterStyle(lyr_framecenter)
        addLayerNoCrsDialog(lyr_framecenter, group=groupName)
        # 3D Style
        if ele:
            SetDefaultFrameCenter3DStyle(lyr_framecenter)

    if qgsu.selectLayerByName(Line_lyr, groupName) is None:
        #         lyr_line = newLinesLayer(
        # None, ["longitude", "latitude", "altitude"], epsg, Line_lyr)
        lyr_line = newLinesLayer(None, [], epsg, Line_lyr)
        SetDefaultLineStyle(lyr_line)
        addLayerNoCrsDialog(lyr_line, group=groupName)

    if qgsu.selectLayerByName(Polygon_lyr, groupName) is None:
        lyr_polygon = newPolygonsLayer(None, [
            "Centroid_longitude", "Centroid_latitude", "Centroid_altitude",
            "Area"
        ], epsg, Polygon_lyr)
        SetDefaultPolygonStyle(lyr_polygon)
        addLayerNoCrsDialog(lyr_polygon, group=groupName)

    QApplication.processEvents()
    return
Esempio n. 24
0
    def mousePressEvent(self, event):
        """
        :type event: QMouseEvent
        :param event:
        :return:
        """
        if event.button() == Qt.LeftButton:
            self.pressed = self.snapped = True
            self.pressPos = self.dragPos = event.pos()
            self.tapTimer.stop()
            self.tapTimer.start(HOLD_TIME, self)

            #point drawer
            if self.gt is not None and pointDrawer:
                if (not self.IsPointOnScreen(event.x(), event.y())):
                    return

                transf = self.gt([
                    (event.x() - self.GetXBlackZone()) * self.GetXRatio(),
                    (event.y() - self.GetYBlackZone()) * self.GetYRatio()
                ])
                #targetAlt = GetFrameCenter()[2]
                Longitude = float(round(transf[1], 4))
                Latitude = float(round(transf[0], 4))
                #Altitude = targetAlt
                Altitude = 0.0
                #add pin point on the map
                pointLyr = qgsu.selectLayerByName(Point_lyr)
                pointLyr.startEditing()
                feature = QgsFeature()
                feature.setAttributes([Longitude, Latitude, Altitude])
                p = QgsPointXY()
                p.set(Longitude, Latitude)
                geom = QgsGeometry.fromPointXY(p)
                feature.setGeometry(geom)
                pointLyr.addFeatures([feature])

                CommonLayer(pointLyr)

                self.drawPtPos.append([Longitude, Latitude])
                #if not called, the paint event is not triggered.
                self.UpdateSurface()

            #line drawer
            if self.gt is not None and lineDrawer:
                if (not self.IsPointOnScreen(event.x(), event.y())):
                    return

                transf = self.gt([
                    (event.x() - self.GetXBlackZone()) * self.GetXRatio(),
                    (event.y() - self.GetYBlackZone()) * self.GetYRatio()
                ])
                #targetAlt = GetFrameCenter()[2]
                Longitude = float(round(transf[1], 4))
                Latitude = float(round(transf[0], 4))
                #Altitude = targetAlt
                Altitude = 0.0
                #add pin point on the map
                linelyr = qgsu.selectLayerByName(Line_lyr)
                linelyr.startEditing()
                feature = QgsFeature()
                f = QgsFeature()
                if linelyr.featureCount() == 0:
                    f.setAttributes([Longitude, Latitude, Altitude])
                    surface = QgsGeometry.fromPolylineXY([
                        QgsPointXY(Longitude, Latitude),
                        QgsPointXY(Longitude, Latitude)
                    ])
                    f.setGeometry(surface)
                    linelyr.addFeatures([f])

                else:
                    f_last = linelyr.getFeature(linelyr.featureCount())
                    f.setAttributes([Longitude, Latitude, Altitude])
                    surface = QgsGeometry.fromPolylineXY([
                        QgsPointXY(Longitude, Latitude),
                        QgsPointXY(f_last.attribute(0), f_last.attribute(1))
                    ])
                    f.setGeometry(surface)
                    linelyr.addFeatures([f])

                CommonLayer(linelyr)

                self.drawLines.append([Longitude, Latitude])
                #if not called, the paint event is not triggered.
                self.UpdateSurface()

        if zoomRect and event.button() == Qt.LeftButton:
            self.origin = event.pos()
            self.rubberBand.setGeometry(QRect(self.origin, QSize()))
            self.rubberBand.show()
            self.changeRubberBand = True
Esempio n. 25
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
Esempio n. 26
0
def UpdateFootPrintData(packet, cornerPointUL, cornerPointUR, cornerPointLR,
                        cornerPointLL, ele):
    ''' Update Footprint Values '''
    global crtSensorSrc, groupName
    imgSS = packet.ImageSourceSensor

    footprintLyr = qgsu.selectLayerByName(Footprint_lyr, groupName)

    try:
        if all(v is not None for v in [
                footprintLyr, cornerPointUL, cornerPointUR, cornerPointLR,
                cornerPointLL
        ]) and all(v >= 2 for v in [
                len(cornerPointUL),
                len(cornerPointUR),
                len(cornerPointLR),
                len(cornerPointLL)
        ]):
            if (imgSS != crtSensorSrc):
                SetDefaultFootprintStyle(footprintLyr, imgSS)
                crtSensorSrc = imgSS

            footprintLyr.startEditing()
            if footprintLyr.featureCount() == 0:
                feature = QgsFeature()
                feature.setAttributes([
                    cornerPointUL[1], cornerPointUL[0], cornerPointUR[1],
                    cornerPointUR[0], cornerPointLR[1], cornerPointLR[0],
                    cornerPointLL[1], cornerPointLL[0]
                ])
                surface = QgsGeometry.fromPolygonXY([[
                    QgsPointXY(cornerPointUL[1], cornerPointUL[0]),
                    QgsPointXY(cornerPointUR[1], cornerPointUR[0]),
                    QgsPointXY(cornerPointLR[1], cornerPointLR[0]),
                    QgsPointXY(cornerPointLL[1], cornerPointLL[0]),
                    QgsPointXY(cornerPointUL[1], cornerPointUL[0])
                ]])
                feature.setGeometry(surface)
                footprintLyr.addFeatures([feature])
            else:
                fetId = 1
                attrib = {
                    0: cornerPointUL[1],
                    1: cornerPointUL[0],
                    2: cornerPointUR[1],
                    3: cornerPointUR[0],
                    4: cornerPointLR[1],
                    5: cornerPointLR[0],
                    6: cornerPointLL[1],
                    7: cornerPointLL[0]
                }

                footprintLyr.dataProvider().changeAttributeValues(
                    {fetId: attrib})

                footprintLyr.dataProvider().changeGeometryValues({
                    fetId:
                    QgsGeometry.fromPolygonXY([[
                        QgsPointXY(cornerPointUL[1], cornerPointUL[0]),
                        QgsPointXY(cornerPointUR[1], cornerPointUR[0]),
                        QgsPointXY(cornerPointLR[1], cornerPointLR[0]),
                        QgsPointXY(cornerPointLL[1], cornerPointLL[0]),
                        QgsPointXY(cornerPointUL[1], cornerPointUL[0])
                    ]])
                })

            CommonLayer(footprintLyr)
            # 3D Style
            if ele:
                SetDefaultFootprint3DStyle(footprintLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvLayers",
                                       "Failed Update FootPrint Layer! : "),
            str(e))
    return
Esempio n. 27
0
def UpdateBeamsData(packet, cornerPointUL, cornerPointUR, cornerPointLR,
                    cornerPointLL, ele):
    ''' Update Beams Values '''
    lat = packet.SensorLatitude
    lon = packet.SensorLongitude
    alt = packet.SensorTrueAltitude

    global groupName
    beamsLyr = qgsu.selectLayerByName(Beams_lyr, groupName)

    try:
        if all(v is not None for v in [
                beamsLyr, lat, lon, alt, cornerPointUL, cornerPointUR,
                cornerPointLR, cornerPointLL
        ]) and all(v >= 2 for v in [
                len(cornerPointUL),
                len(cornerPointUR),
                len(cornerPointLR),
                len(cornerPointLL)
        ]):
            beamsLyr.startEditing()
            if beamsLyr.featureCount() == 0:

                # UL
                featureUL = QgsFeature()
                featureUL.setAttributes(
                    [lon, lat, alt, cornerPointUL[1], cornerPointUL[0]])
                featureUL.setGeometry(
                    QgsLineString(QgsPoint(lon, lat, alt),
                                  QgsPoint(cornerPointUL[1],
                                           cornerPointUL[0])))
                beamsLyr.addFeatures([featureUL])
                # UR
                featureUR = QgsFeature()
                featureUR.setAttributes(
                    [lon, lat, alt, cornerPointUR[1], cornerPointUR[0]])
                featureUR.setGeometry(
                    QgsLineString(QgsPoint(lon, lat, alt),
                                  QgsPoint(cornerPointUR[1],
                                           cornerPointUR[0])))
                beamsLyr.addFeatures([featureUR])
                # LR
                featureLR = QgsFeature()
                featureLR.setAttributes(
                    [lon, lat, alt, cornerPointLR[1], cornerPointLR[0]])
                featureLR.setGeometry(
                    QgsLineString(QgsPoint(lon, lat, alt),
                                  QgsPoint(cornerPointLR[1],
                                           cornerPointLR[0])))
                beamsLyr.addFeatures([featureLR])
                # LL
                featureLL = QgsFeature()
                featureLL.setAttributes(
                    [lon, lat, alt, cornerPointLL[1], cornerPointLL[0]])
                featureLL.setGeometry(
                    QgsLineString(QgsPoint(lon, lat, alt),
                                  QgsPoint(cornerPointLL[1],
                                           cornerPointLL[0])))
                beamsLyr.addFeatures([featureLL])

            else:
                # UL
                beamsLyr.dataProvider().changeAttributeValues({
                    1: {
                        0: lon,
                        1: lat,
                        2: alt,
                        3: cornerPointUL[1],
                        4: cornerPointUL[0]
                    }
                })
                beamsLyr.dataProvider().changeGeometryValues({
                    1:
                    QgsGeometry(
                        QgsLineString(
                            QgsPoint(lon, lat, alt),
                            QgsPoint(cornerPointUL[1], cornerPointUL[0])))
                })
                # UR
                beamsLyr.dataProvider().changeAttributeValues({
                    2: {
                        0: lon,
                        1: lat,
                        2: alt,
                        3: cornerPointUR[1],
                        4: cornerPointUR[0]
                    }
                })
                beamsLyr.dataProvider().changeGeometryValues({
                    2:
                    QgsGeometry(
                        QgsLineString(
                            QgsPoint(lon, lat, alt),
                            QgsPoint(cornerPointUR[1], cornerPointUR[0])))
                })
                # LR
                beamsLyr.dataProvider().changeAttributeValues({
                    3: {
                        0: lon,
                        1: lat,
                        2: alt,
                        3: cornerPointLR[1],
                        4: cornerPointLR[0]
                    }
                })
                beamsLyr.dataProvider().changeGeometryValues({
                    3:
                    QgsGeometry(
                        QgsLineString(
                            QgsPoint(lon, lat, alt),
                            QgsPoint(cornerPointLR[1], cornerPointLR[0])))
                })
                # LL
                beamsLyr.dataProvider().changeAttributeValues({
                    4: {
                        0: lon,
                        1: lat,
                        2: alt,
                        3: cornerPointLL[1],
                        4: cornerPointLL[0]
                    }
                })
                beamsLyr.dataProvider().changeGeometryValues({
                    4:
                    QgsGeometry(
                        QgsLineString(
                            QgsPoint(lon, lat, alt),
                            QgsPoint(cornerPointLL[1], cornerPointLL[0])))
                })

            CommonLayer(beamsLyr)
            # 3D Style
            if ele:
                SetDefaultBeams3DStyle(beamsLyr)

    except Exception as e:
        qgsu.showUserAndLogMessage(
            QCoreApplication.translate("QgsFmvUtils",
                                       "Failed Update Beams Layer! : "),
            str(e))
    return