Mic*_*hal 98 geocoding panoramio
我给出了一个由纬度和经度定义的位置.现在我想计算一个距离该点10公里的边界框.
边界框应定义为latmin,lngmin和latmax,lngmax.
我需要这些东西才能使用panoramio API.
有人知道如何获得积分的公式吗?
编辑:伙计们我正在寻找一个公式/函数,它以lat&lng作为输入并返回一个边界框作为latmin&lngmin和latmax&latmin.Mysql,php,c#,javascript很好,但伪代码也应该没问题.
编辑:我不是在寻找能够显示2点距离的解决方案
Fed*_*oni 57
我建议将地球表面局部近似为一个球体,其半径由给定纬度的WGS84椭球给出.我怀疑latMin和latMax的精确计算需要椭圆函数,并且不会产生明显的精度增加(WGS84本身就是近似值).
我的实现如下(它是用Python编写的;我还没有测试过):
# degrees to radians
def deg2rad(degrees):
return math.pi*degrees/180.0
# radians to degrees
def rad2deg(radians):
return 180.0*radians/math.pi
# Semi-axes of WGS-84 geoidal reference
WGS84_a = 6378137.0 # Major semiaxis [m]
WGS84_b = 6356752.3 # Minor semiaxis [m]
# Earth radius at a given latitude, according to the WGS-84 ellipsoid [m]
def WGS84EarthRadius(lat):
# http://en.wikipedia.org/wiki/Earth_radius
An = WGS84_a*WGS84_a * math.cos(lat)
Bn = WGS84_b*WGS84_b * math.sin(lat)
Ad = WGS84_a * math.cos(lat)
Bd = WGS84_b * math.sin(lat)
return math.sqrt( (An*An + Bn*Bn)/(Ad*Ad + Bd*Bd) )
# Bounding box surrounding the point at given coordinates,
# assuming local approximation of Earth surface as a sphere
# of radius given by WGS84
def boundingBox(latitudeInDegrees, longitudeInDegrees, halfSideInKm):
lat = deg2rad(latitudeInDegrees)
lon = deg2rad(longitudeInDegrees)
halfSide = 1000*halfSideInKm
# Radius of Earth at given latitude
radius = WGS84EarthRadius(lat)
# Radius of the parallel at given latitude
pradius = radius*math.cos(lat)
latMin = lat - halfSide/radius
latMax = lat + halfSide/radius
lonMin = lon - halfSide/pradius
lonMax = lon + halfSide/pradius
return (rad2deg(latMin), rad2deg(lonMin), rad2deg(latMax), rad2deg(lonMax))
Run Code Online (Sandbox Code Playgroud)
编辑:以下代码将(度,素数,秒)转换为度数+度数的分数,反之亦然(未经测试):
def dps2deg(degrees, primes, seconds):
return degrees + primes/60.0 + seconds/3600.0
def deg2dps(degrees):
intdeg = math.floor(degrees)
primes = (degrees - intdeg)*60.0
intpri = math.floor(primes)
seconds = (primes - intpri)*60.0
intsec = round(seconds)
return (int(intdeg), int(intpri), int(intsec))
Run Code Online (Sandbox Code Playgroud)
小智 52
我写了一篇关于找到边界坐标的文章:
http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates
本文解释了这些公式,并提供了Java实现.(这也说明了为什么费德里科的最小/最大经度公式不准确.)
Ε Г*_*И О 31
在这里,我已经将Federico A. Ramponi对C#的回答转换为任何感兴趣的人:
public class MapPoint
{
public double Longitude { get; set; } // In Degrees
public double Latitude { get; set; } // In Degrees
}
public class BoundingBox
{
public MapPoint MinPoint { get; set; }
public MapPoint MaxPoint { get; set; }
}
// Semi-axes of WGS-84 geoidal reference
private const double WGS84_a = 6378137.0; // Major semiaxis [m]
private const double WGS84_b = 6356752.3; // Minor semiaxis [m]
// 'halfSideInKm' is the half length of the bounding box you want in kilometers.
public static BoundingBox GetBoundingBox(MapPoint point, double halfSideInKm)
{
// Bounding box surrounding the point at given coordinates,
// assuming local approximation of Earth surface as a sphere
// of radius given by WGS84
var lat = Deg2rad(point.Latitude);
var lon = Deg2rad(point.Longitude);
var halfSide = 1000 * halfSideInKm;
// Radius of Earth at given latitude
var radius = WGS84EarthRadius(lat);
// Radius of the parallel at given latitude
var pradius = radius * Math.Cos(lat);
var latMin = lat - halfSide / radius;
var latMax = lat + halfSide / radius;
var lonMin = lon - halfSide / pradius;
var lonMax = lon + halfSide / pradius;
return new BoundingBox {
MinPoint = new MapPoint { Latitude = Rad2deg(latMin), Longitude = Rad2deg(lonMin) },
MaxPoint = new MapPoint { Latitude = Rad2deg(latMax), Longitude = Rad2deg(lonMax) }
};
}
// degrees to radians
private static double Deg2rad(double degrees)
{
return Math.PI * degrees / 180.0;
}
// radians to degrees
private static double Rad2deg(double radians)
{
return 180.0 * radians / Math.PI;
}
// Earth radius at a given latitude, according to the WGS-84 ellipsoid [m]
private static double WGS84EarthRadius(double lat)
{
// http://en.wikipedia.org/wiki/Earth_radius
var An = WGS84_a * WGS84_a * Math.Cos(lat);
var Bn = WGS84_b * WGS84_b * Math.Sin(lat);
var Ad = WGS84_a * Math.Cos(lat);
var Bd = WGS84_b * Math.Sin(lat);
return Math.Sqrt((An*An + Bn*Bn) / (Ad*Ad + Bd*Bd));
}
Run Code Online (Sandbox Code Playgroud)
小智 9
我编写了一个JavaScript函数,它返回一个方形边界框的四个坐标,给定一个距离和一对坐标:
'use strict';
/**
* @param {number} distance - distance (km) from the point represented by centerPoint
* @param {array} centerPoint - two-dimensional array containing center coords [latitude, longitude]
* @description
* Computes the bounding coordinates of all points on the surface of a sphere
* that has a great circle distance to the point represented by the centerPoint
* argument that is less or equal to the distance argument.
* Technique from: Jan Matuschek <http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates>
* @author Alex Salisbury
*/
getBoundingBox = function (centerPoint, distance) {
var MIN_LAT, MAX_LAT, MIN_LON, MAX_LON, R, radDist, degLat, degLon, radLat, radLon, minLat, maxLat, minLon, maxLon, deltaLon;
if (distance < 0) {
return 'Illegal arguments';
}
// helper functions (degrees<–>radians)
Number.prototype.degToRad = function () {
return this * (Math.PI / 180);
};
Number.prototype.radToDeg = function () {
return (180 * this) / Math.PI;
};
// coordinate limits
MIN_LAT = (-90).degToRad();
MAX_LAT = (90).degToRad();
MIN_LON = (-180).degToRad();
MAX_LON = (180).degToRad();
// Earth's radius (km)
R = 6378.1;
// angular distance in radians on a great circle
radDist = distance / R;
// center point coordinates (deg)
degLat = centerPoint[0];
degLon = centerPoint[1];
// center point coordinates (rad)
radLat = degLat.degToRad();
radLon = degLon.degToRad();
// minimum and maximum latitudes for given distance
minLat = radLat - radDist;
maxLat = radLat + radDist;
// minimum and maximum longitudes for given distance
minLon = void 0;
maxLon = void 0;
// define deltaLon to help determine min and max longitudes
deltaLon = Math.asin(Math.sin(radDist) / Math.cos(radLat));
if (minLat > MIN_LAT && maxLat < MAX_LAT) {
minLon = radLon - deltaLon;
maxLon = radLon + deltaLon;
if (minLon < MIN_LON) {
minLon = minLon + 2 * Math.PI;
}
if (maxLon > MAX_LON) {
maxLon = maxLon - 2 * Math.PI;
}
}
// a pole is within the given distance
else {
minLat = Math.max(minLat, MIN_LAT);
maxLat = Math.min(maxLat, MAX_LAT);
minLon = MIN_LON;
maxLon = MAX_LON;
}
return [
minLon.radToDeg(),
minLat.radToDeg(),
maxLon.radToDeg(),
maxLat.radToDeg()
];
};
Run Code Online (Sandbox Code Playgroud)
这是一个使用 javascript 的简单实现,它基于纬度到 kms where 的转换1 degree latitude ~ 111.2 km。
我正在根据给定的纬度、经度和半径(以公里为单位)计算地图的边界。
function getBoundsFromLatLng(lat, lng, radiusInKm){
var lat_change = radiusInKm/111.2;
var lon_change = Math.abs(Math.cos(lat*(Math.PI/180)));
var bounds = {
lat_min : lat - lat_change,
lon_min : lng - lon_change,
lat_max : lat + lat_change,
lon_max : lng + lon_change
};
return bounds;
}
Run Code Online (Sandbox Code Playgroud)
@Jan Philip Matuschek 的插图很好的解释。(请对他的答案投赞成票,而不是这个;我添加这个是因为我花了一点时间来理解原始答案)
寻找最近邻的优化边界框技术需要为距离 d 处的点 P 导出最小和最大纬度、经度对。所有落在这些点之外的点与该点的距离肯定大于 d。这里需要注意的一件事是交叉点纬度的计算,正如 Jan Philip Matuschek 解释中强调的那样。交点的纬度不在P点的纬度上,而是稍微偏离了点。在确定距离 d 的点 P 的正确最小和最大边界经度时,这是一个经常被遗漏但很重要的部分。这在验证中也很有用。
P的(交点纬度,经度高)到(纬度,经度)之间的半正弦距离等于距离d。
Python 要点https://gist.github.com/alexcpn/f95ae83a7ee0293a5225
我改编了一个我发现的 PHP 脚本来做到这一点。您可以使用它来找到一个点(例如,20 公里外)周围的框的角。我的具体示例适用于 Google Maps API:
小智 5
由于我需要非常粗略的估计,所以为了在弹性搜索查询中过滤掉一些不必要的文档,我采用了以下公式:
Min.lat = Given.Lat - (0.009 x N)
Max.lat = Given.Lat + (0.009 x N)
Min.lon = Given.lon - (0.009 x N)
Max.lon = Given.lon + (0.009 x N)
Run Code Online (Sandbox Code Playgroud)
从给定位置需要N = kms.对于你的情况N = 10
不准确但方便.
| 归档时间: |
|
| 查看次数: |
101711 次 |
| 最近记录: |