Esempio n. 1
0
 def handleGeoUnitChange(self, geo_unit):
     self.geo_unit = geo_unit
     if TrLib.IsGeographic(str(self.cb_bshlm_system.currentText())):
         for field in self.input_bshlm:
             WidgetUtils.translateAngularField(field, geo_unit, precision=4)
     for field in self.output_bshlm_geo:
         WidgetUtils.translateAngularField(field, geo_unit, precision=4)
Esempio n. 2
0
    def doBesselHelmert(self):
        # Check if we need to update data....
        is_custom = self.chb_bshlm_custom_ellipsoid.isChecked()
        self.cache.is_valid = False
        self.logBshlm("", clear=True)
        if is_custom or str(self.cb_bshlm_system.currentText()) != self.cache.mlb:
            self.onBshlmSystemChanged(False)
        if not self.cache.valid_label:
            self.logBshlm("Invalid input label...", "red")
            self.clearOutput()
            return
        is_mode1 = self.rdobt_bshlm_mode1.isChecked()
        # Get needed input
        mlb = self.cache.mlb
        geo_mlb = self.cache.geo_mlb
        is_geo_in = is_custom or TrLib.IsGeographic(mlb)
        if is_mode1:
            coords, msg = WidgetUtils.getInput(
                self.input_bshlm, is_geo_in, z_fields=[], angular_unit=self.geo_unit)
            if len(coords) != 4:
                self.logBshlm("Input coordinate %d not OK.\n%s" %
                              (len(coords) + 1, msg), "red")
                self.input_bshlm[len(coords)].setFocus()
                self.clearOutput()
                return
            x1, y1, x2, y2 = coords

        else:
            coords, msg = WidgetUtils.getInput(
                self.input_bshlm[0:2], is_geo_in, z_fields=[], angular_unit=self.geo_unit)
            if len(coords) != 2:
                self.logBshlm("Station1 coordinates not OK.\n%s" % msg, "red")
                self.input_bshlm[len(coords)].setFocus()
                self.clearOutput()
                return
            input_data, msg = WidgetUtils.getInput(self.input_bshlm_azimuth, True, z_fields=[
                                                   0], angular_unit=self.geo_unit_derived)
            if len(input_data) != 2:
                self.logBshlm(
                    "Input distance and azimuth not OK.\n%s" % msg, "red")
                self.input_bshlm_azimuth[len(input_data)].setFocus()
                self.clearOutput()
                return
            x1, y1 = coords

            dist, a1 = input_data
        a = self.cache.axis
        f = self.cache.flattening
        #end get needed input#
        #transform to geo coords if needed#
        if not is_custom:
            try:
                ct = TrLib.CoordinateTransformation(mlb, geo_mlb)
            except:
                self.logBshlm("Input label not OK!", "red")
                self.clearOutput()
                return
            try:
                x1, y1, z = ct.Transform(x1, y1)
            except:
                msg = ""
                err = TrLib.GetLastError()
                if err in ERRORS:
                    msg = "\n%s" % ERRORS[err]
                self.logBshlm(
                    "Error in transformation of coords for station1" + msg, "red")
                self.clearOutput()
                return
        # display output of first transformation, x1,y1 should now alwyas be in
        # geo-coords#
        WidgetUtils.setOutput([x1, y1], self.output_bshlm_geo[
                              :2], True, z_fields=[], angular_unit=self.geo_unit)

        # Now get the other output from bshlm and transformations....
        if is_mode1:
            if not is_custom:
                try:  # transform to geographic
                    x2, y2, z = ct.Transform(x2, y2)
                except:
                    msg = ""
                    err = TrLib.GetLastError()
                    if err in ERRORS:
                        msg = "\n%s" % ERRORS[err]
                    self.logBshlm(
                        "Error in transformation of coords for station2" + msg, "red")
                    self.clearOutput()
                    return
            data = TrLib.BesselHelmert(a, f, x1, y1, x2, y2)
            if data[0] is not None:
                a1, a2 = data[1:]
                # WidgetUtils.setOutput(data,self.output_bshlm_azimuth,True,z_fields=[0],angular_unit=self.geo_unit_derived)
                self.output_bshlm_azimuth[0].setText("%.3f m" % data[0])
                self.output_bshlm_azimuth[1].setText(translateFromDegrees(
                    data[1], self.geo_unit_derived, precision=1))
                self.output_bshlm_azimuth[2].setText(translateFromDegrees(
                    data[2], self.geo_unit_derived, precision=1))
            else:
                self.message("Error: could not calculate azimuth!")
                self.clearOutput()
                return
        else:
            data = TrLib.InverseBesselHelmert(a, f, x1, y1, a1, dist)
            if data[0] is not None:
                x2, y2, a2 = data
                if not is_custom:
                    try:
                        x2_out, y2_out, z2 = ct.InverseTransform(x2, y2)
                    except:
                        msg = ""
                        err = TrLib.GetLastError()
                        if err in ERRORS:
                            msg = "\n%s" % ERRORS[err]
                        self.logBshlm(
                            "Error in transformation of coords for station2" + msg, "red")
                        self.clearOutput()
                        return
                else:
                    x2_out = x2
                    y2_out = y2
                # display result...
                WidgetUtils.setOutput([x2_out, y2_out], self.input_bshlm[
                                      2:], is_geo_in, z_fields=[], angular_unit=self.geo_unit)
                self.txt_bshlm_azimuth2.setText(translateFromDegrees(
                    a2, self.geo_unit_derived, precision=1))
            else:
                self.message(
                    "Error: could not do inverse Bessel Helmert calculation")
                self.clearOutput()
                return
        # always display ouput in geo field - even if not transformed
        self.cache.a1 = a1
        self.cache.a2 = a2
        WidgetUtils.setOutput([x2, y2],
                              self.output_bshlm_geo[2:], True, z_fields=[], angular_unit=self.geo_unit)
        self.cache.is_valid = True
        self.cache.mode = int(not is_mode1)