def match_class(df): shandong = df.to_crs(3857) box = gutil.shp2box(shandong, (3600, 2400), 0.15, 1) paper = gnp.frombox(*box, dtype=np.uint8) idx = gmt.build_index(glob('../data/class/*.tif')) gmt.match_idx(idx, paper, out='in', order=0) gio.write_tif(paper, '../data/result/shandong_class.tif')
def draw_class(): # ===== look up table ===== lut = np.array([[0 ,0 ,0 ], [168,168,0 ], [20 ,119,73 ], [169,208,95 ], [56 ,168,0 ], [126,206,244], [0 ,86 ,154], [112,168,0 ], [147,47 ,20 ], [202,202,202], [0 ,255,197], [255,255,255]], dtype=np.uint8) # ===== read shape file and make a paper ===== liaoning = gio.read_shp('../data/shape/shandong.shp') liaoning = liaoning.to_crs(3857) box = gutil.shp2box(liaoning, (3600, 2400), 0.15, 1) paper = gnp.frombox(*box, dtype=np.uint8) # ===== match the class tif into paper fs = glob('../data/class/*.tif') idx = gmt.build_index(fs) gmt.match_idx(idx, paper, out='in', order=0) msk = paper * 0 gdraw.draw_polygon(msk, liaoning, 255, 0) paper[msk==0] = 11 body = [('图例', 'simhei', 72), ('rect', 1, '农田'), ('rect', 2, '森林'), ('rect', 3, '草地'), ('rect', 4, '灌丛'), ('rect', 5, '湿地'), ('rect', 6, '水体'), ('rect', 7, '苔原'), ('rect', 8, '隔水层'), ('rect', 9, '裸地'), ('rect', 10, '冰雪')] # 底图,位置,内容,空隙,矩形尺寸及线宽,字体字号颜色,外边框宽度 gdraw.draw_style(paper, 60, -60, body, mar=(20, 30), recsize=(120,60,0), font=('simsun', 60, 0), color=0, box=0) gdraw.draw_unit(paper, -120, -60, 0.3, 30, ('times', 48), 0, 'km', 3, anc='r') gdraw.draw_text(paper, '山东省土地利用类型', 80, 60, 0, ('simkai', 128)) gdraw.draw_N(paper, -240, 240, ('simhei', 100), 2, 100, 0) gdraw.draw_polygon(paper, liaoning, 0, 2) gdraw.draw_bound(paper, 5, 5, -5, -5, 0, 2, clear=None) return paper.lookup(lut)
def match_idx_test(): shandong = gio.read_shp('../data/shape/shandong.shp') shandong = shandong.to_crs(3857) info = gutil.shp2box(shandong, (2048, 768 * 2), 0.05) fs = glob('../data/modis/*.hdf') idx = gmt.build_index(fs) rst = gmt.match_idx(idx, info, chan=[0]) plt.imshow(rst) plt.show()
def match_idx_test(): shandong = gio.read_shp('../data/shape/shandong.shp') shandong = shandong.to_crs(3857) info = gutil.shp2box(shandong, (2048, 768 * 2), 0.05, 1) paper = gnp.frombox(*info, dtype=np.int16) fs = glob('../data/modis/*.hdf') idx = gmt.build_index(fs) gmt.match_idx(idx, paper, out='in', chan=[0]) plt.imshow(paper) plt.show()
def run(self, ips, imgs, para=None): prj = None if para['wkt'] != '': with open(para['wkt']) as f: prj = f.read() crs = gutil.makecrs(prj or para['crs']) table = gmt.build_index(imgs).to_crs(crs) box = gutil.shp2box(table, para['scale'] or (para['width'], para['height']), para['mar']) chans = ['Channel %s' % i for i in range(ips.get_nchannels())] chans = [chans.index(i) for i in para['chans']] order = {'nearest': 0, 'linear': 1}[para['order']] rst = gmt.match_multi(imgs, box, chans, step=para['step'], order=order) IPy.show_img([rst], ips.title + '-merge')
'https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}', 'gaode': 'https://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}', 'google': 'http://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}' } def download_online_tiles(tiles, path, src='gaode'): for i, g, x, y, z in tiles[['geometry', 'x', 'y', 'z']].to_records(): img = imread(urls[src].format(x=x, y=y, z=z)) img = build_geo_tif(img, 3857, g.bounds) gio.write_tif(img, '%s/%ld_%d_%d.tif' % (path, z, y, x)) if __name__ == '__main__': import geonumpy.draw as gdraw import geonumpy.match as gmt import geonumpy.io as gio from glob import glob box = gio.read_tif_box('./3.背景TIF.tif') buf = gnp.frombox(*box[:3], 3) tiles = build_online_tiles(level=7, box=box[:3]) download_online_tiles(tiles, './tiles', 'gaode') idx = gmt.build_index(glob('./tiles/*.tif')) rst = gmt.match_idx(idx, box[:3]) gio.write_tif(rst, 'b.tif')
def run(self, para=None): p, f = osp.split(para['path']) name, ext = osp.splitext(f) s = p + '/*' + ext gdf = gmt.build_index(glob(s)) IPy.show_table(gdf, '%s-idx' % name)
def build_idx_test(): fs = glob('../data/modis/*.hdf') idx = gmt.build_index(fs) idx.plot() plt.show()