Beispiel #1
0
def getAttributeInformation(file, project):
    from qpals.qpals import QpalsModuleBase, QpalsParameter
    infoinst = QpalsModuleBase.QpalsModuleBase(execName=os.path.join(project.opalspath, "opalsInfo.exe"),
                                               QpalsProject=project)
    infoinst.params = [QpalsParameter.QpalsParameter('inFile', file,
                                                     None, None, None, None, None)]
    try:
        moduleOut = infoinst.run(show=0)
        outtext = moduleOut['stdout']
        ## begin parsing of log
        header_passed = False
        attrs = []
        entries = []
        for line in outtext.split("\n"):
            if line.startswith("Attribute "):
                header_passed = True
                entries = line.split()
            elif header_passed:
                data = line.split()
                if len(data) == 0:  # end of attribute list
                    break
                attrs.append(data)
        if not header_passed:
            raise NotImplementedError
        return attrs, entries
    except Exception as e:
        raise e
        return None, None
Beispiel #2
0
    def runview(self):
        self.secInst.runSecBtnView.setEnabled(False)
        regionFilter = "Region["
        for p in self.rbPoints:
            regionFilter += "%.3f %.3f " % (p[0], p[1])
        regionFilter += "]"
        if self.secInst.filterStr.text() != "":
            regionFilter = regionFilter + " and " + self.secInst.filterStr.text(
            )
        Module = QpalsModuleBase.QpalsModuleBase(
            execName=os.path.join(self.secInst.project.opalspath,
                                  "opalsView.exe"),
            QpalsProject=self.secInst.project)
        infile = QpalsParameter.QpalsParameter(
            'inFile', self.secInst.txtinfileSimple.text(), None, None, None,
            None, None)
        filter = QpalsParameter.QpalsParameter('filter', regionFilter, None,
                                               None, None, None, None)

        Module.params.append(infile)
        Module.params.append(filter)
        thread, worker = Module.run_async(status=self.update_status,
                                          on_error=self.sec_error,
                                          on_finish=self.runviewfinished)
        self.thread.append(thread)
        self.worker.append(worker)
Beispiel #3
0
 def update_status(self, message):
     out_lines = [item for item in re.split("[\n\r\b]", message) if item]
     percentage = out_lines[-1]
     # print percentage
     if r"%" in percentage:
         perc = QpalsModuleBase.get_percentage(percentage)
         self.secInst.progress.setValue(int(perc))
