Skip to content
Advertisement

Given a long/lat, convert meters into longitude/latitude degrees

I have a longitude and latitude stored as a geometry with SRID 4326.

I want to make a line that is exactly 1000 meters long that is 90 degrees (to the right).

I know that the conversion from a longitudal/latitudal degree to a meter varies about where you are on the globe. That is why I will pass a reference long/lat that can be taken into consideration.

I am looking for something “good enough” that assumes that the distance you want will be no greater than 100 miles.

Given a long/lat and a meter distance of 1000 meters, return to me the size of the line long/lat degrees.

This question is specific to one example but I am looking for a general solution, because I have many functions that work upon “SRID Units” and the SRID I work with is long/lat (4326) but I always want to deal with meters and not degrees.

The hope is that I can call scaler function to convert the meters I want to the 4326 units.

Some hacks I have considered for finding X meters is converting the geometry into a geography and using the STBuffer(X) to make a circle with a radius equal to that of X, then create a long line that intersects the buffer and to find the point of the intersection, which will be the long/lat of exactly X meters away. This seems very hacky and inefficient but might be the most accurate


Edit:

To find the deltaX and deltaY the function is doing the the following:

I can supply @AngleRads and @DistanceInDegrees. The problem is that @DistanceInDegrees has to match 4326 units (degrees). Is it even possible to find a @DistanceInDegrees that will correspond to 1000 meters no matter what angle is given?

When I use the formula @DistanceInDegrees = (@Meters / 6371008.7714) * (180 / pi()) / cos(@Lat1 * pi()/180) and a angle of 90 degrees, then the length of the line is 1002 meters, close but not identically 1000.. If I use a degree of 45 the length of the line is 1191.67 meters.

Advertisement

Answer

After your EDIT, It seems you are looking for DISTANCE and BEARING

Here is a Table-Valued Function which may help

Example

Returns

Now, when I calculate the distance, I get 999.99999448737 meters

The Table-Valued Function If Interested

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement