Earth Position (GPS)

Tip

Transforms from the space to the gps coordinate system. Parameters are \(\mathrm{lat}, \mathrm{lon}, \alpha_\mathrm{heading}\).

Often the camera is looking at landmarks where the GPS position is known or the GPS position of the camera itself is known and the GPS position of landmarks has to be determined.

Parameters

  • lat, \(\mathrm{lat}\): the latitude of the camera position.
  • lon, \(\mathrm{lon}\): the longitude of the camera position.
  • heading_deg, \(\alpha_\mathrm{heading}\): the direction in which the camera is looking, also used by the spatial orientation. (0°: the camera faces “north”, 90°: east, 180°: south, 270°: west)

Functions

Camera.setGPSpos(lat, lon=None, elevation=None)[source]

Provide the earth position for the camera.

Parameters:
  • lat (number, string) – the latitude of the camera or the string representing the gps position.
  • lon (number, optional) – the longitude of the camera.
  • elevation (number, optional) – the elevation of the camera.

Examples

>>> import cameratransform as ct
>>> cam = ct.Camera()

Supply the gps position of the camera as floats:

>>> cam.setGPSpos(-66.66, 140.00, 19)

or as a string:

>>> cam.setGPSpos("66°39'53.4"S 140°00'34.8"")
Camera.gpsFromSpace(points)[source]

Convert points (Nx3) from the space coordinate system to the gps coordinate system.

Parameters:points (ndarray) – the points in space coordinates to transform, dimensions (3), (Nx3)
Returns:points – the points in the gps coordinate system, dimensions (3), (Nx3)
Return type:ndarray
Camera.spaceFromGPS(points)[source]

Convert points (Nx3) from the gps coordinate system to the space coordinate system.

Parameters:points (ndarray) – the points in gps coordinates to transform, dimensions (3), (Nx3)
Returns:points – the points in the space coordinate system, dimensions (3), (Nx3)
Return type:ndarray
Camera.gpsFromImage(points, X=None, Y=None, Z=0, D=None)[source]

Convert points (Nx2) from the image coordinate system to the gps coordinate system.

Parameters:points (ndarray) – the points in image coordinates to transform, dimensions (2), (Nx2)
Returns:points – the points in the gps coordinate system, dimensions (3), (Nx3)
Return type:ndarray
Camera.imageFromGPS(points)[source]

Convert points (Nx3) from the gps coordinate system to the image coordinate system.

Parameters:points (ndarray) – the points in gps coordinates to transform, dimensions (3), (Nx3)
Returns:points – the points in the image coordinate system, dimensions (2), (Nx2)
Return type:ndarray

Transformation

Distance

cameratransform.getDistance(point1, point2)[source]

Calculate the great circle distance between two points \((\mathrm{lat}_1, \mathrm{lon}_1)\) and \((\mathrm{lat}_2, \mathrm{lon}_2)\) on the earth (specified in decimal degrees)

\[\begin{split}\Delta\mathrm{lon} &= \mathrm{lon}_2 - \mathrm{lon}_1\\ \Delta\mathrm{lat} &= \mathrm{lat}_2 - \mathrm{lat}_1\\ a &= \sin(\Delta\mathrm{lat}/2)^2 + \cos(\mathrm{lat}_1) \cdot \cos(\mathrm{lat}_2) \cdot \sin(\Delta\mathrm{lat}/2)^2\\ d &= 6371\,\mathrm{km} \cdot 2 \arccos(\sqrt a)\end{split}\]
Parameters:
  • point1 (ndarray) – the start point from which to calculate the distance, dimensions (2), (3), (Nx2), (Nx3)
  • point2 (ndarray) – the end point to which to calculate the distance, dimensions (2), (3), (Nx2), (Nx3)
Returns:

distance – the distance in m, dimensions (), (N)

Return type:

float, ndarray

Examples

>>> import cameratransform as ct

Calculate the distance in m between two gps positions:

>>> ct.getDistance([52.51666667, 13.4], [48.13583333, 11.57988889])
503926.75849507266

or between a list of gps positions:

>>> ct.getDistance([[52.51666667, 13.4], [52.51666667, 13.4]], [[49.597854, 11.005092], [48.13583333, 11.57988889]])
array([365127.04999716, 503926.75849507])

Bearing

cameratransform.getBearing(point1, point2)[source]

The angle relative \(\beta\) to the north direction from point \((\mathrm{lat}_1, \mathrm{lon}_1)\) to point \((\mathrm{lat}_2, \mathrm{lon}_2)\):

\[\begin{split}\Delta\mathrm{lon} &= \mathrm{lon}_2 - \mathrm{lon}_1\\ X &= \cos(\mathrm{lat}_2) \cdot \sin(\Delta\mathrm{lon})\\ Y &= \cos(\mathrm{lat}_1) \cdot \sin(\mathrm{lat}_2) - \sin(\mathrm{lat}_1) \cdot \cos(\mathrm{lat}_2) \cdot \cos(\Delta\mathrm{lon})\\ \beta &= \arctan2(X, Y)\end{split}\]
Parameters:
  • point1 (ndarray) – the first point from which to calculate the bearing, dimensions (2), (3), (Nx2), (Nx3)
  • point2 (ndarray) – the second point to which to calculate the bearing, dimensions (2), (3), (Nx2), (Nx3)
Returns:

bearing – the bearing angle in degree, dimensions (), (N)

Return type:

float, ndarray

Examples

>>> import cameratransform as ct

Calculate the bearing in degrees between two gps positions:

>>> ct.getBearing([85.3205556, 4.52777778], [-66.66559128, 140.02233212])
53.34214977328738

or between a list of gps positions:

>>> ct.getBearing([[85.3205556, 4.52777778], [65.3205556, 7.52777778]], [[-66.66559128, 140.02233212], [-60.66559128, 80.02233212]])
array([ 53.34214977, 136.82109976])

Move Distance

cameratransform.moveDistance(start, distance, bearing)[source]

Moving from \((\mathrm{lat}_1, \mathrm{lon}_1)\) a distance of \(d\) in the direction of \(\beta\):

\[\begin{split}R &= 6371\,\mathrm{km}\\ \mathrm{lat}_2 &= \arcsin(\sin(\mathrm{lat}_1) \cdot \cos(d / R) + \cos(\mathrm{lat}_1) \cdot \sin(d / R) \cdot \cos(\beta))\\ \mathrm{lon}_2 &= \mathrm{lon}_1 + \arctan\left(\frac{\sin(\beta) \cdot \sin(d / R) \cdot \cos(\mathrm{lat}_1)}{ \cos(d / R) - \sin(\mathrm{lat}_1) \cdot \sin(\mathrm{lat}_2)}\right)\end{split}\]
Parameters:
  • start (ndarray) – the start point from which to calculate the distance, dimensions (2), (3), (Nx2), (Nx3)
  • distance (float, ndarray) – the distance to move in m, dimensions (), (N)
  • bearing (float, ndarray) – the bearing angle in degrees, specifying in which direction to move, dimensions (), (N)
Returns:

target – the target point, dimensions (2), (3), (Nx2), (Nx3)

Return type:

ndarray

Examples

>>> import cameratransform as ct

Move from 52.51666667°N 13.4°E, 503.926 km in the direction -164°:

>>> ct.moveDistance([52.51666667, 13.4], 503926, -164)
array([48.14444416, 11.52952357])

Batch process multiple positions at once:

>>> ct.moveDistance([[52.51666667, 13.4], [49.597854, 11.005092]], [10, 20], -164)
array([[52.51658022, 13.39995926],
       [49.5976811 , 11.00501551]])

Or one positions in multiple ways:

>>> ct.moveDistance([52.51666667, 13.4], [503926, 103926], [-164, -140])
array([[48.14444416, 11.52952357],
       [51.79667095, 12.42859387]])

GPS - String Conversion

cameratransform.formatGPS(lat, lon, format=None, asLatex=False)[source]

Formats a latitude, longitude pair in degrees according to the format string. The format string can contain a %s, to denote the letter symbol (N, S, W, E) and up to three number formaters (%d or %f), to denote the degrees, minutes and seconds. To not lose precision, the last one can be float number.

common formats are e.g.:

format output
%2d° %2d’ %6.3f” %s (default) 70° 37’ 4.980” S 8° 9’ 26.280” W
%2d° %2.3f’ %s 70° 37.083’ S 8° 9.438’ W
%2.3f° -70.618050° -8.157300°
Parameters:
  • lat (number) – the latitude in degrees
  • lon (number) – the longitude in degrees
  • format (string) – the format string
  • asLatex (bool) – whether to encode the degree symbol
Returns:

  • lat (string) – the formatted latitude
  • lon (string) – the formatted longitude

Examples

>>> import cameratransform as ct

Convert a coordinate pair to a formatted string:

>>> lat, lon = ct.formatGPS(-70.61805, -8.1573)
>>> lat
'70° 37\'  4.980" S'
>>> lon
' 8°  9\' 26.280" W'

or use a custom format:

>>> lat, lon = ct.formatGPS(-70.61805, -8.1573, format="%2d° %2.3f %s")
>>> lat
'70° 37.083 S'
>>> lon
' 8° 9.438 W'
cameratransform.gpsFromString(gps_string, height=None)[source]

Read a gps coordinate from a text string in different formats, e.g. 70° 37’ 4.980” S 8° 9’ 26.280” W, 70° 37.083 S 8° 9.438 W, or -70.618050° -8.157300°.

Parameters:
  • gps_string (str, list) – the string of the point, containing both latitude and longitude, or a tuple with two strings one for latitude and one for longitude To batch process multiple strings, a list of strings can also be provided.
  • height (float, optional) – the height of the gps point.
Returns:

point – a list containing, lat, lon, (height) of the given point.

Return type:

list

Examples

>>> import cameratransform as ct

Convert a coordinate string to a tuple:

>>> ct.gpsFromString("85° 19′ 14″ N, 000° 02′ 43″ E")
array([8.53205556e+01, 4.52777778e-02])

Add a height information:

>>> ct.gpsFromString("66° 39´56.12862´´S  140°01´20.39562´´ E", 13.769)
array([-66.66559128, 140.02233212,  13.769     ])

Use a tuple:

>>> ct.gpsFromString(["66°39'56.12862''S", "140°01'20.39562'' E"])
array([-66.66559128, 140.02233212])

Or supply multiple coordinates with height information:

>>> ct.gpsFromString([["-66.66559128° 140.02233212°", 13.769], ["66°39'58.73922''S  140°01'09.55709'' E", 13.769]])
array([[-66.66559128, 140.02233212,  13.769     ],
       [-66.66631645, 140.01932141,  13.769     ]])