Converting degrees to other units of measurement - mysql

I am storing a point as latitude and longitude in a Mysql server. They are both float(10,6). Given a radius, say 100 yards or 100 meters, how can I calculate points around the center. I was thinking of using GIS but I heard it is incomplete or very limited in functionality.

1) Tranform the lat/lon to a cartesian based coordinate system of units meter,
the tranformed point is now at (x,y)
2) Use school mathemathics (polar coordinates) to calculate the points:
2a) create points on circle at (0,0) with polar coordinates (r* sin (phi), r* cos(phi)), r in meters, phi in radians
2b) add (x,y) to all that resulting points, to move the circle points from center (0,0) to (x,y)
3) tranform all points back to lat/lon

Related

Convert LatLng to (x, y) coordinates

I'm working on Google maps which will show multiple vehicles. I've two points(one point which will be the old position and other will be the present position) this positioning system will help write an equation of a line passing through these two points. Which might intersect with other line and inform me about the probability of collision.
But the problem is that I'm fetching the coordinates from the GPS module and it will give the location in Latitude and Longitude format.
I'll need x, y coordinates for this writing the equation of the line passing through them. I've already explored most of the method in different web pages, but the problem is that they will ask for some screen size(or map bounds) which are kind of not compatible with my type of method.
Questions: What is the method to convert Latitude and Longitude to (x, y) coordinates, just like if we see from the space and earth was flat and taking Gulf of Guinea (Lat: 0°, Lon: 0°) as the origin.
If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.
If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.
For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.
As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
1) (0.0km 0.0km)
2) (21.86km 11.1km)
X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km
Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km
If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.

Greater latitude and longitude values

I came across a dataset which has Latitude values in the range (0,181.763) i.e. minimum latitude is 0 degree and maximum latitude is 181.763 degree and Longitude values in the range (228.722,242.008) i.e. minimum latitude is 228.722 degree and maximum latitude is 242.008 degree. Is there some way by which I may confine the latitude and longitude's to correct boundaries?
well if they are spherical coordinates, long 181.763deg points in the same direction as -178.237deg or 361.763deg, depending on the conventions used
to transform latitude ranges of (228.722,242.008) to (-90,90) the transformation matrix to use is ((x-228.722)/0.073811)-90 for each point x. for example 229.3deg gives -82.169deg
it could be that you are using slightly scaled (elliptical) polar coordinates and you can transform them back by division...

Correctly draw on Google Maps a point which exceeds 90 degrees of latitude

I'm working on a simulator that plots the flight path of an aircraft on Google Maps.
The simulator is not aware that the latitude is only defined between -90 and +90 degrees and the longitude between -180 and +180 deg. As a result of this, the flight path may include points beyond the map boundaries. Exceeding in longitude is not an issue as it still plots correctly (a point at longitude x and x+360 is the same), but the latitude is a problem.
Is there any way of telling Google Maps to keep the points between the correct boundaries and plot them correctly?
Otherwise, do you have any ideas of where to find functions that do so?
Longitude, latitude and elevation are a bad coordinate system for a flight simulator, because the mapping presents singularities i.e. there are points infinitely close on the earth that have very different coordinates. For example where you're close to one of the poles longitude variation speed can become arbitrarily big compared to airplane speed. When standing exactly on the pole the longitude doesn't even make sense.
A better solution is to use an XYZ coordinate system for the simulator and only convert to longitude/latitude and elevation for plotting. If you can approximate the earth to a sphere for your use case the computation of this transformation is trivial... otherwise things can get much more complex depending on how accurate you want it to be.
That said it's still possible to give "a" meaning to a point with latitude slightly outside the range -90...90 by extending it over the pole...
if latitude < -90:
latitude = -180 - latitude
longitude = longitude + 180
if latitude > 90:
latitude = 180 - latitude
longitude = longitude + 180
but using this coordinate system for navigating is a very bad idea (the same point in space can have multiple triplets of coordinates).
If your simulator doesn't know that the maximum value for latitude is 90 degrees it is broken and needs to be fixed. Google Maps works correctly for valid/possible values of latitude and longitude.

Distance between two points. East-west + North-south

I need to calculate the distance between two points, but not in the regular way. I need to know 'the east to west distance' + 'the north to south distance'. I guess this is more simple then the regular 'as the crow flies' calculation but i still can't figure out how to do it.
I want to do this using a MySQL query and preferably have the result returned in km. One of the points will be a constant in the query and the other point is a point from the DB so something like SELECT abs(longitude-39.12345)...+abs(latitude... AS Distance FROM shops WHERE shopname='Bingo'.
Thanks in advance!
The north-to-south distance is proportional to the difference in the latitudes. It's about 1 nautical mile per minute of arc (the circumference of the earth is about 21600 nautical miles).
The east-to-west distance is proportional to the difference in the longitudes, but it also varies with the latitude (e.g. it's zero at the poles): I think it's proportional to the cosine of latitude.
Your answer depends on the accuracy required in your answer. If you don't need an answer more accurate than a spherical earth model, you can use a solution similar to the one given by Captain Tom. If you require more accuracy, you'll need to assume the earth is an oblate spheroid. See http://en.wikipedia.org/wiki/Vincenty%27s_formulae for a couple of solutions.
The east-west difference between two points at different latitudes is a distinct number in degrees of longitude, but converting this to miles is problematic because the miles per degree vary according to the latitude. For example, Los Angles and New York City are 44.3 degrees of longitude apart, but converting this to miles would result in a larger number at LA's latitude than at NYC's latitude, since latitude lines are longest at the equator and shrink to zero at the poles.
A reasonable convention would be to count the E-W distance as the average of the two distances calculated at the two latitudes.
You can determine the distance between any two geocode points using the Great-Circle Distance. Here is another decent article on the subject.
The following is an example in C# which shows how to do this:
var earth_radius = Constants.EarthRadius; // 6377.8 km
var dLat = ToRadians(fromLatitude - toLatitude);
var dLon = ToRadians(fromLongitude - toLongitude);
var a =
Math.Sin(dLat / 2) *
Math.Sin(dLat / 2) +
Math.Cos(ToRadians(fromLatitude)) *
Math.Cos(ToRadians(toLatitude)) *
Math.Sin(dLon / 2) *
Math.Sin(dLon / 2);
var c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a)));
var distanceInKilometers = earth_radius * c;
Use simple trig. The normal "as the crow flies" distance is the hypotenuse of the right triangle formed with the two points you have in mind at either ends of the hypotenuse.
Just look at this http://en.wikipedia.org/wiki/Hypotenuse and the solution should become clear.

Calculating geospatial distance with radians

I have a method in an API that takes a lat/long coordinate and will find other coordinates within a specified distance. That distance is in radians.
All the math I do these days deals with accounting or maybe x,y coordinates for laying out UI elements, so I appreciate some help validating these numbers.
Lets ignore people in buildings (altitude) and the fact that the planet isn't perfectly spherical. It is my understanding that the supplied method is doing the Haversine formula internally but that detail is isolated from me.
I am looking at the formula for radians:
θ = s /r, where θ is the subtended
angle in radians, s is arc length, and
r is radius
Given the convenient mean radius of the Earth of:
6371 km
(≈3,959 mi)
I have seen other places saying (6378km)
That means 1 radian on Earth is equal to 6371 km in arc length. That would mean the radian for finding coordinates 1 meter apart would be
( 1 / 6371 ) × 10-7
ie - 1.56961231 × 10-7.
Is that right? If not where is the above incorrect?
It's correct. Although I feel a little shame posting this as an answer :)