Created
November 19, 2019 06:01
-
-
Save Nukem9/6256f58c632298b5d3c1c58e9776e694 to your computer and use it in GitHub Desktop.
C# code to download & stitch together the Submarine Cable Map 2019 from Telegeography
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Drawing; | |
using System.Net; | |
namespace ImageBuilder | |
{ | |
class Program | |
{ | |
static Image[,] m_Images; | |
static void Main(string[] args) | |
{ | |
// High resolution: 6 | |
// Rows: 64 | |
// Columns: 64 | |
m_Images = new Image[64, 64]; | |
for (int i = 0; i < m_Images.GetLength(0); i++) | |
{ | |
for (int j = 0; j < m_Images.GetLength(1); j++) | |
{ | |
//DownloadImage(6, i, j); | |
m_Images[i, j] = LoadImage(6, i, j); | |
} | |
} | |
// | |
// Calculate the maximum size | |
// | |
int totalWidth = 0; | |
int totalHeight = 0; | |
for (int i = 0; i < m_Images.GetLength(0); i++) | |
totalHeight += m_Images[i, 0].Height; | |
for (int i = 0; i < m_Images.GetLength(1); i++) | |
totalWidth += m_Images[0, i].Width; | |
// | |
// Now create the final bitmap | |
// | |
Bitmap finalImg = new Bitmap(totalWidth, totalHeight); | |
finalImg.SetResolution(m_Images[0, 0].HorizontalResolution, m_Images[0, 0].VerticalResolution); | |
Graphics draw = Graphics.FromImage(finalImg); | |
draw.Clear(Color.Black); | |
int h = 0; | |
int w = 0; | |
for (int i = 0; i < m_Images.GetLength(0); i++) | |
{ | |
w = 0; | |
for (int j = 0; j < m_Images.GetLength(1); j++) | |
{ | |
draw.DrawImage(m_Images[i, j], w, h); | |
w += m_Images[i, j].Width; | |
} | |
h += m_Images[i, 0].Height; | |
} | |
finalImg.Save("out.png", System.Drawing.Imaging.ImageFormat.Png); | |
} | |
static bool DownloadImage(int Resoltion, int Row, int Col) | |
{ | |
string localFilename = String.Format("{0}_{1}_{2}.png", Resoltion, Col, Row); | |
string remoteFilename = String.Format("https://tiles.telegeography.com/maps/submarine-cable-map-2019/{0}/{1}/{2}.png8", Resoltion, Col, Row); | |
try | |
{ | |
using (WebClient client = new WebClient()) | |
{ | |
client.DownloadFile(remoteFilename, localFilename); | |
} | |
} | |
catch (Exception) | |
{ | |
return false; | |
} | |
return true; | |
} | |
static Image LoadImage(int Resoltion, int Row, int Col) | |
{ | |
string localFilename = String.Format(Environment.CurrentDirectory + @"\{0}_{1}_{2}.png", Resoltion, Col, Row); | |
return Image.FromFile(localFilename); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment