Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // for LINQPad 5
- var http = new HttpClient();
- var tile_start = new int[]{1819-2,806-3};
- var tile_range = 10;
- var tile_zoom = 11;
- var bmp = new Bitmap(tile_range*256,tile_range*256);
- for(var pixel_x = 0;pixel_x < tile_range*256;pixel_x++) {
- for(var pixel_y = 0;pixel_y < tile_range*256;pixel_y++) {
- bmp.SetPixel(pixel_x,pixel_y,Color.Black);
- }
- }
- for(var count_x = 0; count_x < tile_range;count_x++) {
- for(var count_y = 0; count_y < tile_range;count_y++) {
- try{
- var tile_x = tile_start[0]+count_x;
- var tile_y = tile_start[1]+count_y;
- var url = $@"https://cyberjapandata.gsi.go.jp/xyz/dem_png/{tile_zoom}/{tile_x}/{tile_y}.png";
- var stream = await http.GetStreamAsync(url);
- var src_bmp = new Bitmap(stream);
- for(var pixel_x = 0;pixel_x < 256;pixel_x++) {
- for(var pixel_y = 0;pixel_y < 256;pixel_y++) {
- var h = ToHeight(src_bmp.GetPixel(pixel_x,pixel_y));
- bmp.SetPixel(pixel_x + count_x * 256,pixel_y + count_y * 256,ToColor(h));
- }
- }
- }catch{}
- }
- }
- for(var count_x = 0; count_x < tile_range;count_x++) {
- for(var count_y = 0; count_y < tile_range;count_y++) {
- try{
- var tile_x = tile_start[0]+count_x;
- var tile_y = tile_start[1]+count_y;
- var url = $@"https://cyberjapandata.gsi.go.jp/xyz/lcm25k_2012/{tile_zoom}/{tile_x}/{tile_y}.png";
- var stream = await http.GetStreamAsync(url);
- var src_bmp = new Bitmap(stream);
- for(var pixel_x = 0;pixel_x < 256;pixel_x++) {
- for(var pixel_y = 0;pixel_y < 256;pixel_y++) {
- var color = src_bmp.GetPixel(pixel_x,pixel_y);
- if(color.R == 101 && color.G == 202 && color.B >= 250) {
- bmp.SetPixel(pixel_x + count_x * 256,pixel_y + count_y * 256,Color.Black);
- }
- }
- }
- }catch{}
- }
- }
- bmp.Dump();
- Color ToColor(double height) {
- var min = -40.0;
- var max = 300;
- if(height > max/2) height = max/4 + height/2;
- var value =
- (height - min) / (max - min) * 255;
- if(height < 1) value = 0;
- value = Math.Max(0,Math.Min(255,value));
- return Color.FromArgb((int)value,(int)value,(int)value);
- }
- double ToHeight(Color color) {
- var pow2_8 = 256;
- var pow2_16 = 65536;
- var pow2_23 = 8388608;
- var pow2_24 = 16777216;
- var r = color.R;
- var g = color.G;
- var b = color.B;
- var h = 0.0;
- if (r != 128 || g != 0 || b != 0) {
- var d = r * pow2_16 + g * pow2_8 + b;
- h = (d < pow2_23) ? d : d - pow2_24;
- if (h == -pow2_23) h = 0;
- else h *= 0.01;
- return h;
- }
- return -9999;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement