Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lat/Lon with buffer
//Calculate a buffer for Lat/Lon bounds, so all points with a //distance to the bounds are contained in these bounds. using System; namespace Rextester { public class Program { public static void Main(string[] args) { // our latitude/longitude values for test var g1 = new Point(8, 49); var g2 = new Point(9, 50); // 100 km double buffer = 100000; // convert to Mercator (conformal) double x1, y1, x2, y2; var m1 = Wgs_2_SphereMercator(g1); var m2 = Wgs_2_SphereMercator(g2); // The maxmimum absolute latitude will be used for ground resolution double maxLat = Math.Max(Math.Abs(g1.Y), Math.Abs(g2.Y)); // calculate the ground resoutlion for the latitude double groundResolution = Math.Cos(maxLat * Math.PI / 180.0); // the ground resolution applied to the buffer var mercatorBuffer = buffer / groundResolution; // now add the mercator buffer var mb1 = new Point(m1.X - mercatorBuffer, m1.Y - mercatorBuffer); var mb2 = new Point(m2.X + mercatorBuffer, m2.Y + mercatorBuffer); // back to geo var gb1 = SphereMercator_2_Wgs(mb1); var gb2 = SphereMercator_2_Wgs(mb2); Console.WriteLine("Calculate a buffer for Lat/Lon bounds"); Console.WriteLine("Bounds : (lat: {1}, lon: {0}) / (lat: {3}, lon: {2})", g1.X, g1.Y, g2.X, g2.Y); Console.WriteLine("Buffer : {0}m", buffer); Console.WriteLine("With Buffer: (lat: {1}, lon: {0}) / (lat: {3}, lon: {2})", gb1.X, gb1.Y, gb2.X, gb2.Y); } public static Point Wgs_2_SphereMercator(Point point, double earthRadius = 6371000) { double x = earthRadius * point.X * Math.PI / 180.0; double y = earthRadius * Math.Log(Math.Tan(Math.PI / 4.0 + point.Y * Math.PI / 360.0)); return new Point(x, y); } public static Point SphereMercator_2_Wgs(Point point, double earthRadius = 6371000) { double x = (180.0/Math.PI)*(point.X/earthRadius); double y = (360/Math.PI)*(Math.Atan(Math.Exp(point.Y/earthRadius)) - (Math.PI/4)); return new Point(x, y); } } public class Point { public Point(double x, double y) { this.X = x; this.Y = y; } public double X { get; set; } public double Y { get; set; } } }
run
|
edit
|
history
|
help
0
Testing 002
Linq - When using FirstOrDefault, make sure to check for null result
ingresar datos por teclado
towers of hanoi
Stuff
ElaineBrown
Gerador de Matriz Data
Date Example
okok2
Main3-2