Пример #1
0
 def _gpsfound(self, gpsConnection):
     log("GPS found")
     self.gpsConn = gpsConnection
     self.gpsConn.nmeaSentenceReceived.connect(self.parse_data)
     # self.gpsConn.stateChanged.connect(self.gpsStateChanged)
     self.isConnected = True
     QgsGPSConnectionRegistry.instance().registerConnection(self.gpsConn)
Пример #2
0
 def _gpsfound(self, gpsConnection):
     log("GPS found")
     self.gpsConn = gpsConnection
     self.gpsConn.nmeaSentenceReceived.connect(self.parse_data)
     # self.gpsConn.stateChanged.connect(self.gpsStateChanged)
     self.isConnected = True
     QgsGPSConnectionRegistry.instance().registerConnection(self.gpsConn)
Пример #3
0
    def disconnectGPS(self):
        if self.isConnected:
            self.gpsConn.stateChanged.disconnect(self.gpsStateChanged)
            self.gpsConn.close()

        log("GPS disconnect")
        self.isConnected = False
        self.postion = None
        QgsGPSConnectionRegistry.instance().unregisterConnection(self.gpsConn)
        self.gpsdisconnected.emit()
Пример #4
0
    def disconnectGPS(self):
        if self.isConnected:
            self.gpsConn.stateChanged.disconnect(self.gpsStateChanged)
            self.gpsConn.close()

        log("GPS disconnect")
        self.isConnected = False
        self.postion = None
        QgsGPSConnectionRegistry.instance().unregisterConnection(self.gpsConn)
        self.gpsdisconnected.emit()
Пример #5
0
 def updatePosition(self):
     connectionRegistry = QgsGPSConnectionRegistry().instance()
     connectionList = connectionRegistry.connectionList()
     if connectionList == []:
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         msgBox.setText(
             "GPS connection not detected.\nConnect a GPS and try again")
         msgBox.exec_()
         return
     GPSInfo = connectionList[0].currentGPSInformation()
     firstCoordinate = GPSInfo.longitude
     secondCoordinate = GPSInfo.latitude
     pointCrsGps = QgsPoint(firstCoordinate, secondCoordinate)
     pointCrs = self.crsOperationFromGps.transform(pointCrsGps)
     firstCoordinate = pointCrs.x()
     secondCoordinate = pointCrs.y()
     if self.crs.geographicFlag():
         strFirstCoordinate = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_LONGITUDE_PRECISION.format(
             firstCoordinate)
         strSecondCoordinate = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_LATITUDE_PRECISION.format(
             secondCoordinate)
     else:
         strFirstCoordinate = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_EASTING_PRECISION.format(
             firstCoordinate)
         strSecondCoordinate = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_NORTHING_PRECISION.format(
             secondCoordinate)
     self.firstCoordinateLineEdit.setText(strFirstCoordinate)
     self.secondCoordinateLineEdit.setText(strSecondCoordinate)
     antennaHeight = float(self.heightAntennaLineEdit.text())
     if self.useHeight:
         height = GPSInfo.elevation
         heightGround = height - antennaHeight
         strHeight = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_HEIGHT_PRECISION.format(
             height)
         self.heightGpsLineEdit.setText(strHeight)
         strHeightGround = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_HEIGHT_PRECISION.format(
             heightGround)
         self.heightGroundLineEdit.setText(strHeightGround)
         if self.useGeoidModel:
             geoidHeight = self.getGeoidInterpolatedValue(
                 GPSInfo.longitude, GPSInfo.latitude)
             if geoidHeight == constants.CONST_GNSS_3D_CAPTURE_GEOIDS_NO_VALUE:
                 return
             strGeoidHeight = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_GEOID_HEIGHT_PRECISION.format(
                 geoidHeight)
             heightFromGeoid = heightGround - geoidHeight
             strHeightFromGeoid = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_HEIGHT_FROM_GEOID_PRECISION.format(
                 heightFromGeoid)
             self.heightGeoidLineEdit.setText(strGeoidHeight)
             self.heightFromGeoidLineEdit.setText(strHeightFromGeoid)
Пример #6
0
 def gpsconnection(self):
     try:
         return QgsGPSConnectionRegistry.instance().connectionList()[0]
     except IndexError:
         return None
