コード例 #1
0
def test_howmany():
    w, s, e, n = (-106.6495132446289, 25.845197677612305, -93.50721740722656,
                  36.49387741088867)
    zoom = 7
    expected = 25
    got = ctx.howmany(w, s, e, n, zoom=zoom, verbose=False, ll=True)
    assert got == expected
コード例 #2
0
def good_zoom(gdf, low_tiles=1, high_tiles=3):
	"Find a good initial zoom level."
	crs = gdf.crs
	total_bounds = gdf.total_bounds
	if crs is None:
		raise ValueError
	from shapely.geometry import box
	mapping_area = gpd.GeoDataFrame(geometry=[box(*total_bounds)], crs=crs).to_crs(epsg=3857)
	xmin_, ymin_, xmax_, ymax_ = mapping_area.total_bounds  # w s e n
	zoom = 1
	low_zoom = 1
	tiles = {}
	tiles[zoom] = howmany = ctx.howmany(xmin_, ymin_, xmax_, ymax_, zoom, verbose=False)
	while howmany <= high_tiles:
		zoom += 1
		if howmany <= low_tiles:
			low_zoom += 1
		tiles[zoom] = howmany = ctx.howmany(xmin_, ymin_, xmax_, ymax_, zoom, verbose=False)
	return zoom - 1 + ((high_tiles - tiles[zoom - 1]) / (howmany - tiles[zoom - 1]))
コード例 #3
0
gdzh["geometry"].total_bounds
# 多个行政区域,多个多边形
gdzh = gpd.read_file("d:/temp/geojsonutf8/中华人民共和国/广东省/珠海市/440400_full.json",
                     encoding='utf-8')
gdzh = gdzh.to_crs(epsg=3857)
gdzh.plot(figsize=(16, 16))
plt.show()
# 多个行政区域多个多边形的情形,total_bounds对了,用total_bounds
gdzh["geometry"].bounds
gdzh["geometry"].total_bounds

we, se, ee, ne = gdzh["geometry"].total_bounds
# 计算视野需要的zoom参数 -6? 不对
zoom = ctx.tile._calculate_zoom(we, se, ee, ne)
# 计算要下载的瓦片数量,zoom=10:15,11:40, zoom = -6时只需1块 tile
_ = ctx.howmany(we, se, ee, ne, 11, ll=False)
# 下载瓦片图并画图,不接受负值的zoom,ll=True, 火星坐标等,ll=False, 墨卡托坐标,前面已转换成该坐标
# zoom=11是最合适的,就是上面ctx.add_basemap(ax,source=gaodeurl)自动选定的zoom
img, ext = ctx.bounds2img(we, se, ee, ne, 11, ll=False, source=gaodeurl)
fig, ax = plt.subplots(1, figsize=(16, 16))
plt.imshow(img, extent=ext)
# 另存成tif图像文件,程序挂起,?
_ = ctx.bounds2raster(we, se, ee, ne, 'zh.tif', ll=False)

# Orange Geo的离线地图,除美国外都是到省一级
gdf7 = gpd.read_file("D:/Anaconda3/Lib/site-packages/orangecontrib/geo/geojson/admin1-CHN.json",\
                     encoding='utf-8')
gdf7.plot(figsize=(16, 12))
plt.show()
# 美国的地图边界到郡一级
gdf8 = gpd.read_file("D:/Anaconda3/Lib/site-packages/orangecontrib/geo/geojson/admin2-USA.json",\