Finding the translation between points - language-agnostic

I have a map of the US, and I've got a lot of pixel coordinates on that map which correspond to places of interest. These are dynamically drawn on the map at runtime according to various settings and statistics.
I now need to switch over to a different map of the US which is differently sized, and the top left corner of the map is in a slightly place in the ocean.
So I've manually collected a small set of coordinates for each map that correspond to one another. For example, the point (244,312) on the first map corresponds to the point (598,624) on the second map, and (1323,374) on the first map corresponds to (2793,545) on the second map, etc.
So I'm trying to decide the translation for the X and Y dimensions. So given a set of points for the old and new maps, how do I find the x' = A*x + C and y' = B*x + D equations to automatically translate any point from the old map to the new one?

You have the coordinates of two points on both maps, (x1,y1), (x'1, y'1), (x2, y2) and (x'2, y'2).
A = (x'1 - x'2)/(x1 - x2)
B = (y'1 - y'2)/(y1 - y2)
C = x'1 - A x1
D = y'1 - B y1
P.S. Your equations imply a simple scaling/translation from one map to another. If you're worried about using different projections from globe to plane, the equations will be more complicated.

To get result more robust against inaccuracies more that two points may help.
In this case if you assume only shift and scaling Least squares fit may help: Wikipedia
Basically you minimize sum( (Axi+B-xi')^2 + (Cyi+D-yi')^2 ) by selecting optimal A,B,C,D.

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.

Selecting polar coordinates from cartesian coordinates in a database

In my MySQL database I have three fields, x,y,z representing a position.
I would like to transform these coordinates into polar coordinates az,el,r, and based on these, select the rows where (e.g.) az are within some region.
How would I go about doing this in MySQL?
EDIT:
This in not a question of how to actually do the coordinate transformation, but rather, if MySQL is capable of transforming the data based on some method, and then selecting data once it is transformed with a criterion based on a comparison of the transformed data.
Solve the Triangle ...
Cartesian = How far along and how far up
Polar = How far away and what angle
In order to convert you need to solve the right triangle for the two known sides
you need to use Pythagoras theorem to find the long side (hypotenuse)
you need the Tangent Function to find the angle
r = √ ( x2 + y2 ) = Pythagoras
θ = tan-1 ( y / x ) = Tangent Function
assuming there's no negative values - then you would have to take the inverse of tan function, or convert them to their positive counterpart
Mysql Pythagorus
SQRT((POWER(242-'EAST',2)) + (POWER(463-'NORT',2))) < 50
assuming your coordinates look like this.... here is an example
http://www.tek-tips.com/viewthread.cfm?qid=1397712
Tangent Function here
http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_tan
IMHO this is really a spherical coordinate system maths problem, not a MySQL-specific question.
MySQL just happens to be the data container in this instance.
For any solution you need to work out the maths first, then it becomes a matter of applying the equations to the data.
I can help with MySQL, but I'd have to Google solving these equations and my fingers are tired =)

convert meters to latitude longitude from any point