Beispiel #4
0
    def initUI(self):
        self.ui = QtWidgets.QDialog()
        lo = QtWidgets.QFormLayout()
        self.ui.setSizePolicy(QtWidgets.QSizePolicy.Preferred,
                              QtWidgets.QSizePolicy.Maximum)
        lo.addRow(QtWidgets.QLabel("Load ALS file(s):"))
        self.dropspace = QpalsDropTextbox.QpalsDropTextbox(
            layerlist=self.layerlist)
        self.dropspace.setMinimumContentsLength(20)
        self.dropspace.setSizeAdjustPolicy(
            QtWidgets.QComboBox.AdjustToMinimumContentsLength)
        self.dropspace.editingFinished.connect(self.inFileUpdated)
        lo.addRow(self.dropspace)
        self.visMethod = QtWidgets.QComboBox()
        self.visMethod.addItem(VISUALISATION_METHODS[0])
        self.visMethod.addItem(VISUALISATION_METHODS[1])
        self.visMethod.addItem(VISUALISATION_METHODS[2])
        self.visMethod.addItem(VISUALISATION_METHODS[3])
        self.visMethod.addItem(VISUALISATION_METHODS[4])
        self.visMethod.addItem(VISUALISATION_METHODS[5])
        self.visMethod.addItem(VISUALISATION_METHODS[6])
        self.visMethod.addItem(VISUALISATION_METHODS[7])
        self.visMethod.addItem(VISUALISATION_METHODS[8])
        self.visMethod.addItem(VISUALISATION_METHODS[9])
        self.visMethod.currentIndexChanged.connect(self.updatevisMethod)
        self.cellSizeLbl = QtWidgets.QLabel("Set cell size:")
        self.cellSizeBox = QtWidgets.QLineEdit()
        self.cellFeatLbl = QtWidgets.QLabel("Set feature:")
        self.cellFeatCmb = QtWidgets.QComboBox()
        self.cellAttrLbl = QtWidgets.QLabel("Select attribute:")
        self.cellAttrCmb = QtWidgets.QComboBox()
        self.cellAttrCmb.addItem("Z")
        self.cellAttrCmb.setSizeAdjustPolicy(
            QtWidgets.QComboBox.AdjustToContents)
        self.isoInteLbl = QtWidgets.QLabel("Set isoline interval:")
        self.isoInteBox = QtWidgets.QLineEdit()
        self.isoInteBox.setText("10")
        cellInst = QpalsModuleBase.QpalsModuleBase(
            os.path.join(self.project.opalspath, "opalsCell.exe"),
            self.project)
        cellInst.load()
        for param in cellInst.params:
            if param.name.lower() == "cellsize":
                self.cellSizeBox.setText(param.val)
                break
        self.cellFeatCmb.addItems(self.features)
        self.cellFeatCmb.setCurrentIndex(4)
        lo.addRow(self.cellAttrLbl, self.cellAttrCmb)
        lo.addRow(self.cellSizeLbl, self.cellSizeBox)
        lo.addRow(self.cellFeatLbl, self.cellFeatCmb)
        lo.addRow(self.isoInteLbl, self.isoInteBox)
        lo.addRow(self.visMethod)
        self.okBtn = QtWidgets.QPushButton("Load")
        self.okBtn.clicked.connect(self.loadHelper)
        lo.addRow(self.okBtn)
        self.ui.setLayout(lo)
        self.ui.setWindowTitle("Open ALS file")

        self.visMethod.setCurrentIndex(1)
Beispiel #5
0
    def run_next(self):
        self.count += 1
        outShapeFileH = tempfile.NamedTemporaryFile(suffix=".shp", delete=True)
        outShapeFile = outShapeFileH.name
        outShapeFileH.close()

        self.write_axis_shape(outShapeFile)

        self.currattr = self.attrs_left.pop()
        self.secInst.progress.setValue(0)
        self.secInst.progress.setFormat(
            "Running opalsSection for attribute %s (%s/%s)..." %
            (self.currattr, self.count, self.total))
        Module = QpalsModuleBase.QpalsModuleBase(
            execName=os.path.join(self.secInst.project.opalspath,
                                  "opalsSection.exe"),
            QpalsProject=self.secInst.project)
        infile = QpalsParameter.QpalsParameter(
            'inFile', self.secInst.txtinfileSimple.text(), None, None, None,
            None, None)
        axisfile = QpalsParameter.QpalsParameter('axisFile', outShapeFile,
                                                 None, None, None, None, None)
        attribute = QpalsParameter.QpalsParameter('attribute', self.currattr,
                                                  None, None, None, None, None)
        if self.filter.text():
            attribute = QpalsParameter.QpalsParameter('filter',
                                                      self.filter.text(), None,
                                                      None, None, None, None)
        thickness = QpalsParameter.QpalsParameter(
            'patchSize', '%s;%s' % (self.seclength, self.width * 4), None,
            None, None, None, None)

        outParamFileH = tempfile.NamedTemporaryFile(suffix='.xml', delete=True)
        self.outParamFile = outParamFileH.name
        outParamFileH.close()
        outParamFileParam = QpalsParameter.QpalsParameter(
            'outParamFile', self.outParamFile, None, None, None, None, None)
        Module.params.append(infile)
        Module.params.append(axisfile)
        Module.params.append(thickness)
        Module.params.append(attribute)
        Module.params.append(outParamFileParam)
        thread, worker = Module.run_async(status=self.update_status,
                                          on_finish=self.parse_output,
                                          on_error=self.sec_error)
        self.thread.append(thread)
        self.worker.append(worker)
Beispiel #6
0
    def runLM(self):
        params = {}
        layer = self.cmbLineLayer.currentLayer()
        if self.selectedChkBox.checkState() == 2:
            infile = tempfile.NamedTemporaryFile(delete=False)
            params["approxFile"] = infile.name + ".shp"
            infile.close()
            QgsVectorFileWriter.writeAsVectorFormat(layer,
                                                    params["approxFile"],
                                                    "utf-8", layer.crs(),
                                                    "ESRI Shapefile",
                                                    1)  # 1 for selected only
            try:
                os.remove(infile.name + ".prj")
            except:
                pass
        else:
            params["approxFile"] = layer.source()

        outfile = tempfile.NamedTemporaryFile(delete=False)
        params["outFile"] = outfile.name + ".shp"
        outfile.close()

        params["inFile"] = self.cmbOdmPath.text()

        Module = QpalsModuleBase.QpalsModuleBase(execName=os.path.join(
            self.project.opalspath, "opalsLineModeler.exe"),
                                                 QpalsProject=self.project)

        paramlist = []
        for param in params.keys():
            paramlist.append(
                QpalsParameter.QpalsParameter(param, params[param], None, None,
                                              None, None, None))
        Module.params = paramlist
        #print "running module. writing outfile to %s" % params["outFile"]
        moduleOut = Module.run(show=0)
        #print moduleOut
        self.iface.addVectorLayer(params["outFile"],
                                  os.path.basename("Modelled Lines"), "ogr")
Beispiel #7
0
 def call(self,
          module,
          params,
          outext="",
          returnstdout=False,
          nooutfile=False):
     Module = QpalsModuleBase.QpalsModuleBase(execName=os.path.join(
         self.project.opalspath, module + ".exe"),
                                              QpalsProject=self.project)
     if "outFile" not in params and not nooutfile:
         file = tempfile.NamedTemporaryFile(delete=False)
         params["outFile"] = file.name + outext
         file.close()
     paramlist = []
     for param in params.keys():
         paramlist.append(
             QpalsParameter.QpalsParameter(param, params[param], None, None,
                                           None, None, None))
     Module.params = paramlist
     moduleOut = Module.run(show=0)
     if returnstdout:
         return moduleOut
     return params["outFile"]
