[英]Calculate SW & NE Lat/Longs of Square X miles from a Centre Lat/Long
I am working on getting data out of the Noaa API. 我正在努力从Noaa API中获取数据。
When talking to the Noaa API you can get a list of weather stations within a square. 与Noaa API通话时,您可以获得一个正方形内的气象站列表。 They call them "extents" and they are a 2 sets of lat/longs.
他们称它们为“范围”,它们是2套经纬度。 The bottom left lat/long and the top right lat/long
左下纬度/经度和右上纬度/经度
As detailed here: 如此处详细说明:
http://www.ncdc.noaa.gov/cdo-web/webservices/v2#stations http://www.ncdc.noaa.gov/cdo-web/webservices/v2#stations
I have been given a list of lat/longs for a number of cities in the US and I am trying to work out the best way of putting a box around. 我得到了美国多个城市的经/纬度清单,我正在设法找到最好的放置箱子的方法。
So, my first guess would be to take the central lat/long, work out the lat/long 75 miles to the West, then work out the lat/long of the point 75 miles South of that point. 因此,我的第一个猜测是乘以中心纬度/经度,算出向西75英里的纬度/经度,然后算出该点以南75英里处的纬度/经度。
Ideally I would like to have this as ac# function. 理想情况下,我希望将此作为ac#函数。
Has anyone got any ideas on the best way to code this please? 请问有人对最佳编码方式有任何想法吗?
Thanks 谢谢
Yippee! yippee的! - found the solution...
-找到了解决方案...
First a simple class: 首先是一个简单的类:
public class LatLonAlt
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public double Altitude { get; set; }
}
Then a function to calculate a new position: 然后是一个计算新头寸的函数:
public static HelpersModel.LatLonAlt CalculateDerivedPosition(HelpersModel.LatLonAlt source, double range, double bearing)
{
double latA = Convert.ToDouble(source.Latitude) * (Math.PI / 180);
double lonA = Convert.ToDouble(source.Longitude) * (Math.PI / 180);
double angularDistance = range / 6371;
double trueCourse = bearing * (Math.PI / 180);
double lat = Math.Asin(
Math.Sin(latA) * Math.Cos(angularDistance) +
Math.Cos(latA) * Math.Sin(angularDistance) * Math.Cos(trueCourse));
double dlon = Math.Atan2(
Math.Sin(trueCourse) * Math.Sin(angularDistance) * Math.Cos(latA),
Math.Cos(angularDistance) - Math.Sin(latA) * Math.Sin(lat));
double lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI;
HelpersModel.LatLonAlt results = new HelpersModel.LatLonAlt();
results.Latitude = lat * (180 / Math.PI);
results.Longitude = lon * (180 / Math.PI);
results.Altitude = source.Altitude;
return results;
}
Then, and I know I can do this better.. but it works for now... 然后,我知道我可以做得更好..但是它现在可以使用...
2 functions that work out the bottmleft and topright extent: 2个计算出bottmleft和topright范围的函数:
public static HelpersModel.LatLonAlt FindBottomLeftExtent(HelpersModel.LatLonAlt startpoint)
{
// first move left
HelpersModel.LatLonAlt movedleft = CalculateDerivedPosition(startpoint, 72.42, 270);
// move down
HelpersModel.LatLonAlt moveddown = CalculateDerivedPosition(movedleft, 72.42, 180);
return moveddown;
}
public static HelpersModel.LatLonAlt FindTopRightExtent(HelpersModel.LatLonAlt startpoint)
{
// first move right
HelpersModel.LatLonAlt movedright = CalculateDerivedPosition(startpoint, 72.42, 90);
// move up
HelpersModel.LatLonAlt movedup = CalculateDerivedPosition(movedright, 72.42, 0);
return movedup;
}
HTH! HTH!
Trev 崔佛
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.