C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

PHP Library: Calculate a bounding box for a given lat/lng location

Share :

How to calculate the bounding box for a given lat/lng location?

Tag : development , By : Jonathan Bernard
Date : March 29 2020, 07:55 AM
Hope that helps I suggest to approximate locally the Earth surface as a sphere with radius given by the WGS84 ellipsoid at the given latitude. I suspect that the exact computation of latMin and latMax would require elliptic functions and would not yield an appreciable increase in accuracy (WGS84 is itself an approximation).
My implementation follows (It's written in Python; I have not tested it):
``````# degrees to radians
return math.pi*degrees/180.0

# 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]
An = WGS84_a*WGS84_a * math.cos(lat)
Bn = WGS84_b*WGS84_b * math.sin(lat)
Bd = WGS84_b * math.sin(lat)

# 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):
halfSide = 1000*halfSideInKm

# Radius of Earth at given latitude
# Radius of the parallel at given latitude

``````
``````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))
``````

Calculate bounding box for OpenStreetMap

Tag : development , By : user119413
Date : March 29 2020, 07:55 AM
wish of those help Yes, it is. I've had a similar problem, so I've written it up. Like this:
``````use Math::Trig;

sub getTileNumber {
my (\$lat,\$lon,\$zoom) = @_;
my \$xtile = int( (\$lon+180)/360 * 2**\$zoom ) ;
my \$ytile = int( (1 - log(tan(deg2rad(\$lat)) + sec(deg2rad(\$lat)))/pi)/2 * 2**\$zoom ) ;
return (\$xtile, \$ytile);
}

sub getLonLat {
my (\$xtile, \$ytile, \$zoom) = @_;
my \$n = 2 ** \$zoom;
my \$lon_deg = \$xtile / \$n * 360.0 - 180.0;
my \$lat_deg = rad2deg(atan(sinh(pi * (1 - 2 * \$ytile / \$n))));
return (\$lon_deg, \$lat_deg);
}

# convert from permalink OSM format like:
# http://www.openstreetmap.org/?lat=43.731049999999996&lon=15.79375&zoom=13&layers=M
# to OSM "Export" iframe embedded bbox format like:
# http://www.openstreetmap.org/export/embed.html?bbox=15.7444,43.708,15.8431,43.7541&layer=mapnik

sub LonLat_to_bbox {
my (\$lat, \$lon, \$zoom) = @_;

my \$width = 425; my \$height = 350;  # note: must modify this to match your embed map width/height in pixels
my \$tile_size = 256;

my (\$xtile, \$ytile) = getTileNumber (\$lat, \$lon, \$zoom);

my \$xtile_s = (\$xtile * \$tile_size - \$width/2) / \$tile_size;
my \$ytile_s = (\$ytile * \$tile_size - \$height/2) / \$tile_size;
my \$xtile_e = (\$xtile * \$tile_size + \$width/2) / \$tile_size;
my \$ytile_e = (\$ytile * \$tile_size + \$height/2) / \$tile_size;

my (\$lon_s, \$lat_s) = getLonLat(\$xtile_s, \$ytile_s, \$zoom);
my (\$lon_e, \$lat_e) = getLonLat(\$xtile_e, \$ytile_e, \$zoom);

my \$bbox = "\$lon_s,\$lat_s,\$lon_e,\$lat_e";
return \$bbox;
}
``````

How do I calculate a bounding polygon?

Tag : development , By : Navin
Date : March 29 2020, 07:55 AM
may help you . You're probably looking for the convex hull and for convex hull algorithms.
One of the simplest 2D algorithms is the Gift wrapping algorithm. To quote Wikipedia:

How to calculate bounding box area?

Tag : matlab , By : Guyou
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The first two are the left most x and y coordinates respectively. The next two values are the lengths in the x and y direction respectively (starting from the x and y coordinates). So for area you need to multiply the last two values (e.g., 287*165). For more information see the documentation for regionprops('BoundingBox').

How to calculate the center of the bounding box?

Tag : python , By : dantino
Date : March 29 2020, 07:55 AM