Beispiel #8
0
    def createWidget(self):
        self.advanced_widget = QtWidgets.QDialog()
        self.simple_widget = QtWidgets.QDialog()
        self.tabs = QtWidgets.QTabWidget()
        ### SIMPLE ###
        self.ls = QtWidgets.QFormLayout()
        self.ls.addRow(QtWidgets.QLabel("Choose input file:"))
        self.txtinfileSimple = QpalsDropTextbox.QpalsDropTextbox(
            layerlist=self.layerlist, filterrex=".*\.odm$")
        hboxsimple1 = QtWidgets.QHBoxLayout()
        hboxsimple1.addWidget(self.txtinfileSimple, 1)
        self.txtinfileSimple.textChanged.connect(self.simpleIsLoaded)
        self.ls.addRow(QtWidgets.QLabel("Input file (odm)"), hboxsimple1)
        self.linetoolBtn = QtWidgets.QPushButton("Pick section")
        self.linetoolBtn.clicked.connect(self.activateLineTool)
        self.linetoolBtn.setEnabled(False)
        self.ls.addRow(self.linetoolBtn)

        self.runSecBtnSimple = QtWidgets.QPushButton("Create section")
        self.runSecBtnSimple.clicked.connect(self.ltool.runsec)
        self.runSecBtnSimple.setEnabled(False)
        self.runSecBtnSimple.setStyleSheet("background-color: rgb(50,240,50)")

        self.runSecBtnView = QtWidgets.QPushButton("Open section in opalsView")
        self.runSecBtnView.clicked.connect(self.ltool.runview)
        self.runSecBtnView.setEnabled(False)
        self.runSecBtnView.setStyleSheet("background-color: rgb(100,100,240)")
        hb = QtWidgets.QHBoxLayout()
        hb.addWidget(self.runSecBtnSimple)
        hb.addWidget(self.runSecBtnView)

        self.simpleLineLayer = QgsMapLayerComboBox()
        self.simpleLineLayer.setFilters(QgsMapLayerProxyModel.LineLayer)
        self.simpleLineLayerChk = QtWidgets.QCheckBox(
            "Visualize (3D) Line Layer:")
        self.ls.addRow(self.simpleLineLayerChk, self.simpleLineLayer)
        self.showSection = QtWidgets.QCheckBox("Show section")
        self.filterStr = QtWidgets.QLineEdit("Class[Ground]")
        self.filterAttrBox = QCollapsibleGroupBox.QCollapsibleGroupBox(
            'Show attribute selection')
        self.filterAttrBox.setLayout(QtWidgets.QGridLayout())
        self.filterAttrBox.setChecked(False)  # hide it
        self.filterAttrs = {}
        self.progress = QtWidgets.QProgressBar()
        self.stateSwitch = QToggleSwitch.QToggleSwitch("vispy", "matplotlib")
        self.showSection.stateChanged.connect(self.checkBoxChanged)
        self.showSection.setCheckState(2)
        self.showSection.setTristate(False)
        self.ls.addRow(self.showSection)
        self.ls.addRow("Filter String:", self.filterStr)
        self.ls.addRow(self.filterAttrBox)
        self.ls.addRow(hb)
        self.ls.addRow(self.progress)
        self.ls.addRow(self.stateSwitch)
        self.simple_widget.setLayout(self.ls)
        ### ADVANCED ###
        lo = QtWidgets.QFormLayout()
        ######
        lo.addRow(
            QtWidgets.QLabel("Step 1. Choose point cloud and visualize it:"))
        self.txtinfile = QpalsDropTextbox.QpalsDropTextbox(
            layerlist=self.layerlist)
        hbox1 = QtWidgets.QHBoxLayout()
        hbox1.addWidget(self.txtinfile, 1)
        lo.addRow(QtWidgets.QLabel("Input file (odm)"), hbox1)
        self.runShdBtn = QtWidgets.QPushButton("Create shading")
        self.runShdBtn.clicked.connect(self.loadShading)
        lo.addRow(self.runShdBtn)
        ######
        self.status = QtWidgets.QListWidgetItem("hidden status")
        lo.addRow(QtWidgets.QLabel("Step 2. Create sections"))
        self.secInst = QpalsModuleBase.QpalsModuleBase(
            execName=os.path.join(self.project.opalspath, "opalsSection.exe"),
            QpalsProject=self.project)
        self.secInst.load()
        self.secInst.listitem = self.status
        secUi = self.secInst.getParamUi()
        lo.addRow(secUi)

        self.runSecBtn = QtWidgets.QPushButton("Calculate sections")
        self.runSecBtn.clicked.connect(self.runSection)
        lo.addRow(self.runSecBtn)
        #######
        lo.addRow(
            QtWidgets.QLabel(
                "Step 3. Use the Section picking tool to show Sections"))
        self.pickSecBtn = QtWidgets.QPushButton("Pick section")
        self.pickSecBtn.clicked.connect(self.activateTool)
        lo.addRow(self.pickSecBtn)

        self.advanced_widget.setLayout(lo)
        self.tabs.addTab(self.simple_widget, "Simple")
        self.tabs.addTab(self.advanced_widget, "Advanced")

        self.scrollwidget = QtWidgets.QScrollArea()
        self.scrollwidget.setWidgetResizable(True)
        self.scrollwidget.setSizePolicy(QtWidgets.QSizePolicy.Ignored,
                                        QtWidgets.QSizePolicy.Ignored)
        self.scrollwidget.setWidget(self.tabs)

        return self.scrollwidget