Beispiel #1
0
def beregning(firedb, sagsevent, koordinat, observationer):
    sagsevent.eventtype = EventType.KOORDINAT_BEREGNET
    b0 = Beregning(sagsevent=sagsevent,
                   observationer=observationer,
                   koordinater=[koordinat])
    firedb.session.add(b0)
    return b0
Beispiel #2
0
    def indset_beregning(self, sagsevent: Sagsevent, beregning: Beregning):
        if not self._is_new_object(beregning):
            raise Exception(f"Cannot re-add already persistent beregning: {beregning}")

        self._check_and_prepare_sagsevent(sagsevent, EventType.KOORDINAT_BEREGNET)
        beregning.sagsevent = sagsevent
        for koordinat in beregning.koordinater:
            if not self._is_new_object(koordinat):
                raise Exception(
                    f"Added beregning cannot refer to existing koordinat: {koordinat}"
                )
            koordinat.sagsevent = sagsevent
        self.session.add(beregning)
        self.session.commit()
Beispiel #3
0
def test_indset_beregning(
    firedb: FireDb,
    sag: Sag,
    sagsevent: Sagsevent,
    punkt: Punkt,
    srid: Srid,
    observationstype: ObservationsType,
):
    o0 = Observation(
        sagsevent=sagsevent,
        observationstidspunkt=func.current_timestamp(),
        observationstype=observationstype,
        opstillingspunkt=punkt,
    )

    firedb.indset_sagsevent(
        Sagsevent(
            sag=sag,
            sagseventinfos=[
                SagseventInfo(beskrivelse="Testindsættelse af observation")
            ],
            eventtype=EventType.OBSERVATION_INDSAT,
            observationer=[o0],
        ))
    beregning = Beregning()
    beregning.observationer.append(o0)
    koordinat = Koordinat(srid=srid,
                          punkt=punkt,
                          x=0,
                          y=0,
                          z=0,
                          sx=0,
                          sy=0,
                          sz=0)
    beregning.koordinater.append(koordinat)

    firedb.indset_sagsevent(
        Sagsevent(
            sag=sag,
            eventtype=EventType.KOORDINAT_BEREGNET,
            sagseventinfos=[SagseventInfo(beskrivelse="Testberegning")],
            beregninger=[beregning],
            koordinater=beregning.koordinater,
        ))

    assert koordinat.objektid is not None
Beispiel #4
0
    def read(self, sags_id):

        sag = self.fireDb.hent_sag(sags_id)

        namespace = "{http://www.gnu.org/software/gama/gama-local-adjustment}"
        tree = ET.parse(self.input_stream)
        root = tree.getroot()

        beregning = Beregning()

        srid = self.fireDb.hent_srid("EPSG:5799")

        adjusted_element = root.find(namespace +
                                     "coordinates").find(namespace +
                                                         "adjusted")
        cov_mat_values = (
            root.find(namespace +
                      "coordinates").find(namespace +
                                          "cov-mat").findall(namespace +
                                                             "flt"))
        original_index_indicies = (
            root.find(namespace +
                      "coordinates").find(namespace +
                                          "original-index").findall(namespace +
                                                                    "ind"))

        for idx, point in enumerate(adjusted_element.iter(namespace +
                                                          "point")):
            # Read values from the point
            z = point.find(namespace + "z").text
            point_id = point.find(namespace + "id").text

            # Read the correct entry in cov_mat_values
            cov_mat_index = int(original_index_indicies[idx].text) - 1
            cov_mat_element = cov_mat_values[cov_mat_index]
            # Read value as float
            cov_mat_value = float(cov_mat_element.text)
            # .. and tale sqrt to find std_dev
            std_dev = math.sqrt(cov_mat_value)

            koordinat = Koordinat()
            koordinat.srid = srid
            koordinat.z = z
            koordinat.sz = std_dev
            koordinat.punkt = self.fireDb.hent_punkt(point_id)
            beregning.koordinater.append(koordinat)

        observation_id_list = []
        observations_element = root.find(namespace + "observations")
        for idx, diff in enumerate(
                observations_element.iter(namespace + "height-diff")):
            observationId = diff.get("extern")
            observation_id_list.append(observationId)

        observation_list = self.fireDb.hent_observationer(observation_id_list)
        beregning.observationer.extend(observation_list)

        self.fireDb.indset_sagsevent(
            Sagsevent(
                sag=sag,
                eventtype=EventType.KOORDINAT_BEREGNET,
                sagseventinfos=[
                    SagseventInfo(beskrivelse="Beregning indlæst via GNU Gama")
                ],
                beregninger=[beregning],
                koordinater=beregning.koordinater,
            ))
