def test_dump_hex_load_binary(some_point, tmpdir): """Asserts that reading a binary file as text (hex mode) fails.""" file = tmpdir.join("test.wkb") with open(file, "w") as file_pointer: dump(some_point, file_pointer, hex=True) with pytest.raises(WKBReadingError): with open(file, "rb") as file_pointer: load(file_pointer)
def test_dump_binary_load_hex(some_point, tmpdir): """Asserts that reading a text file (hex mode) as binary fails.""" file = tmpdir.join("test.wkb") with open(file, "wb") as file_pointer: dump(some_point, file_pointer) with pytest.raises( (WKBReadingError, UnicodeEncodeError, UnicodeDecodeError)): with open(file, "r") as file_pointer: load(file_pointer, hex=True)
def test_dump_load_hex(some_point, tmpdir): file = tmpdir.join("test.wkb") with open(file, "w") as file_pointer: dump(some_point, file_pointer, hex=True) with open(file, "r") as file_pointer: restored = load(file_pointer, hex=True) assert some_point == restored
def test_dump_load_binary(some_point, tmpdir): file = tmpdir.join("test.wkb") with open(file, "wb") as file_pointer: dump(some_point, file_pointer) with open(file, "rb") as file_pointer: restored = load(file_pointer) assert some_point == restored
def test_dump_binary_load_hex(some_point, tmpdir): """Asserts that reading a text file (hex mode) as binary fails.""" file = tmpdir.join("test.wkb") with open(file, "wb") as file_pointer: dump(some_point, file_pointer) # TODO(shapely-2.0) on windows this doesn't seem to error with pygeos, # but you get back a point with garbage coordinates if sys.platform == 'win32': with open(file, "r") as file_pointer: restored = load(file_pointer, hex=True) assert some_point != restored return with pytest.raises((UnicodeEncodeError, UnicodeDecodeError)): with open(file, "r") as file_pointer: load(file_pointer, hex=True)
def test_high_many_points_shapely(benchmark): xx, yy = np.mgrid[-180:180,-90:90] # 64800 points xx = xx.astype('float64') yy = yy.astype('float64') with open(high, 'rb') as fd: land = wkb.load (fd) prep = shapely.prepared.prep(land) contains = benchmark(shapely.vectorized.contains, prep, xx, yy) assert np.any(contains)
def __init__(self, extent=None, skippoly=False, __concurrency_delay__=0, __concurrency_abort__=False, __no_retry__=False, __retry_delete__=False): """ Initialize landmask from generated GeoTIFF Args: extent (array): [xmin, ymin, xmax, ymax] skippoly (bool): do not load polygons __concurrency_delay__: internally used for race condition testing, do not use. __concurrency_abort__: internally used for race condition testing, do not use. __no_retry__: internally used for mask generation testing, do not use. __retry_delete__: internally used for mask generation testing, do not use. """ self.extent = extent self.transform = self.get_transform() self.invtransform = self.get_inverse_transform() self.skippoly = skippoly self.__concurrency_delay__ = __concurrency_delay__ self.__concurrency_abort__ = __concurrency_abort__ self.__no_retry__ = __no_retry__ self.__retry_delete__ = __retry_delete__ self.__check_permissions__() if not self.__mask_exists__(): self.__generate__() self.__open_mask__() if not skippoly: from .gshhs import get_gshhs_f with get_gshhs_f() as fd: self.land = wkb.load(fd) if extent: self.extent = box(*extent) self.extent = shapely.prepared.prep(self.extent) # polygons self.land = MultiPolygon( [l for l in self.land.geoms if self.extent.intersects(l)]) self.polys = self.land self.land = shapely.prepared.prep(self.land)
def l(): with open(high, 'rb') as fd: land = wkb.load (fd) prep = shapely.prepared.prep(land)
from shapely.wkb import load, dump import shapely.geometry as geometry from shapely.ops import linemerge, unary_union, polygonize import cartopy.io.shapereader as shpreader api = overpy.Overpass() areas = { "Alaska": 1116270, } shapes = {} for area, id in areas.items(): # Load and cache all prerequested areas try: shapes[area] = load(open("{:s}.wkb".format(area), "rb")) except FileNotFoundError: print("Area {:s} not found in cache.".format(area)) query = """[out:json][timeout:25]; rel({:d}); out body; >; out skel qt; """.format(id) result = api.query(query) # Convert ways to linstrings lss = [] for ii_w, way in enumerate(result.ways): ls_coords = []