def features(self): geom_column = self.dataset.geom_column_name for _, feature in self.dataset.features(): if geom_column: # add bboxes to geometries. feature[geom_column] = normalise_gpkg_geom( feature[geom_column]) yield feature
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
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
def features(self): ggc = self.get_gpkg_meta_item("gpkg_geometry_columns") geom_field = ggc["column_name"] if ggc else None 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_field: source_feature_dict[attr] = normalise_gpkg_geom(attr_blob.data) else: source_feature_dict[attr] = json.loads( attr_blob.data.decode("utf8") ) yield source_feature_dict
def test_normalise_geometry(input, expected): assert normalise_gpkg_geom(input) == expected