Beispiel #5
0
    def read(self, sags_id):

        sag = self.fireDb.hent_sag(sags_id)

        namespace = "{http://www.gnu.org/software/gama/gama-local-adjustment}"
        tree = ET.parse(self.input_stream)
        root = tree.getroot()

        # In the description
        description_element = root.find(namespace + "description")
        description = description_element.text

        # .. find all obervation ids
        # observation_ids_start = description.find("{observation_ids}") + len("{observation_ids} :")
        # bservation_ids_end = description.find("{/observation_ids}")
        # observation_ids = description[observation_ids_start:observation_ids_end]
        # observation_id_list= ast.literal_eval(observation_ids)

        # ... and fetch those observations

        beregning = Beregning()

        srid = self.fireDb.hent_srid("EPSG:5799")

        adjusted_element = root.find(namespace +
                                     "coordinates").find(namespace +
                                                         "adjusted")
        cov_mat_values = (
            root.find(namespace +
                      "coordinates").find(namespace +
                                          "cov-mat").findall(namespace +
                                                             "flt"))
        original_index_indicies = (
            root.find(namespace +
                      "coordinates").find(namespace +
                                          "original-index").findall(namespace +
                                                                    "ind"))

        for idx, point in enumerate(adjusted_element.iter(namespace +
                                                          "point")):
            # Read values from the point
            z = point.find(namespace + "z").text
            point_id = point.find(namespace + "id").text

            # Read the correct entry in cov_mat_values
            cov_mat_index = int(original_index_indicies[idx].text) - 1
            cov_mat_element = cov_mat_values[cov_mat_index]
            # Read value as float
            cov_mat_value = float(cov_mat_element.text)
            # .. and tale sqrt to find std_dev
            std_dev = math.sqrt(cov_mat_value)

            koordinat = Koordinat()
            koordinat.srid = srid
            koordinat.z = z
            koordinat.sz = std_dev
            koordinat.transformeret = "false"
            koordinat.punkt = self.fireDb.hent_punkt(point_id)
            beregning.koordinater.append(koordinat)

        observation_id_list = []
        observations_element = root.find(namespace + "observations")
        for idx, diff in enumerate(
                observations_element.iter(namespace + "height-diff")):
            observationId = diff.get("extern")
            observation_id_list.append(observationId)

        observation_list = self.fireDb.hent_observationer(observation_id_list)
        beregning.observationer.extend(observation_list)

        self.fireDb.indset_beregning(Sagsevent(sag=sag), beregning)
Beispiel #6
0
def test_indset_beregning_invalidates_existing_koordinat(
        firedb: FireDb, sag: Sag, punkt: Punkt, srid: Srid,
        observation: Observation):
    firedb.indset_sagsevent(
        Sagsevent(
            sag=sag,
            sagseventinfos=[
                SagseventInfo(beskrivelse="Testindsættelse af observation")
            ],
            eventtype=EventType.OBSERVATION_INDSAT,
            observationer=[observation],
        ))
    beregning = Beregning()
    beregning.observationer.append(observation)
    koordinat = Koordinat(srid=srid,
                          punkt=punkt,
                          x=0,
                          y=0,
                          z=0,
                          sx=0,
                          sy=0,
                          sz=0)
    beregning.koordinater.append(koordinat)

    firedb.indset_sagsevent(
        Sagsevent(
            sag=sag,
            eventtype=EventType.KOORDINAT_BEREGNET,
            sagseventinfos=[SagseventInfo(beskrivelse="Testberegning")],
            beregninger=[beregning],
            koordinater=beregning.koordinater,
        ))

    # new beregning of the same observation with a new koordinat
    beregning2 = Beregning()
    beregning2.observationer.append(observation)
    koordinat2 = Koordinat(
        srid=srid,
        punkt=punkt,
        x=1,
        y=0,
        z=0,
        sx=0,
        sy=0,
        sz=0,
    )
    beregning2.koordinater.append(koordinat2)

    firedb.indset_sagsevent(
        Sagsevent(
            sag=sag,
            eventtype=EventType.KOORDINAT_BEREGNET,
            sagseventinfos=[SagseventInfo(beskrivelse="Testberegning")],
            beregninger=[beregning2],
            koordinater=beregning2.koordinater,
        ))

    assert len(punkt.koordinater) == 2
    assert len([k for k in punkt.koordinater
                if k.registreringtil is None]) == 1
    assert koordinat2.srid is not None