def GetLine3DIntersectionWithDEM(sensorPt, targetPt): pt = [] sensorLat = sensorPt[0] sensorLon = sensorPt[1] sensorAlt = sensorPt[2] targetLat = targetPt[0] targetLon = targetPt[1] try: targetAlt = targetPt[2] except Exception: targetAlt = GetFrameCenter()[2] distance = sphere.distance([sensorLat, sensorLon], [targetLat, targetLon]) distance = sqrt(distance ** 2 + (targetAlt - sensorAlt) ** 2) dLat = (targetLat - sensorLat) / distance dLon = (targetLon - sensorLon) / distance dAlt = (targetAlt - sensorAlt) / distance xOrigin = dtm_transform[0] yOrigin = dtm_transform[3] pixelWidth = dtm_transform[1] pixelHeight = -dtm_transform[5] pixelWidthMeter = pixelWidth * (pi / 180.0) * 6378137.0 # start at k = sensor point, then test every pixel a point on the 3D line # until we cross the dtm (diffAlt >= 0). diffAlt = -1 for k in range(0, int(dtm_buffer * pixelWidthMeter), int(pixelWidthMeter)): point = [sensorLon + k * dLon, sensorLat + k * dLat, sensorAlt + k * dAlt] col = int((point[0] - xOrigin) / pixelWidth) row = int((yOrigin - point[1]) / pixelHeight) try: diffAlt = point[2] - dtm_data[row - dtm_rowLowerBound][col - dtm_colLowerBound] except Exception: qgsu.showUserAndLogMessage( "", "DEM point not found after all iterations.", onlyLog=True) break if diffAlt <= 0: pt = [point[1], point[0], point[2]] break if not pt: qgsu.showUserAndLogMessage( "", "DEM point not found, last computed delta high: " + str(diffAlt), onlyLog=True) return pt
def unload(self): ''' Unload Plugin ''' self.iface.removePluginMenu( QCoreApplication.translate("Fmv", "Full Motion Video (FMV)"), self.actionFMV) self.iface.removePluginMenu( QCoreApplication.translate("Fmv", "Full Motion Video (FMV)"), self.actionAbout) self.iface.removeToolBarIcon(self.actionFMV) log.removeLogging() qgsu.removeMosaicFolder()
def paint(self, painter): ''' Paint Frame''' if (self.currentFrame.map(QAbstractVideoBuffer.ReadOnly)): oldTransform = painter.transform() if (self.surfaceFormat().scanLineDirection() == QVideoSurfaceFormat.BottomToTop): painter.scale(1, -1) painter.translate(0, -self.widget.height()) self.image = QImage(self.currentFrame.bits(), self.currentFrame.width(), self.currentFrame.height(), self.currentFrame.bytesPerLine(), self.imageFormat ) if self.widget._filterSatate.grayColorFilter: self.image = filter.GrayFilter(self.image) if self.widget._filterSatate.MirroredHFilter: self.image = filter.MirrredFilter(self.image) if self.widget._filterSatate.monoFilter: self.image = filter.MonoFilter(self.image) if self.widget._filterSatate.edgeDetectionFilter: self.image = filter.EdgeFilter(self.image) if self.widget._filterSatate.contrastFilter: self.image = filter.AutoContrastFilter(self.image) if self.widget._filterSatate.invertColorFilter: self.image.invertPixels() painter.drawImage(self.targetRect, self.image, self.sourceRect) if self._interaction.objectTracking and self.widget._isinit: frame = convertQImageToMat(self.image) # Update tracker ok, bbox = self.widget.tracker.update(frame) # Draw bounding box if ok: # qgsu.showUserAndLogMessage( # "bbox : ", str(bbox), level=QGis.Warning) painter.setPen(Qt.blue) painter.drawRect(QRect(int(bbox[0]), int( bbox[1]), int(bbox[2]), int(bbox[3]))) else: qgsu.showUserAndLogMessage( "Tracking failure detected ", "", level=QGis.Warning) painter.setTransform(oldTransform) self.currentFrame.unmap() return self.painter
def getVideoFolder(video_file): ''' Get or create Video Temporal folder ''' home = os.path.expanduser("~") qgsu.createFolderByName(home, "QGIS_FMV") root, _ = os.path.splitext(os.path.basename(video_file)) homefmv = os.path.join(home, "QGIS_FMV") qgsu.createFolderByName(homefmv, root) return os.path.join(homefmv, root)
def dispose(self): # qgsu.showUserAndLogMessage("", "Dispose called on StreamMetaReader.", onlyLog=True) self.splitter.nbsr.stopped = True # kill the process if open, releases source port try: self.splitter.p.kill() qgsu.showUserAndLogMessage("", "Splitter Popen process killed.", onlyLog=True) except OSError: # can't kill a dead proc pass
def createMosaic(self, value): ''' Function for create Video Mosaic ''' home = os.path.expanduser("~") qgsu.createFolderByName(home, "QGIS_FMV") homefmv = os.path.join(home, "QGIS_FMV") root, ext = os.path.splitext(os.path.basename(self.fileName)) qgsu.createFolderByName(homefmv, root) self.createingMosaic = value # Create Group CreateGroupByName() return
def statusChanged(self, status): ''' Signal Status video change ''' self.handleCursor(status) if status is QMediaPlayer.LoadingMedia or status is QMediaPlayer.StalledMedia or status is QMediaPlayer.InvalidMedia: self.videoAvailableChanged(False) elif status == QMediaPlayer.InvalidMedia: qgsu.showUserAndLogMessage(QCoreApplication.translate( "QgsFmvPlayer", self.player.errorString()), level=QGis.Warning) self.videoAvailableChanged(False) else: self.videoAvailableChanged(True)
def finished(e): QApplication.restoreOverrideCursor() if e is None: qgsu.showUserAndLogMessage( QCoreApplication.translate("QgsFmvMetadata", "Succesfully creating PDF")) else: qgsu.showUserAndLogMessage(QCoreApplication.translate( "QgsFmvMetadata", "Failed creating PDF : "), str(e), level=QGis.Warning) return
def SetGCPsToGeoTransform(cornerPointUL, cornerPointUR, cornerPointLR, cornerPointLL, frameCenterLon, frameCenterLat): ''' Make Geotranform from pixel to lon lat coordinates ''' gcps = [] global gcornerPointUL gcornerPointUL = cornerPointUL global gcornerPointUR gcornerPointUR = cornerPointUR global gcornerPointLR gcornerPointLR = cornerPointLR global gcornerPointLL gcornerPointLL = cornerPointLL global gframeCenterLat gframeCenterLat = frameCenterLat global gframeCenterLon gframeCenterLon = frameCenterLon global geotransform global geotransform_affine Height = GetFrameCenter()[2] gcp = gdal.GCP(cornerPointUL[1], cornerPointUL[0], Height, 0, 0, "Corner Upper Left", "1") gcps.append(gcp) gcp = gdal.GCP(cornerPointUR[1], cornerPointUR[0], Height, xSize, 0, "Corner Upper Right", "2") gcps.append(gcp) gcp = gdal.GCP(cornerPointLR[1], cornerPointLR[0], Height, xSize, ySize, "Corner Lower Right", "3") gcps.append(gcp) gcp = gdal.GCP(cornerPointLL[1], cornerPointLL[0], Height, 0, ySize, "Corner Lower Left", "4") gcps.append(gcp) gcp = gdal.GCP(frameCenterLon, frameCenterLat, Height, xSize / 2, ySize / 2, "Center", "5") gcps.append(gcp) geotransform_affine = gdal.GCPsToGeoTransform(gcps) src = np.float64( np.array([[0.0, 0.0], [xSize, 0.0], [xSize, ySize], [0.0, ySize]])) dst = np.float64( np.array([cornerPointUL, cornerPointUR, cornerPointLR, cornerPointLL])) geotransform = from_points(src, dst) if geotransform is None: qgsu.showUserAndLogMessage("", "Unable to extract a geotransform.", onlyLog=True) return
def present(self, frame): if (self.surfaceFormat().pixelFormat() != frame.pixelFormat() or self.surfaceFormat().frameSize() != frame.size()): self.setError(QAbstractVideoSurface.IncorrectFormatError) self.stop() return False else: self.currentFrame = frame self.widget.repaint(self.targetRect) qgsu.showUserAndLogMessage(QCoreApplication.translate( "QgsVideo", 'Video : '), "Repaint Video", onlyLog=True) return True
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
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
def install_pip_requirements(): ''' Install Requeriments from pip ''' package_dir = QgsApplication.qgisSettingsDirPath() + 'python/plugins/QGIS_FMV/' requirements_file = os.path.join(package_dir, 'requirements.txt') if not os.path.isfile(requirements_file): qgsu.showUserAndLogMessage("", 'No requirements file found in {}'.format( requirements_file), "", onlyLog=True) raise try: from pip._internal import main main(['install', '-r', requirements_file]) except Exception: raise return
def initElevationModel(frameCenterLat, frameCenterLon, dtm_path): ''' Start DEM transformation and extract data for set Z value in points ''' global dtm_data, dtm_transform, dtm_colLowerBound, dtm_rowLowerBound # Initialize the dtm once, based on a zone arouind the target qgsu.showUserAndLogMessage("", "Initializing DTM.", onlyLog=True) dataset = gdal.Open(dtm_path) if dataset is None: qgsu.showUserAndLogMessage(QCoreApplication.translate( "QgsFmvUtils", "Failed to read DTM file. "), level=QGis.Warning) return band = dataset.GetRasterBand(1) dtm_transform = dataset.GetGeoTransform() xOrigin = dtm_transform[0] yOrigin = dtm_transform[3] pixelWidth = dtm_transform[1] pixelHeight = -dtm_transform[5] cIndex = int((frameCenterLon - xOrigin) / pixelWidth) rIndex = int((frameCenterLat - yOrigin) / (-pixelHeight)) dtm_colLowerBound = cIndex - dtm_buffer dtm_rowLowerBound = rIndex - dtm_buffer if dtm_colLowerBound < 0 or dtm_rowLowerBound < 0: qgsu.showUserAndLogMessage(QCoreApplication.translate( "QgsFmvUtils", "There is no DTM for theses bounds. Check/increase DTM_buffer_size in settings.ini"), level=QGis.Warning) else: # qgsu.showUserAndLogMessage("UpdateLayers: ", " dtm_colLowerBound:"+str(dtm_colLowerBound)+" dtm_rowLowerBound:"+str(dtm_rowLowerBound)+" dtm_buffer:"+str(dtm_buffer), onlyLog=True) dtm_data = band.ReadAsArray( dtm_colLowerBound, dtm_rowLowerBound, 2 * dtm_buffer, 2 * dtm_buffer) if dtm_data is not None: qgsu.showUserAndLogMessage( "", "DTM successfully initialized, len: " + str(len(dtm_data)), onlyLog=True)
def parse(self): """Parse the parent into items. Called on init and modification of parent value. If a known parser is not available for key, parse as generic KLV element. """ for key, value in KLVParser(self.value, self.key_length): try: self.items[key] = self.parsers[key](value) except Exception: # None qgsu.showUserAndLogMessage("", "Value cannot be read for key: " + str(key.hex()), onlyLog=True)
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))
def CreateCSV(self): ''' Create csv for each recording ''' self.cmb_telemetry.clear() input_video = self.ln_inputVideo.text() input_metadata = self.ln_inputMeta.text() if input_video == "" or input_metadata == "": qgsu.showUserAndLogMessage(QCoreApplication.translate( "Multiplexor", "You must complete all the information")) return self.ReadCSVRecordings(input_metadata) # Enable create video button self.bt_createMISB.setEnabled(True) return
def playFile(self, videoPath): ''' Play file from path ''' try: RemoveVideoLayers() RemoveGroupByName() # if "udp://" in videoPath: # host, port = videoPath.split("://")[1].split(":") # receiver = UDPClient(host, int(port), type="udp") # receiver.show() # self.close() # return # if "tcp://" in videoPath: # host, port = videoPath.split("://")[1].split(":") # receiver = UDPClient(host, port, type="tcp") # receiver.show() # self.close() # return self.fileName = videoPath self.playlist = QMediaPlaylist() if self.isStreaming: url = QUrl(videoPath) else: url = QUrl.fromLocalFile(videoPath) qgsu.showUserAndLogMessage("", "Added: " + str(url), onlyLog=True) self.playlist.addMedia(QMediaContent(url)) self.player.setPlaylist(self.playlist) self.setWindowTitle( QCoreApplication.translate("QgsFmvPlayer", 'Playing : ') + os.path.basename(os.path.normpath(videoPath))) CreateVideoLayers() self.clearMetadata() self.HasFileAudio = True if not self.HasAudio(videoPath): self.actionAudio.setEnabled(False) self.actionSave_Audio.setEnabled(False) self.HasFileAudio = False self.playClicked(True) except Exception as e: qgsu.showUserAndLogMessage(QCoreApplication.translate( "QgsFmvPlayer", 'Open Video File : '), str(e), level=QGis.Warning)
def UpdateFrameCenterData(packet, ele): """ Update FrameCenter Values """ lat = packet[0] lon = packet[1] alt = packet[2] if alt is None: alt = 0.0 global groupName frameCenterLyr = 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), )
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))
def loadJsonFromConsole(self, value): ''' Load Json from console output ''' error = QJsonParseError() self.mDocument = QJsonDocument.fromJson(value, error) if self.mDocument is not None: self.beginResetModel() if self.mDocument.isArray(): self.mRootItem.load(list(self.mDocument.array())) else: self.mRootItem = self.mRootItem.load(self.mDocument.object()) self.endResetModel() return True qgsu.showUserAndLogMessage("", "QJsonModel: error loading Json", onlyLog=True) return False
def RemoveVideoLayers(): ''' Create Video Layers ''' try: QgsProject.instance().removeMapLayer(qgsu.selectLayerByName(Platform_lyr).id()) except: None try: QgsProject.instance().removeMapLayer(qgsu.selectLayerByName(Beams_lyr).id()) except: None try: QgsProject.instance().removeMapLayer(qgsu.selectLayerByName(Footprint_lyr).id()) except: None iface.mapCanvas().refresh() QApplication.processEvents() return
def __init__(self, video_path): self.split = video_path.split(":") self.srcProtocol = self.split[0] self.srcHost = self.split[1] self.srcPort = int(self.split[2]) self.destPort = self.srcPort + 10 self.connection = self.srcProtocol + ':' + self.srcHost + ':' + str( self.srcPort) self.connectionDest = self.srcProtocol + '://127.0.0.1:' + str( self.destPort) self.splitter = Splitter([ '-i', self.connection, '-c', 'copy', '-map', '0:v?', '-map', '0:a?', '-f', 'rtp_mpegts', self.connectionDest, '-map', '0:d?', '-f', 'data', '-' ]) self.splitter.start() qgsu.showUserAndLogMessage("", "Splitter started.", onlyLog=True)
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
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() QApplication.processEvents() return
def RemoveAllDrawPolygonOnMap(): ''' Remove all features on Polygon Layer ''' polyLyr = qgsu.selectLayerByName(Polygon_lyr, groupName) if polyLyr is None: return polyLyr.startEditing() polyLyr.dataProvider().truncate() CommonLayer(polyLyr) return
def georeferencingVideo(parent): """ Extract Current Frame Thread """ image = parent.videoWidget.currentFrame() folder = getVideoFolder(parent.fileName) qgsu.createFolderByName(folder, "mosaic") out = os.path.join(folder, "mosaic") position = str(parent.player.position()) taskGeoreferencingVideo = QgsTask.fromFunction('Georeferencing Current Frame Task', GeoreferenceFrame, image=image, output=out, p=position, on_finished=parent.finishedTask, flags=QgsTask.CanCancel) QgsApplication.taskManager().addTask(taskGeoreferencingVideo) return
def RemoveAllDrawLineOnMap(): ''' Remove all features on Line Layer ''' lineLyr = qgsu.selectLayerByName(Line_lyr, groupName) if lineLyr is None: return lineLyr.startEditing() lineLyr.dataProvider().truncate() CommonLayer(lineLyr) return
def parse(self): """Parse the parent into items. Called on init and modification of parent value. If a known parser is not available for key, parse as generic KLV element. """ for key, value in KLVParser(self.value, self.key_length): try: self.items[key] = self.parsers[key](value) except (KeyError, TypeError, ValueError): self.items[key] = self._unknown_element(key, value) except Exception: # None qgsu.showUserAndLogMessage( "", "Value cannot be read for Tag: " + str(int.from_bytes(key, byteorder=sys.byteorder)) + " value: " + str(value), onlyLog=True)
def SetGCPsToGeoTransform(cornerPointUL, cornerPointUR, cornerPointLR, cornerPointLL, frameCenterLon, frameCenterLat): ''' Make Geotranform from pixel to lon lat coordinates ''' gcps = [] global gcornerPointUL gcornerPointUL = cornerPointUL global gcornerPointUR gcornerPointUR = cornerPointUR global gcornerPointLR gcornerPointLR = cornerPointLR global gcornerPointLL gcornerPointLL = cornerPointLL global gframeCenterLat gframeCenterLat = frameCenterLat global gframeCenterLon gframeCenterLon = frameCenterLon Height = 0 gcp = gdal.GCP(cornerPointUL[1], cornerPointUL[0], Height, 0, 0, "Corner Upper Left", "1") gcps.append(gcp) gcp = gdal.GCP(cornerPointUR[1], cornerPointUR[0], Height, xSize, 0, "Corner Upper Right", "2") gcps.append(gcp) gcp = gdal.GCP(cornerPointLR[1], cornerPointLR[0], Height, xSize, ySize, "Corner Lower Right", "3") gcps.append(gcp) gcp = gdal.GCP(cornerPointLL[1], cornerPointLL[0], Height, 0, ySize, "Corner Lower Left", "4") gcps.append(gcp) gcp = gdal.GCP(frameCenterLon, frameCenterLat, Height, xSize / 2, ySize / 2, "Center", "5") gcps.append(gcp) global geotransform geotransform = gdal.GCPsToGeoTransform(gcps) if geotransform is None: qgsu.showUserAndLogMessage(QCoreApplication.translate( "QgsFmvUtils", 'Unable to extract a geotransform.'), onlyLog=True) return