Last active
December 15, 2015 20:59
-
-
Save attrition/5322320 to your computer and use it in GitHub Desktop.
Read in ascii topology data and extract a square chunk centred around a given latitude and longitude (code provides ottawa and montreal targets). Expects 30 arc-second map of canada.
This file contains 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.IO; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Windows.Forms; | |
namespace AscMapSubset | |
{ | |
static class Program | |
{ | |
/// <summary> | |
/// The main entry point for the application. | |
/// </summary> | |
[STAThread] | |
static void Main() | |
{ | |
Application.EnableVisualStyles(); | |
Application.SetCompatibleTextRenderingDefault(false); | |
var canLat = 41.004166667f; | |
var canLon = -147.995833333f; | |
var cellSize = 0.008333333f; | |
// montreal | |
var monLat = 45.4987368f; | |
var monLon = -73.5907014f; | |
// ottawa | |
var ottLat = 45.4240305f; | |
var ottLon = -75.6954888f; | |
var area = new List<List<string>>(); | |
var areaRadius = 5; | |
var y = (int)Math.Round(Math.Abs(monLat - canLat) / cellSize); | |
var x = (int)Math.Round(Math.Abs(monLon - canLon) / cellSize); | |
var height = 5040; | |
var startX = x - areaRadius; | |
var startY = height - (y - areaRadius); | |
var endX = x + areaRadius; | |
var endY = height - (y + areaRadius); | |
var lines = File.ReadAllLines(@"can3d30.asc") | |
.Where((line, lineNum) => lineNum > 5) | |
.ToList(); | |
for (int i = startY; i >= endY; i--) | |
{ | |
var line = lines[i]; | |
var cols = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); | |
area.Add(cols.Where((col, idx) => idx >= startX && idx <= endX).ToList()); | |
} | |
var output = new List<string>(); | |
var currLine = area.Count - 1; | |
for (int lonStep = startX; lonStep <= endX; lonStep++) | |
{ | |
var col = 0; | |
for (int latStep = startY; latStep >= endY; latStep--) | |
{ | |
var currLat = canLat + ((height - latStep) * cellSize); | |
var currLon = canLon + (lonStep * cellSize); | |
output.Add(currLat + " " + currLon + " " + area[currLine][col]); | |
col++; | |
} | |
currLine--; | |
} | |
File.WriteAllLines(@"output.asc", output); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected 30 arc-send map of Canada provided here: can3d30