[PYTHON] [GPS] Use pyproj to calculate distance, azimuth, and elevation from GPS latitude and longitude

Overview

It can be used when flying a rocket or radio-controlled helicopter with GPS attached, or when creating data from GPS information of a flying object. How to calculate ** distance, azimuth, elevation ** from GPS ** latitude / longitude, altitude ** information. It is convenient to use python's pyproj library, so how to use it.

Advance preparation

Install pyproj pip install pyproj

Or

  1. Download the source from the pyproj page
  2. Run python setup.py build
  3. Run python setup.py install

Purpose

Let p1 be the reference point and obj be the flying target. Find the distance and azimuth from the latitude and longitude of p1 and obj with the inv () method of the Geod class of the pyproj package. The distance is the distance on the map and the straight line distance from the reference point to the object. Furthermore, the elevation angle (angle when looking up) is calculated using math.atan2 () including the altitude of obj. 2d.jpg

3d.jpg

Source

geod_sample.py


#!/usr/bin/env python
#-*- coding: utf-8 -*-
import math
from pyproj import Geod

#Reference point(p1)Latitude(p1_latitude),longitude(p1_longitude) 
#The unit is Degree
p1_latitude = 35.3524
p1_longitude = 135.0302

#Flying objects are latitude(obj_latitude),longitude(obj_longitude), Altitude(obj_altitude)Is at
obj_latitude = 35.3532
obj_longitude = 135.0305
obj_altitude = 1000 #Units(m)

#ellps is the equatorial radius. GPS uses WGS84. Distance is 6,378,137m
g = Geod(ellps='WGS84')

# inv() method
#The argument is inv(Longitude of p1,Latitude of p1,Longitude of interest,Target latitude, radians=False)
#The output changes with radians. No, or if you enter Degree and True in False, it will be output in Radian.
#The return value is the azimuth(azimuth), Anti-azimuth(back_azimuth),distance(distance_2d)Order
azimuth, back_azimuth, distance_2d = g.inv(p1_longitude, p1_latitude, obj_longitude, obj_latitude)

#If you want only what you need, you can do the following
result = g.inv(p1_longitude, p1_latitude, obj_longitude, obj_latitude)
azimuth = result[0]
back_azimuth = result[1]
distance_2d = result[2]

# inv()If you know the distance obtained in, the elevation angle will be combined with the GPS altitude.(elevation)Understand
# math.degrees()Is math.atan2()The return value of is Radian, so Degree(°)Is being converted to.
elevation = math.degrees(math.atan2(obj_altitude, distance_2d)

#Straight line distance to a flying object(distance_3d)Uses math to Pythagorean theorem
# math.Required by pypot.
distance_3d = math.hypot(distance_2d, obj_altitude)

print 'The distance on the map from the reference position to the flying object is' + str(distance_2d) + "m"
print 'The linear distance from the reference position to the flying object is' + str(distance_3d) + "m"
print 'The azimuth from the reference position to the flying object is' + str(azimuth) + "°"
print 'The anti-azimuth angle from the reference position to the flying object is' + str(back_azimuth) +"°"
print 'The elevation angle from the reference position to the flying object is' + str(elevation) + "°"

Recommended Posts

[GPS] Use pyproj to calculate distance, azimuth, and elevation from GPS latitude and longitude
Find the distance from latitude and longitude (considering the roundness of the earth).
Get the address from latitude and longitude
Download Geographical Survey tiles from latitude and longitude
Give latitude and longitude point sequence data and try to identify the road from OpenStreetMap data
Convert latitude, longitude, GPS altitude to 3D Cartesian coordinates
How to get the pixel value of the point from the satellite image by specifying the latitude and longitude
Find the waypoint from latitude and longitude (considering the roundness of the earth).