jgdtrans.point module#

Provides Point.

class jgdtrans.point.Point(latitude: float, longitude: float, altitude: float = 0.0)#

Bases: Sequence[float]

A triplet of latitude, longitude and altitude.

This is Sequence[float] of lengh 3.

We note that latitude and longitude is DD notation, use Point.to_dms() and Point.from_dms() for converting to/from DMS notation.

Examples

>>> Point(36.10377479, 140.087855041)
Point(latitude=36.10377479, longitude=140.087855041, altitude=0.0)
>>> Point(36.10377479, 140.087855041, 2.340)
Point(latitude=36.10377479, longitude=140.087855041, altitude=2.340)
>>> point = Point(36.10377479, 140.087855041)
>>> len(point)
3
>>> for v in point:
...     print(v)
36.10377479
140.087855041
0.0
>>> point[0], point[1], point[2]
(36.10377479, 140.087855041, 0.0)
>>> lat, lng, alt = point
>>> lat, lng, alt
(36.10377479, 140.087855041, 0.0)
latitude: float#

The latitude [deg] of the point which satisfies -90.0 <= and <= 90.0.

longitude: float#

The longitude [deg] of the point which satisfies -180.0 <= and <= 180.0.

altitude: float = 0.0#

The altitude [m] of the point, defaulting 0.0.

add(corr: Correction) Point#

Returns a Point which is self plus corr for each component.

This is not inplace.

Returns:

a Point obj

Examples

>>> point = Point(0.0, 0.0, 0.0)
>>> point.add(Correction(1.0, 2.0, 3.0))
Point(latitude=1.0, longitude=2.0, altitude=3.0)
>>> point
Point(latitude=0.0, longitude=0.0, altitude=0.0)
sub(corr: Correction) Point#

Returns a Point which is self substruct corr for each component.

This is not inplace.

Returns:

a Point obj

Examples

>>> point = Point(0.0, 0.0, 0.0)
>>> point.sub(Correction(1.0, 2.0, 3.0))
Point(latitude=-1.0, longitude=-2.0, altitude=-3.0)
>>> point
Point(latitude=0.0, longitude=0.0, altitude=0.0)
normalize() Point#

Returns a new normalized Point obj.

The resulting Point obj has normalized latitude and longitude which value -90.0 <= and <= 90.0, and -180.0 <= and <= 180.0 respectively.

Returns:

The normalized point, not null.

Examples

>>> Point(100.0, 200.0, 5.0).normalize()
Point(latitude=80.0, longitude=-160.0, altitude=5.0)
classmethod from_node(node: _mesh.MeshNode) Self#

Makes a Point which pointing a node represented by meshcode.

The resulting altitude is 0.0.

Parameters:

node – the mesh node

Returns:

the point (the altitude is 0.0)

Examples

>>> node = MeshNode(MeshCoord(54, 1, 2), MeshCoord(40, 0, 7))
>>> Point.from_node(node)
Point(latitude=36.1, longitude=140.0875, altitude=0.0)
classmethod from_meshcode(meshcode: int) Self#

Makes a Point (the latitude and the longitude) of the node represented by code.

Parameters:

meshcode – the meshcode

Returns:

a Point obj

Raises:

ValueError – when invalid code given

Examples

>>> Point.from_meshcode(54401027)
Point(latitude=36.1, longitude=140.0875, altitude=0.0)
classmethod from_dms(latitude: _dms.DMS | str, longitude: _dms.DMS | str, altitude: float = 0.0) Self#

Makes a Point from DMS notation latitude and longitdue (and altitude).

Parameters:
  • latitude – the latitude in DMS notation

  • longitude – the longitude in DMS notation

  • altitude – the altitude [m], defaulting 0.0

Returns:

a Point obj with the DD notation latitude and longitude

Raises:

ValueError – when latitude and/or longitude is invalied

Examples

>>> Point.from_dms("360613.58925", "1400516.27815")
Point(latitude=36.10377479166667, longitude=140.08785504166664, altitude=0.0)
to_dms() tuple[str, str, float]#

Returns the point with the DMS notation latitude and longitude.

Returns:

a tuple of latitude, longtitude and altitude

Examples

>>> point = Point.from_dms("360613.58925", "1400516.27815")
>>> point.to_dms()
('360613.58925', '1400516.27815', 0.0)
to_meshcode(mesh_unit: _types.MeshUnitType) int#

Returns the meshcode of the nearest south-east mesh node of self.

Parameters:

mesh_unit – The mesh unit, 1 or 5

Returns:

the meshcode

Raises:

ValueError – when latitude and/or longitude is negative

Examples

>>> point = Point(36.103774791666666, 140.08785504166664, 10.0)
>>> point.to_meshcode(1)
54401027
>>> point = Point(36.103774791666666, 140.08785504166664, 10.0)
>>> point.to_meshcode(5)
54401005
mesh_node(mesh_unit: _types.MeshUnitType) _mesh.MeshNode#

Returns the nearest south-east mesh node of self.

We note that the result does not depend on the Point.altitude.

Parameters:

mesh_unit – The mesh unit, 1 or 5

Returns:

a MeshNode

Raises:

ValueError – when latitude and/or longitude is negative

Examples

>>> point = Point(36.103774791666666, 140.08785504166664, 10.0)
>>> point.mesh_node(point, 1)
MeshNode(MeshCode(54, 1, 2), MeshCode(40, 0, 7))
>>> point.mesh_node(point, 5)
MeshNode(MeshCode(54, 1, 0), MeshCode(40, 0, 5))
mesh_cell(mesh_unit: _types.MeshUnitType) _mesh.MeshCell#

Returns the unit mesh cell containing self.

Parameters:

mesh_unit – The mesh unit, 1 or 5

Returns:

the unit mesh cell containing self

Raises:

ValueError – when latitude and/or longitude is negative, or such MeshCell is not found

Examples

>>> point = Point(36.10377479, 140.087855041)
>>> point.mesh_cell(mesh_unit=1)
MeshCell(
    south_west=MeshNode(MeshCoord(54, 1, 2), MeshCoord(40, 0, 7)),
    south_east=MeshNode(MeshCoord(54, 1, 2), MeshCoord(40, 0, 8)),
    north_west=MeshNode(MeshCoord(54, 1, 3), MeshCoord(40, 0, 7)),
    north_east=MeshNode(MeshCoord(54, 1, 3), MeshCoord(40, 0, 8)),
    unit=1,
)
>>> point.mesh_cell(mesh_unit=5)
MeshCell(
    south_west=MeshNode(MeshCoord(54, 1, 0), MeshCoord(40, 0, 5)),
    south_east=MeshNode(MeshCoord(54, 1, 0), MeshCoord(40, 1, 0)),
    north_west=MeshNode(MeshCoord(54, 1, 5), MeshCoord(40, 0, 5)),
    north_east=MeshNode(MeshCoord(54, 1, 5), MeshCoord(40, 1, 0)),
    unit=5,
)