本文整理汇总了Python中mercantile.bounds方法的典型用法代码示例。如果您正苦于以下问题:Python mercantile.bounds方法的具体用法?Python mercantile.bounds怎么用?Python mercantile.bounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mercantile
的用法示例。
在下文中一共展示了mercantile.bounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pixel_to_location
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def pixel_to_location(tile, dx, dy):
"""Converts a pixel in a tile to a coordinate.
Args:
tile: the mercantile tile to calculate the location in.
dx: the relative x offset in range [0, 1].
dy: the relative y offset in range [0, 1].
Returns:
The coordinate for the pixel in the tile.
"""
assert 0 <= dx <= 1, "x offset is in [0, 1]"
assert 0 <= dy <= 1, "y offset is in [0, 1]"
west, south, east, north = mercantile.bounds(tile)
def lerp(a, b, c):
return a + c * (b - a)
lon = lerp(west, east, dx)
lat = lerp(south, north, dy)
return lon, lat
示例2: get_mvt
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def get_mvt(zoom,x,y):
try: # Sanitize the inputs
sani_zoom,sani_x,sani_y = float(zoom),float(x),float(y)
del zoom,x,y
except:
print('suspicious')
return 1
scale_denom = zoom_to_scale_denom(sani_zoom)
tilebounds = bounds(sani_zoom,sani_x,sani_y)
s,w,n,e = str(tilebounds['s']),str(tilebounds['w']),str(tilebounds['n']),str(tilebounds['e'])
final_query = "EXECUTE gettile(!bbox!, !scale_denominator!, !pixel_width!, !pixel_height!);"
sent_query = replace_tokens(final_query,s,w,n,e,scale_denom)
response = list(session.execute(sent_query))
print(sent_query)
layers = filter(None,list(itertools.chain.from_iterable(response)))
final_tile = b''
for layer in layers:
final_tile = final_tile + io.BytesIO(layer).getvalue()
return final_tile
示例3: test_resampling_returns_different_results
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def test_resampling_returns_different_results():
bounds = (
-8844681.416934313,
3757032.814272982,
-8766409.899970293,
3835304.331237001,
)
with rasterio.open(f"{LANDSAT_PATH}_B2.TIF") as src_dst:
arr, _ = reader.part(
src_dst, bounds, 16, 16, dst_crs=constants.WEB_MERCATOR_CRS
)
arr2, _ = reader.part(
src_dst,
bounds,
16,
16,
dst_crs=constants.WEB_MERCATOR_CRS,
resampling_method="bilinear",
)
assert not numpy.array_equal(arr, arr2)
示例4: test_tile_read_extmask
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def test_tile_read_extmask():
"""Read masked area."""
# non-boundless tile covering the masked part
mercator_tile = mercantile.Tile(x=876431, y=1603669, z=22)
bounds = mercantile.xy_bounds(mercator_tile)
with rasterio.Env(GDAL_DISABLE_READDIR_ON_OPEN="TRUE"):
with rasterio.open(S3_EXTMASK_PATH) as src_dst:
arr, mask = reader.part(src_dst, bounds, 256, 256)
assert arr.shape == (3, 256, 256)
assert mask.shape == (256, 256)
assert not mask.all()
# boundless tile covering the masked part
mercator_tile = mercantile.Tile(x=876431, y=1603668, z=22)
bounds = mercantile.xy_bounds(mercator_tile)
with rasterio.Env(GDAL_DISABLE_READDIR_ON_OPEN="EMPTY_DIR"):
with rasterio.open(S3_MASK_PATH) as src_dst:
arr, mask = reader.part(src_dst, bounds, 256, 256)
assert arr.shape == (3, 256, 256)
assert not mask.all()
示例5: test_tile_read_vrt_option
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def test_tile_read_vrt_option():
"""Should work as expected (read landsat band)."""
bounds = (
-8844681.416934313,
3757032.814272982,
-8766409.899970293,
3835304.331237001,
)
tilesize = 16
with rasterio.open(f"{LANDSAT_PATH}_B2.TIF") as src_dst:
arr, mask = reader.part(
src_dst,
bounds,
tilesize,
tilesize,
warp_vrt_option=dict(source_extra=10, num_threads=10),
)
assert arr.shape == (1, 16, 16)
assert mask.shape == (16, 16)
示例6: test_tile_exists_valid
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def test_tile_exists_valid():
"""Should work as expected (return true)."""
bounds = [-80, 34, -75, 40]
# Contains
assert utils.tile_exists(bounds, 7, 36, 50) # bounds contains tile bounds
assert utils.tile_exists(bounds, 3, 2, 3) # tile bounds contains bounds
# Intersects
assert utils.tile_exists(bounds, 7, 35, 50)
assert utils.tile_exists(bounds, 7, 37, 50)
assert utils.tile_exists(bounds, 7, 36, 51)
assert utils.tile_exists(bounds, 7, 37, 51)
assert utils.tile_exists(bounds, 7, 35, 51)
assert utils.tile_exists(bounds, 7, 35, 48)
assert utils.tile_exists(bounds, 7, 37, 48)
# Outside tiles
assert not utils.tile_exists(bounds, 7, 36, 40)
assert not utils.tile_exists(bounds, 7, 36, 60)
assert not utils.tile_exists(bounds, 7, 25, 50)
assert not utils.tile_exists(bounds, 7, 70, 50)
示例7: test_get_vrt_transform_valid
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def test_get_vrt_transform_valid():
"""Should return correct transform and size."""
bounds = (
-11663507.036777973,
4715018.0897710975,
-11663487.927520901,
4715037.199028169,
)
with rasterio.open(S3_PATH) as src:
vrt_transform, vrt_width, vrt_height = utils.get_vrt_transform(
src, bounds, 64, 64
)
assert vrt_transform[2] == -11663507.036777973
assert vrt_transform[5] == 4715037.199028169
assert vrt_width == 100
assert vrt_height == 100
vrt_transform, vrt_width, vrt_height = utils.get_vrt_transform(
src, bounds, 256, 256
)
assert vrt_transform[2] == -11663507.036777973
assert vrt_transform[5] == 4715037.199028169
assert vrt_width == 256
assert vrt_height == 256
示例8: test_get_vrt_transform_valid4326
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def test_get_vrt_transform_valid4326():
"""Should return correct transform and size."""
bounds = (
-104.77523803710938,
38.95353532141205,
-104.77455139160156,
38.954069293441066,
)
with rasterio.open(S3_PATH) as src:
vrt_transform, vrt_width, vrt_height = utils.get_vrt_transform(
src, bounds, 256, 256, dst_crs=constants.WGS84_CRS
)
assert vrt_transform[2] == -104.77523803710938
assert vrt_transform[5] == 38.954069293441066
assert vrt_width == 420
assert vrt_height == 327
示例9: test_aligned_with_internaltile
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def test_aligned_with_internaltile():
"""Check if COG is in WebMercator and aligned with internal tiles."""
bounds = mercantile.bounds(43, 25, 7)
with rasterio.open(COG_DST) as src_dst:
assert not utils._requested_tile_aligned_with_internal_tile(
src_dst, bounds, 256, 256
)
with rasterio.open(NOCOG) as src_dst:
assert not utils._requested_tile_aligned_with_internal_tile(
src_dst, bounds, 256, 256
)
bounds = mercantile.bounds(147, 182, 9)
with rasterio.open(COG_NOWEB) as src_dst:
assert not utils._requested_tile_aligned_with_internal_tile(
src_dst, bounds, 256, 256
)
with rasterio.open(COG_WEB_TILED) as src_dst:
assert utils._requested_tile_aligned_with_internal_tile(
src_dst, bounds, 256, 256
)
示例10: get_area_acres
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def get_area_acres(geometry):
""" Calculate area in acres for a GeoJSON geometry
:param geometry: A GeoJSON Polygon geometry
:returns: Area in acres
"""
shapely_geometry = shape(geometry)
geom_aea = transform(
partial(
pyproj.transform,
pyproj.Proj(init="EPSG:4326"),
pyproj.Proj(
proj="aea",
lat1=shapely_geometry.bounds[1],
lat2=shapely_geometry.bounds[3],
),
),
shapely_geometry,
)
return round(geom_aea.area / 4046.8564224)
示例11: histogram_match
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def histogram_match(self, use_bands, blm_source='browse', **kwargs):
''' Match the histogram to existing imagery '''
warnings.warn('Histogram matching has changed due to the Maps API deprecation, see https://github.com/DigitalGlobe/gbdxtools/issues/778')
assert has_rio, "To match image histograms please install rio_hist"
data = self._read(self[use_bands,...], **kwargs)
data = np.rollaxis(data.astype(np.float32), 0, 3)
if 0 in data:
data = np.ma.masked_values(data, 0)
bounds = self._reproject(box(*self.bounds), from_proj=self.proj, to_proj="EPSG:4326").bounds
ref = BrowseImage(self.cat_id, bbox=bounds).read()
out = np.dstack([rio_match(data[:,:,idx], ref[:,:,idx].astype(np.double)/255.0)
for idx in range(data.shape[-1])])
if 'stretch' in kwargs or 'gamma' in kwargs:
return self._histogram_stretch(out, **kwargs)
else:
return out
示例12: test_make_tiles_tile_bounds
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def test_make_tiles_tile_bounds(x, y):
'''
Test if children tiles from z10 are created correctly
'''
test_bounds = mercantile.bounds(x, y, 10)
test_bbox = list(mercantile.xy(test_bounds.west, test_bounds.south)) + list(mercantile.xy(test_bounds.east, test_bounds.north))
test_crs = 'epsg:3857'
test_minz = 10
test_maxz = 13
created_tiles_gen = _make_tiles(test_bbox, test_crs, test_minz, test_maxz)
assert isinstance(created_tiles_gen, types.GeneratorType)
created_tiles = list(created_tiles_gen)
assert len(created_tiles) == 85
示例13: create_pyramid_job
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def create_pyramid_job(x, y, min_zoom, max_zoom, bounds):
pyramid = {
'tile': {
'x': x,
'y': y,
'min_zoom': min_zoom,
'max_zoom': max_zoom
},
'bounds': {
'west': bounds.west,
'south': bounds.south,
'east': bounds.east,
'north': bounds.north
}
}
def payload_id():
hash_obj = json.dumps(pyramid, sort_keys=True).encode('utf-8')
return hashlib.sha1(hash_obj).hexdigest()
return {
'id': payload_id(),
'type': 'pyramid',
'pyramid': pyramid
}
示例14: pyramid_jobs
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def pyramid_jobs(x, y, z, job_zoom, max_zoom):
"""
Generate pyramid jobs for a given job_zoom level
starting at with the parent tile defined by x, y, z.
"""
if z == job_zoom:
bounds = mercantile.bounds(x, y, z)
yield create_pyramid_job(
x=x, y=y,
min_zoom=z, max_zoom=max_zoom,
bounds=bounds
)
return
tiles = all_descendant_tiles(x, y, z, job_zoom)
pyramid_zoom_level_tiles = (t for t in tiles if t.z == job_zoom)
for tile in pyramid_zoom_level_tiles:
bounds = mercantile.bounds(tile.x, tile.y, tile.z)
yield create_pyramid_job(tile.x, tile.y, min_zoom=tile.z,
max_zoom=max_zoom, bounds=bounds)
示例15: bounds
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import bounds [as 别名]
def bounds(zoom,x,y):
inProj = pyproj.Proj(init='epsg:4326')
outProj = pyproj.Proj(init='epsg:3857')
lnglatbbox = mercantile.bounds(x,y,zoom)
ws = (pyproj.transform(inProj,outProj,lnglatbbox[0],lnglatbbox[1]))
en = (pyproj.transform(inProj,outProj,lnglatbbox[2],lnglatbbox[3]))
return {'w':ws[0],'s':ws[1],'e':en[0],'n':en[1]}