예제 #1
0
    def python_postread(self, geom):
        # We normalise geometries to avoid spurious diffs - diffs where nothing
        # of any consequence has changed (eg, only endianness has changed).
        # This includes setting the SRID to zero for each geometry so that we don't store a separate SRID per geometry,
        # but only one per column at most.

        # Its possible in GPKG to put arbitrary values in columns, regardless of type.
        # We don't try to convert them here - we let the commit validation step report this as an error.
        return normalise_gpkg_geom(geom) if isinstance(geom, bytes) else geom
예제 #2
0
파일: v1.py 프로젝트: koordinates/kart
 def features(self):
     # Geometries weren't normalised in V1, but they are in V2.
     # Normalise them here.
     geom_column = self.geom_column_name
     for feature in super().features():
         if geom_column:
             # add bboxes to geometries.
             feature[geom_column] = normalise_gpkg_geom(
                 feature[geom_column])
         yield feature
예제 #3
0
def test_gpkg_wkb_gpkg_roundtrip(input, input_has_envelope, little_endian,
                                 little_endian_wkb, with_envelope):
    """
    Tests the following functions work and are consistent with each other:
        * normalise_gpkg_geom
        * gpkg_geom_to_hex_wkb
        * hex_wkb_to_gpkg_geom
    """
    assert normalise_gpkg_geom(input) == input
    hex_wkb = gpkg_geom_to_hex_wkb(input)
    assert hex_wkb.startswith(
        "01"), "gpkg_geom_to_hex_wkb produced big-endian WKB"

    # Produce a GPKG geom in LE/BE variants of both the GPKG headers and the WKB itself.
    gpkg_geom_intermediate = hex_wkb_to_gpkg_geom(
        hex_wkb,
        _little_endian=little_endian,
        _little_endian_wkb=little_endian_wkb,
        _add_envelope_type=GPKG_ENVELOPE_XY
        if with_envelope else GPKG_ENVELOPE_NONE,
    )
    assert normalise_gpkg_geom(gpkg_geom_intermediate) == input

    if little_endian and little_endian_wkb and with_envelope == input_has_envelope:
        assert gpkg_geom_intermediate == input
        return

    else:
        if with_envelope and not input_has_envelope:
            # If we're adding an envelope, the geometry should have gotten bigger...
            assert len(gpkg_geom_intermediate) > len(input)
        elif input_has_envelope and not with_envelope:
            # If we're removing an envelope, the geometry should have gotten smaller...
            assert len(gpkg_geom_intermediate) < len(input)
        else:
            assert len(gpkg_geom_intermediate) == len(input)

    # Now re-roundtrip to convert it back to the original
    # (little-endian, no envelope)
    hex_wkb_2 = gpkg_geom_to_hex_wkb(gpkg_geom_intermediate)
    gpkg_geom = hex_wkb_to_gpkg_geom(hex_wkb_2)

    assert gpkg_geom == input
예제 #4
0
파일: v0.py 프로젝트: koordinates/kart
    def features(self):
        geom_column = self.geom_column_name

        for feature_dir in self._iter_feature_dirs():
            source_feature_dict = {}
            for attr_blob in feature_dir:
                if not hasattr(attr_blob, "data"):
                    continue
                attr = attr_blob.name
                if attr == geom_column:
                    source_feature_dict[attr] = normalise_gpkg_geom(
                        attr_blob.data)
                else:
                    source_feature_dict[attr] = json_unpack(attr_blob.data)
            yield source_feature_dict
예제 #5
0
def test_normalise_geometry(input, expected):
    assert normalise_gpkg_geom(input) == expected