In my project I have to find [latitude, longitude] coordinate(s) from one point in distance of 500 meters (this could be any random coordinate or an array of coordinates around my point). How can I do this?
Note: I need this in order to find multiple paths between points different from shortest one which is returned us via Google Maps Directions Api..So using my method I will define the center of the road from A to B and then find some coordinates below and above that center position and use this as another waypoint to go from A to B - I guess this might help me to find multiple paths...
Any suggestions from GIS professionals?
EDIT: UTM conversion is the most preferable one for such calculations, and I've created UTM Java class if anyone needs..
If I understand your question right you have a known point in Lat/Long and you need calculate the Lat/Long of another point or points 500m away from your starting point.
If this is what you are doing, you have several options most of which involve specialist GIS APIs. However, I'm guesing you're a programmer/mathematician rather than a Geographer so, you may prefer to opt for using the Haversine formula. You can find a discussion on this topic here plus the formula.
One caveat is that the distamce you are working with (500m is quite small) and the Earth is far from being a perfect sphere or even a slightly flattened spheroid. It is locally "lumpy" and that can put your calculation out. If you need more accuracy you will have to account for these imperfections by using an appropriate local Datum (model of the Earth - there are many e.g. see EPSG list) and to do that you will probably need to start using the GIS libraries as the maths gets very detailed otherwise.
This is the code used by google map (SphericalUtil.java)
// from SphericalUtil.java
// compile 'com.google.maps.android:android-maps-utils:0.4.4'
public static LatLng computeOffset(LatLng from, double distance, double heading) {
distance /= 6371009.0D; //earth_radius = 6371009 # in meters
heading = Math.toRadians(heading);
double fromLat = Math.toRadians(from.latitude);
double fromLng = Math.toRadians(from.longitude);
double cosDistance = Math.cos(distance);
double sinDistance = Math.sin(distance);
double sinFromLat = Math.sin(fromLat);
double cosFromLat = Math.cos(fromLat);
double sinLat = cosDistance * sinFromLat + sinDistance * cosFromLat * Math.cos(heading);
double dLng = Math.atan2(sinDistance * cosFromLat * Math.sin(heading), cosDistance - sinFromLat * sinLat);
return new LatLng(Math.toDegrees(Math.asin(sinLat)), Math.toDegrees(fromLng + dLng));
}
to use it, you just have to enter the centerLatLng, the distance in meters, and the heading in degrees from centerLatLng.
you can change the formula to the language of your preference.

Mysql geometry AREA() function returns what exactly when coords are long/lat?

My question is somewhat related to this similar one, which links to a pretty complex solution - but what I want to understand is the result of this:
Using a Mysql Geometry field to store a small polygon I duly ran
select AREA(myPolygon) where id =1
over it, and got an value like 2.345. So can anyone tell me, just what does that number represent seeing as the stored values were long/lat sets describing the polygon?
FYI, the areas I am working on are relatively small (car parks and the like) and the area does not have to be exact - I will not be concerned about the curvature of the earth.
2.345 of what? Thanks, this is bugging me.
The short answer is that the units for your area calculation are basically meaningless ([deg lat diff] * [deg lon diff]). Even though the curvature of the earth wouldn't come into play for the area calculation (since your areas are "small"), it does come into play for the calculation of distance between the lat/lon polygon coordinates.
Since a degree of longitude is different based on the distance from the equator (http://en.wikipedia.org/wiki/Longitude#Degree_length), there really is no direct conversion of your area into m^2 or km^2. It is dependent on the distance north/south of the equator.
If you always have rectangular polygons, you could just store the opposite corner coordinates and calculate area using something like this: PHP Library: Calculate a bounding box for a given lat/lng location
The most "correct" thing to do would be to store your polygons using X-Y (meters) coordinates (perhaps UTM using the WGS-84 ellipsoid), which can be calculated from lat/lon using various libraries like the following for Java: Java, convert lat/lon to UTM. You could then continue to use the MySQL AREA() function.

How do I convert from this weird Coordinate unit to LngLat for use in Google Maps?

I have a database full of rows if coordinate pairs like this:
ux: 6643641
uy: 264274
uz: NULL
I have been tasked to make all these coordinates appear on google maps as points of interest, but nobody could tell me what the hell those coordinates were.
What I need for Google Maps is longitude and lengtitude coordinates. I know the one can be converted to the other, but nothing more.
I realize this might not be the correct place to ask about coordinate systems, but I honestly couldn't think of any other place to state the question.
Thanks for any help!
That's my bad, I now see that there is more data for each row:
CoordSystemNumber: 23
CoordSystemName: EUREF89 UTM Sone 33
I think that format is called UTM. You need to know the Zone and Hemisphere to complete the conversion. Is there other data associated with this?
Tell me if this seems helpful :
x = 882880 meters
y = -4924482 meters
z = 3944130 meters
Geocentric latitude and longitude are not commonly used, but they are defined by
latitude = arctan( z / sqrt( x^2 + y^2 ) )
longitude = arctan( y / x )
Taken from here :
http://www.cv.nrao.edu/~rfisher/Ephemerides/earth_rot.html
see this too :
http://en.wikipedia.org/wiki/Geographic_coordinate_system
This wikipedia article might offer some help.
The coordinates are often chosen such that one of the numbers represent vertical position, and two or three of the numbers represent horizontal position. A common choice of coordinates is latitude, longitude and elevation.