Пример #7
0
 def _gpsfound(self, gpsConnection):
     log("GPS found")
     self.gpsConn = gpsConnection
     self.gpsConn.stateChanged.connect(self.gpsStateChanged)
     self.isConnected = True
     QgsGPSConnectionRegistry.instance().registerConnection(self.gpsConn)
Пример #8
0
 def gpsconnection(self):
     try:
         return QgsGPSConnectionRegistry.instance().connectionList()[0]
     except IndexError:
         return None
Пример #9
0
 def startProcess(self):
     connectionRegistry = QgsGPSConnectionRegistry().instance()
     connectionList = connectionRegistry.connectionList()
     if connectionList == []:
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         msgBox.setText(
             "GPS connection not detected.\nConnect a GPS and try again")
         msgBox.exec_()
         return
     GPSInfo = connectionList[0].currentGPSInformation()
     self.capturePointGroupBox.setEnabled(False)
     if not self.configureDialog.getIsOk():
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         msgBox.setText("The configuration is not valid")
         msgBox.exec_()
         return
     if self.useCode:
         self.codePushButton.setEnabled(True)
         self.codeLineEdit.setEnabled(True)
     else:
         self.codePushButton.setEnabled(False)
         self.codeLineEdit.setEnabled(False)
         self.codeLineEdit.clear()
     if self.useName:
         self.namePushButton.setEnabled(True)
         self.nameLineEdit.setEnabled(True)
     else:
         self.namePushButton.setEnabled(False)
         self.nameLineEdit.setEnabled(False)
         self.nameLineEdit.clear()
     if self.useNumber:
         self.numberPushButton.setEnabled(True)
         self.numberLineEdit.setEnabled(True)
     else:
         self.numberPushButton.setEnabled(False)
         self.numberLineEdit.setEnabled(False)
         self.numberLineEdit.clear()
     if self.useHeight:
         self.heightAntennaPushButton.setEnabled(True)
         self.heightAntennaLineEdit.setEnabled(True)
         self.antennaHeight = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_ANTENNA_HEIGHT_DEFAULT_VALUE
         strAntennaHeigth = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_ANTENNA_HEIGHT_PRECISION.format(
             self.antennaHeight)
         self.heightAntennaLineEdit.setText(strAntennaHeigth)
         self.heightGpsLabel.setEnabled(True)
         self.heightGpsLineEdit.setEnabled(True)
         self.heightGroundLabel.setEnabled(True)
         self.heightGroundLineEdit.setEnabled(True)
         if self.useGeoidModel and self.geoidModelFileName:
             self.heightGeoidLabel.setEnabled(True)
             self.heightGeoidLineEdit.setEnabled(True)
             self.heightFromGeoidLabel.setEnabled(True)
             self.heightFromGeoidLineEdit.setEnabled(True)
         else:
             self.heightGeoidLabel.setEnabled(False)
             self.heightGeoidLineEdit.setEnabled(False)
             self.heightGeoidLineEdit.clear()
             self.heightFromGeoidLabel.setEnabled(False)
             self.heightFromGeoidLineEdit.setEnabled(False)
             self.heightFromGeoidLineEdit.clear()
     else:
         self.heightAntennaPushButton.setEnabled(False)
         self.heightAntennaLineEdit.setEnabled(False)
         self.heightAntennaLineEdit.clear()
         self.heightGpsLabel.setEnabled(False)
         self.heightGpsLineEdit.setEnabled(False)
         self.heightGpsLineEdit.clear()
         self.heightGroundLabel.setEnabled(False)
         self.heightGroundLineEdit.setEnabled(False)
         self.heightGroundLineEdit.clear()
         self.heightGeoidLabel.setEnabled(False)
         self.heightGeoidLineEdit.setEnabled(False)
         self.heightGeoidLineEdit.clear()
         self.heightFromGeoidLabel.setEnabled(False)
         self.heightFromGeoidLineEdit.setEnabled(False)
         self.heightFromGeoidLineEdit.clear()
     fileName = self.csvFileName
     if not fileName:
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         msgBox.setText("You must select CSV file")
         msgBox.exec_()
         return
     strDateTime = ""
     if QFile.exists(fileName):
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         text = "Exists CSV file:\n" + fileName
         msgBox.setText(text)
         msgBox.setInformativeText(
             "Do you want to rename it with current date an time?")
         msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Discard
                                   | QMessageBox.Cancel)
         msgBox.setDefaultButton(QMessageBox.Ok)
         ret = msgBox.exec_()
         if ret == QMessageBox.Ok:
             dateTime = QDateTime.currentDateTime()
             strDateTime = dateTime.toString("yyyy-MM-dd_HH-mm-ss")
             fileInfo = QFileInfo(fileName)
             filePath = fileInfo.absolutePath()
             fileNameWithoutExtension = fileInfo.completeBaseName()
             fileExtension = fileInfo.completeSuffix()
             newFileName = filePath + "/" + fileNameWithoutExtension + "_" + strDateTime + "." + fileExtension
             if not QFile.copy(fileName, newFileName):
                 msgBox = QMessageBox(self)
                 msgBox.setIcon(QMessageBox.Warning)
                 msgBox.setWindowTitle(
                     constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
                 msgBox.setWindowTitle(
                     constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
                 msgBox.setText("Error copying existing file:\n" +
                                fileName + "\n" + newFileName)
                 msgBox.exec_()
                 return
     if not self.crs.isValid():
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         msgBox.setText("You must select the output CRS")
         msgBox.exec_()
         return
     if self.useGeoidModel and self.geoidModelFileName == constants.CONST_GNSS_3D_CAPTURE_COMBOBOX_NO_SELECT_OPTION:
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         msgBox.setText(
             "If you select substract geoide height \n you must select a geoid model"
         )
         msgBox.exec_()
         return
     csvFile = QFile(fileName)
     if not csvFile.open(QIODevice.WriteOnly | QIODevice.Text):
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         msgBox.setText("Error opening for writting file:\n" + fileName)
         msgBox.exec_()
         return
     csvTextStream = QTextStream(csvFile)
     fileInfo = QFileInfo(fileName)
     self.memoryLayerName = fileInfo.completeBaseName()
     existsMemoryLayer = None
     for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
         if lyr.name() == self.memoryLayerName:
             existsMemoryLayer = lyr
             break
     if existsMemoryLayer != None:
         newMemoryLayerName = self.memoryLayerName + "_" + strDateTime
         existsMemoryLayer.setLayerName(newMemoryLayerName)
     memoryLayerTypeAndCrs = "Point?crs=" + self.crs.authid()  #EPSG:4326"
     self.memoryLayer = QgsVectorLayer(memoryLayerTypeAndCrs,
                                       self.memoryLayerName, "memory")
     self.memoryLayerDataProvider = self.memoryLayer.dataProvider()
     memoryLayerFields = []
     # add fields
     firstField = True
     if self.useName:
         csvTextStream << "Name"
         firstField = False
         memoryLayerFields.append(QgsField("Name", QVariant.String))
     if self.useNumber:
         if not firstField:
             csvTextStream << ","
         else:
             firstField = False
         csvTextStream << "Number"
         memoryLayerFields.append(QgsField("Number", QVariant.Int))
     if not firstField:
         csvTextStream << ","
     else:
         firstField = False
     if not self.crs.geographicFlag():
         csvTextStream << "Easting"
         csvTextStream << "," << "Northing"
         memoryLayerFields.append(QgsField("Easting", QVariant.Double))
         memoryLayerFields.append(QgsField("Northing", QVariant.Double))
     else:
         csvTextStream << "Longitude"
         csvTextStream << "," << "Latitude"
         memoryLayerFields.append(QgsField("Longitude", QVariant.Double))
         memoryLayerFields.append(QgsField("Latitude", QVariant.Double))
     if self.useHeight:
         csvTextStream << "," << "Height"
         memoryLayerFields.append(QgsField("Height", QVariant.Double))
     if self.useCode:
         csvTextStream << "," << "Code"
         memoryLayerFields.append(QgsField("Code", QVariant.String))
     csvFile.close()
     self.memoryLayerDataProvider.addAttributes(memoryLayerFields)
     # self.memoryLayerDataProvider.addAttributes([QgsField("Name", QVariant.String),
     #                                             QgsField("Number", QVariant.String),
     #                                             QgsField("FirstCoordinate", QVariant.Double),
     #                                             QgsField("SecondCoordinate", QVariant.Double),
     #                                             QgsField("Height", QVariant.Double),
     #                                             QgsField("Code",  QVariant.Int)])
     self.memoryLayer.startEditing()
     self.memoryLayer.commitChanges()
     qmlFileName = self.path_plugin + "/" + constants.CONST_GNSS_3D_CAPTURE_QML_TEMPLATES_FOLDER + "/"
     if self.useName:
         qmlFileName += constants.CONST_GNSS_3D_CAPTURE_QML_TEMPLATES_FOLDER_QML_POINT_NAME_Z
     elif self.useNumber:
         qmlFileName += constants.CONST_GNSS_3D_CAPTURE_QML_TEMPLATES_FOLDER_QML_POINT_NUMBER_Z
     else:
         qmlFileName += constants.CONST_GNSS_3D_CAPTURE_QML_TEMPLATES_FOLDER_QML_POINT_Z
     self.memoryLayer.loadNamedStyle(qmlFileName)
     QgsMapLayerRegistry.instance().addMapLayer(self.memoryLayer)
     epsgCodeGps = constants.CONST_GNSS_3D_CAPTURE_EPSG_CODE_GPS
     self.crsGps = QgsCoordinateReferenceSystem(epsgCodeGps)
     if not self.crsGps.isValid():
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         msgBox.setText("Error creating CRS by EPSG Code: " +
                        str(epsgCodeGps))
         msgBox.exec_()
         self.isValid = False
         return
     self.crsOperationFromGps = QgsCoordinateTransform(
         self.crsGps, self.crs)
     if self.useHeight:
         if self.useGeoidModel:
             if not QFile.exists(self.geoidModelFileName):
                 msgBox = QMessageBox(self)
                 msgBox.setIcon(QMessageBox.Information)
                 msgBox.setWindowTitle(
                     constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
                 msgBox.setText("Geoid Model file not exists:\n" +
                                self.geoidModelFileName)
                 msgBox.exec_()
                 self.isValid = False
                 return
             geoidModelFileInfo = QFileInfo(self.geoidModelFileName)
             geoidModelPath = geoidModelFileInfo.filePath()
             geoidModelBaseName = geoidModelFileInfo.baseName()
             self.geoidModel = QgsRasterLayer(geoidModelPath,
                                              geoidModelBaseName)
             self.crsGeoidModel = self.geoidModel.crs()
             if not self.crsGeoidModel.isValid():
                 msgBox = QMessageBox(self)
                 msgBox.setIcon(QMessageBox.Information)
                 msgBox.setWindowTitle(
                     constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
                 msgBox.setText("Error getting Geoid Model CRS:\n" +
                                self.geoidModelFileName)
                 msgBox.exec_()
                 self.isValid = False
                 return
             self.geoidStepFirstCoordinate = self.geoidModel.rasterUnitsPerPixelX(
             )  # debe ser positivo
             self.geoidStepSecondCoordinate = 1.0 * self.geoidModel.rasterUnitsPerPixelX(
             )  # debe ser positivo
             self.geoidExtend = self.geoidModel.dataProvider().extent()
             self.geoidMinimumFirstCoordinate = self.geoidExtend.xMinimum()
             self.geoidMaximumSecondCoordinate = self.geoidExtend.yMaximum()
             self.crsOperationFromGpsToGeoid = QgsCoordinateTransform(
                 self.crsGps, self.crsGeoidModel)
     self.capturePointGroupBox.setEnabled(True)
     self.configurePushButton.setEnabled(False)
     self.startPushButton.setEnabled(False)
     self.finishPushButton.setEnabled(True)
     if self.useNumber:
         strFirstNumber = str(
             constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_FIRST_POINT_NUMBER)
         self.numberLineEdit.setText(strFirstNumber)
     self.updatePosition()
Пример #10
0
 def savePoint(self):
     connectionRegistry = QgsGPSConnectionRegistry().instance()
     connectionList = connectionRegistry.connectionList()
     if connectionList == []:
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         msgBox.setText(
             "GPS connection not detected.\nConnect a GPS and try again")
         msgBox.exec_()
         return
     csvFile = QFile(self.csvFileName)
     if not csvFile.open(QIODevice.Append | QIODevice.Text):
         msgBox = QMessageBox(self)
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setWindowTitle(constants.CONST_GNSS_3D_CAPTURE_WINDOW_TITLE)
         msgBox.setText("Error opening for writting file:\n" +
                        self.csvFileName)
         msgBox.exec_()
         return
     csvTextStream = QTextStream(csvFile)
     csvTextStream << "\n"
     fieldValues = {}
     fieldNumber = 0
     listFieldValues = []
     if self.useName:
         name = self.nameLineEdit.text()
         csvTextStream << name << ","
         #fieldValues[fieldNumber]=QVariant(name)
         fieldValues[fieldNumber] = name
         fieldNumber = fieldNumber + 1
         listFieldValues.append(name)
     if self.useNumber:
         number = self.numberLineEdit.text()
         csvTextStream << number << ","
         #fieldValues[fieldNumber]=QVariant(number)
         fieldValues[fieldNumber] = number
         fieldNumber = fieldNumber + 1
         listFieldValues.append(number)
     GPSInfo = connectionList[0].currentGPSInformation()
     firstCoordinate = GPSInfo.longitude
     secondCoordinate = GPSInfo.latitude
     pointCrsGps = QgsPoint(firstCoordinate, secondCoordinate)
     pointCrs = self.crsOperationFromGps.transform(pointCrsGps)
     firstCoordinate = pointCrs.x()
     secondCoordinate = pointCrs.y()
     if self.crs.geographicFlag():
         strFirstCoordinate = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_LONGITUDE_PRECISION.format(
             firstCoordinate)
         strSecondCoordinate = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_LATITUDE_PRECISION.format(
             secondCoordinate)
     else:
         strFirstCoordinate = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_EASTING_PRECISION.format(
             firstCoordinate)
         strSecondCoordinate = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_NORTHING_PRECISION.format(
             secondCoordinate)
     csvTextStream << strFirstCoordinate << ","
     csvTextStream << strSecondCoordinate
     #fieldValues[fieldNumber]=QVariant(firstCoordinate)
     fieldValues[fieldNumber] = firstCoordinate
     listFieldValues.append(firstCoordinate)
     fieldNumber = fieldNumber + 1
     #fieldValues[fieldNumber]=QVariant(secondCoordinate)
     fieldValues[fieldNumber] = secondCoordinate
     listFieldValues.append(secondCoordinate)
     fieldNumber = fieldNumber + 1
     if self.useHeight:
         antennaHeight = float(self.heightAntennaLineEdit.text())
         height = GPSInfo.elevation
         height = height - antennaHeight
         if self.useGeoidModel:
             geoidHeight = self.getGeoidInterpolatedValue(
                 GPSInfo.longitude, GPSInfo.latitude)
             if geoidHeight == constants.CONST_GNSS_3D_CAPTURE_GEOIDS_NO_VALUE:
                 return
             height = height - geoidHeight
         strHeight = constants.CONST_GNSS_3D_CAPTURE_SAVE_POINT_HEIGHT_PRECISION.format(
             height)
         csvTextStream << "," << strHeight
         #fieldValues[fieldNumber]=QVariant(height)
         fieldValues[fieldNumber] = height
         listFieldValues.append(height)
         fieldNumber = fieldNumber + 1
     if self.useCode:
         code = self.codeLineEdit.text()
         csvTextStream << "," << code
         #fieldValues[fieldNumber]=QVariant(code)
         fieldValues[fieldNumber] = code
         listFieldValues.append(code)
     csvFile.close()
     fet = QgsFeature()
     fet.setGeometry(
         QgsGeometry.fromPoint(QgsPoint(firstCoordinate, secondCoordinate)))
     #fet.setAttributeMap(fieldValues)
     fet.setAttributes(listFieldValues)
     self.memoryLayerDataProvider.addFeatures([fet])
     self.memoryLayer.commitChanges()
     self.memoryLayerName.triggerRepaint()
     if self.useNumber:
         self.pointNumbers.append(int(number))
         candidateValue = self.pointNumbers[len(self.pointNumbers) - 1] + 1
         if self.pointNumbers.count(candidateValue) != 0:
             control = True
             while control:
                 candidateValue = candidateValue + 1
                 if self.pointNumbers.count(candidateValue) == 0:
                     control = False
         self.numberLineEdit.setText(str(candidateValue))
     self.accept()
Пример #11
0
 def _gpsfound(self, gpsConnection):
     log("GPS found")
     self.gpsConn = gpsConnection
     self.gpsConn.stateChanged.connect(self.gpsStateChanged)
     self.isConnected = True
     QgsGPSConnectionRegistry.instance().registerConnection(self.gpsConn)