I'm looking for the easiest way convert utm to lat / long
If the server-side code is better.
for example utm
EASTING NORTHING
521937.7447 3955151.601
Thank you
In order to convert UTM coordinates (easting and northing) to latitude and longitude you need the zone number and zone letter as well.
Without these your easting / northing values could be in any of the 60 zones defined by UTM.
As for libraries, there are packages for Python, Javascript and probably others.
Sample for JS:
utm.toLatLon(easting, northing, zoneNum, zoneLetter)
//returns { latitude, longitude }
utm.fromLatLon(latitude, longitude)
//returns { easting, northing, zoneNum, zoneLetter }
You can use ST_Transform in Postgis if you have access to this
https://postgis.net/docs/ST_Transform.html
Example:
ST_AsText(ST_Transform(ST_SetSRID(the_geom, 27700), 4326)))
Related
How would be the algorithm to convert the following GPS coordinates (Java language prefered)?
From UTM/SAD69:
Latitude: 7171359,145
Longitude: 716431,81
Zone: 22
Hemisphere: South
To Decimal (Google Maps friendly):
Longitude: -48.8461461196
Latitude: -25.559740724
http://maps.google.com.br/maps?q=-25.559740724,-48.8461461196&hl=pt-BR&t=h&z=16
You could utilize UTMConverter.java for that purpose, the following example:
double easting = 716431.81;
double northing = 7171359.145;
int zone = 22;
boolean isSouthHemishere = true;
LatLng value = UTMConverter.convertToLatLng(easting,northing,zone,isSouthHemishere);
System.out.println(value);
gives the same result (lat: -25.55933783,lng:-48.84565751) as Geographic/UTM Coordinate Converter online tool
Use PROJ.4 to convert from EPSG:29192 (SAD69 / UTM zone 22S) to EPSG:4326 (WGS 84).
For example here is a simple interface to transform, but there are others for command line, JavaScript, etc.
I have an third party application which saves lat and lng values as below in the db.
lat lng lat_dir lng_dir
2824.2311 07703.0962 N E
The problem is, It is not clear on which unit lat lng values are saved in DB.
I have tried to convert in degree by assuming the values in KM. After Lat comes some where nearby If I assume,But in no way lng comes. lng values is more away that I can assume.
Any Guidence is appreciated.
PS. I have no control over third party application, and there is no document present over lat lng calculation by third party application.
Google map requires the lat and lng to be in the decimal format. The format that the third party application is storing is used by some GPS tracking devices. I don't recall what the format is called though.
You will need to convert the lat / lng to decimal format before plotting it on the map. Given below is the Java code to convert it into a decimal format.
private static String getCordinate(String location) {
int len = location.length();
String decimals = location.substring(len-7);
Float decimalf = Float.parseFloat(decimals) / 60;
String first = location.substring(0,len-7);
Float coordinate = Float.parseFloat(first) + decimalf;
return coordinate.toString();
}
Coordinate Format - Latitude : 1907.51672 & Longitude : 7252.34810
Output Format : Latitude : 28.403852 & Longitude : 77.051605
The location is as follows on Google Maps
I have a rectangular polygon and I want to extend the boundaries by 10 km for example.
How would I do that ?
I could use extend method, but how Do I find the distance of 10 km in lat lng ?
So far I have :
bounds = new google.maps.LatLngBounds();
pt = new google.maps.LatLng(lat,lng);
bounds.extend(pt)
It depends on how exact an answer you need.
You could use the following approximation:
Latitude: 1 deg = 110.57 km; Longitude: 1 deg = 111.320 km source: http://en.wikipedia.org/wiki/Latitude
For a more exact formula, you need to check http://www.movable-type.co.uk/scripts/latlong.html . It has various formulas and also some code. You are looking for the section called 'Destination point given distance and bearing from start point'
It depends where you are looking at but a longitude is 111km and a latitude 110km:http://en.m.wikipedia.org/wiki/Latitude.
I'm experimenting with System.Data.Spatial.DbGeography, that I want to use to determine the distance from one coordinate to another (going to be stored in SQL server).
My coordinates are in lat/long, and I got them from Bing Maps (I've tried with coordinates from Google Maps too, with the same result).
var osloCentralStation = DbGeography.FromText("POINT(59.9109 10.7523)", 4326);
var drammen = DbGeography.FromText("POINT(59.7378 10.2050)", 4326);
Console.WriteLine("Distance: {0}km", osloCentralStation.Distance(drammen) / 1000);
Returns:
Distance: 63,4340839088124km
The returned distance is approximately double what it should be.
https://maps.google.com/maps?saddr=59.9109+10.7523&daddr=59.7378+10.2050
Does anybody have any idea as to what's going on?
You're not declaring the element in WKT in the right order.
WKT should be in your case:
POINT(10.2050 59.7378)
See OGC standard here:
http://msdn.microsoft.com/en-us/library/bb933834.aspx
http://en.wikipedia.org/wiki/Well-known_text
And then it has to be declared like:
POINT(LONGITUDE LATITUDE)
Also keep in mind that it won't be the driving distance but the distance by air.
It turns out that lat/long are given as long/lat when creating new DbGeography objects.
I've written a little helper method so that I don't get it wrong again in the future:
private static DbGeography CreateDbGeography(double latitude, double longitude, int srid = 0)
{
var text = string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", longitude, latitude);
if (srid > 0)
{
return DbGeography.FromText(text, srid);
}
return DbGeography.FromText(text);
}
So: I have the following function, adapted from a formula found online, which takes two lat/lon coordinates and finds the distance between them in miles (along a spherical Earth):
public static double distance (double lat1, double lon1, double lat2, double lon2) {
double theta = toRadians(lon1-lon2);
lat1 = toRadians(lat1);
lon1 = toRadians(lon1);
lat2 = toRadians(lat2);
lon2 = toRadians(lon2);
double dist = sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2)*cos(theta);
dist = toDegrees(acos(dist)) * 60 * 1.1515 * 1.609344 * 1000;
return dist;
}
As far as I can tell this works just fine.
What I need is a second function which, using the exact same model of the Earth's geometry, takes a single lat/lon pair [A], a heading, and a distance, and outputs a new lat/lon pair [B] such that if you started at point [A], and traveled the given distance at the given heading, you'd wind up at point [B].
This is where the fact that my geometry skills have left me entirely comes into play :)
Any help would be much appreciated!
Thanks,
-Dan
I get most of those types of formulas from The Aviation Formulary.
The formula he gives is:
Lat/lon given radial and distance
A point {lat,lon} is a distance d out on
the tc radial from point 1 if:
lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
IF (cos(lat)=0)
lon=lon1 // endpoint a pole
ELSE
lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
ENDIF
This algorithm is limited to distances such that dlon < pi/2, i.e
those that extend around less than one
quarter of the circumference of the
earth in longitude. A completely
general, but more complicated
algorithm is necessary if greater
distances are allowed:
lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(lat))
lon=mod( lon1-dlon +pi,2*pi )-pi
Note that he's using "tc" to stand for true course (in radians clockwise from North) and the distances he gives are in radians of arc along the surface of the earth. This is explained (along with formulas to convert back and forth from nautical miles) in the first section of the Formulary. Also, check out the "Implementation Notes" and "Worked Examples" on that page.