def test_to_wkb_srid(): # hex representation of POINT (0 0) with SRID=4 ewkb = "01010000200400000000000000000000000000000000000000" wkb = "010100000000000000000000000000000000000000" actual = pygeos.from_wkb(ewkb) assert pygeos.to_wkt(actual, trim=True) == "POINT (0 0)" assert pygeos.to_wkb(actual, hex=True, byte_order=1) == wkb assert pygeos.to_wkb(actual, hex=True, include_srid=True, byte_order=1) == ewkb point = pygeos.points(1, 1) point_with_srid = pygeos.set_srid(point, np.int32(4326)) result = pygeos.to_wkb(point_with_srid, include_srid=True, byte_order=1) assert np.frombuffer(result[5:9], "<u4").item() == 4326
def _convert_to_ewkb(gdf, geom_name, srid): """Convert geometries to ewkb. """ if compat.USE_PYGEOS: from pygeos import set_srid, to_wkb geoms = to_wkb(set_srid(gdf[geom_name].values.data, srid=srid), hex=True, include_srid=True) else: from shapely.wkb import dumps geoms = [dumps(geom, srid=srid, hex=True) for geom in gdf[geom_name]] gdf[geom_name] = geoms return gdf
def _convert_to_ewkb(gdf, geom_name, srid): """Convert geometries to ewkb. """ if compat.USE_PYGEOS: from pygeos import set_srid, to_wkb geoms = to_wkb(set_srid(gdf[geom_name].values.data, srid=srid), hex=True, include_srid=True) else: from shapely.wkb import dumps geoms = [dumps(geom, srid=srid, hex=True) for geom in gdf[geom_name]] # The gdf will warn that the geometry column doesn't hold in-memory geometries # now that they are EWKB, so convert back to a regular dataframe to avoid warning # the user that the dtypes are unexpected. df = pd.DataFrame(gdf, copy=False) df[geom_name] = geoms return df
def test_get_set_srid(): actual = pygeos.set_srid(point, 4326) assert pygeos.get_srid(point) == 0 assert pygeos.get_srid(actual) == 4326
def test_to_wkb_with_srid(): point_with_srid = pygeos.set_srid(point, np.int32(4326)) result = point_with_srid.to_wkb(include_srid=True) assert np.frombuffer(result[5:9], "<u4").item() == 4326
def test_pickle_with_srid(): geom = pygeos.set_srid(point, 4326) pickled = pickle.dumps(geom) assert pygeos.get_srid(pickle.loads(pickled)) == 4326
def test_to_wkb_point_empty_srid(): expected = pygeos.set_srid(empty_point, 4236) wkb = pygeos.to_wkb(expected, include_srid=True) actual = pygeos.from_wkb(wkb) assert pygeos.get_srid(actual) == 4236
def add_srid(wkb, srid=4326): return to_wkb(set_srid(from_wkb(wkb), srid), hex=True, include_srid=True)
def random_point(): point = points(random.uniform(-90, 90), random.uniform(-180, 180)) return set_srid(point, 4326)