coordconverterjb 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026, James Blessings
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: coordconverterjb
3
+ Version: 0.1.0
4
+ Summary: this package converts the coordinates from degrees to decimals and vice versa
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: James Blessings
8
+ Requires-Python: >=3.12,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Programming Language :: Python :: 3.15
15
+ Description-Content-Type: text/markdown
16
+
17
+ # coordconverterjb
18
+
19
+ this package converts the coordinates from degrees to decimals and vice versa
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ $ pip install coordconverterjb
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ - TODO
30
+
31
+ ## Contributing
32
+
33
+ Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.
34
+
35
+ ## License
36
+
37
+ `coordconverterjb` was created by James Blessings. It is licensed under the terms of the MIT license.
38
+
39
+ ## Credits
40
+
41
+ `coordconverterjb` was created with [`cookiecutter`](https://cookiecutter.readthedocs.io/en/latest/) and the `py-pkgs-cookiecutter` [template](https://github.com/py-pkgs/py-pkgs-cookiecutter).
42
+
@@ -0,0 +1,25 @@
1
+ # coordconverterjb
2
+
3
+ this package converts the coordinates from degrees to decimals and vice versa
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ pip install coordconverterjb
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ - TODO
14
+
15
+ ## Contributing
16
+
17
+ Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.
18
+
19
+ ## License
20
+
21
+ `coordconverterjb` was created by James Blessings. It is licensed under the terms of the MIT license.
22
+
23
+ ## Credits
24
+
25
+ `coordconverterjb` was created with [`cookiecutter`](https://cookiecutter.readthedocs.io/en/latest/) and the `py-pkgs-cookiecutter` [template](https://github.com/py-pkgs/py-pkgs-cookiecutter).
@@ -0,0 +1,15 @@
1
+ [tool.poetry]
2
+ name = "coordconverterjb"
3
+ version = "0.1.0"
4
+ description = "this package converts the coordinates from degrees to decimals and vice versa"
5
+ authors = ["James Blessings"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+
9
+ [tool.poetry.dependencies]
10
+ python = "^3.12"
11
+
12
+
13
+ [build-system]
14
+ requires = ["poetry-core>=1.0.0"]
15
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,3 @@
1
+ # read version from installed package
2
+ from importlib.metadata import version
3
+ __version__ = version("coordconverterjb")
@@ -0,0 +1,161 @@
1
+
2
+ """Convert geographic coordinates between DMS and decimal degrees.
3
+
4
+ Examples
5
+ --------
6
+ >>> to_decimal((15, 47, 0, "S"), (35, 0, 0, "E"))
7
+ (-15.783333333333333, 35.0)
8
+
9
+ >>> to_degree(-15.783333333333333, 35.0)
10
+ ((15, 47, 0.0, 'S'), (35, 0, 0.0, 'E'))
11
+ """
12
+
13
+ from typing import Tuple, Union
14
+
15
+ DMSCoordinate = Tuple[int, int, float, str]
16
+ DecimalCoordinate = Tuple[float, float]
17
+
18
+
19
+ def to_decimal(
20
+ latitude: DMSCoordinate,
21
+ longitude: DMSCoordinate,
22
+ ) -> DecimalCoordinate:
23
+ """Convert latitude and longitude from DMS to decimal degrees.
24
+
25
+ Parameters
26
+ ----------
27
+ latitude : tuple
28
+ Latitude as (degrees, minutes, seconds, direction).
29
+ Direction must be 'N' or 'S'.
30
+ longitude : tuple
31
+ Longitude as (degrees, minutes, seconds, direction).
32
+ Direction must be 'E' or 'W'.
33
+
34
+ Returns
35
+ -------
36
+ tuple of float
37
+ Decimal latitude and decimal longitude. Southern and western
38
+ coordinates are negative.
39
+
40
+ Examples
41
+ --------
42
+ >>> to_decimal((15, 47, 0, "S"), (35, 0, 0, "E"))
43
+ (-15.783333333333333, 35.0)
44
+ >>> to_decimal((51, 30, 0, "N"), (0, 7, 0, "W"))
45
+ (51.5, -0.11666666666666667)
46
+ """
47
+ def convert_one(coordinate, valid_directions, max_degrees):
48
+ if len(coordinate) != 4:
49
+ raise ValueError(
50
+ "Each DMS coordinate must contain degrees, "
51
+ "minutes, seconds and direction."
52
+ )
53
+
54
+ degrees, minutes, seconds, direction = coordinate
55
+ direction = direction.upper() if isinstance(direction, str) else ""
56
+
57
+ if direction not in valid_directions:
58
+ raise ValueError(
59
+ f"Direction must be one of {valid_directions}."
60
+ )
61
+
62
+ if not all(
63
+ isinstance(value, (int, float))
64
+ and not isinstance(value, bool)
65
+ for value in (degrees, minutes, seconds)
66
+ ):
67
+ raise TypeError("Degrees, minutes and seconds must be numeric.")
68
+
69
+ if degrees < 0 or degrees > max_degrees:
70
+ raise ValueError(
71
+ f"Degrees must be between 0 and {max_degrees}."
72
+ )
73
+
74
+ if not 0 <= minutes < 60 or not 0 <= seconds < 60:
75
+ raise ValueError("Minutes and seconds must be in [0, 60).")
76
+
77
+ if degrees == max_degrees and (minutes != 0 or seconds != 0):
78
+ raise ValueError(
79
+ f"At {max_degrees} degrees, minutes and seconds must be zero."
80
+ )
81
+
82
+ decimal_value = degrees + minutes / 60 + seconds / 3600
83
+
84
+ if direction in ("S", "W"):
85
+ decimal_value = -decimal_value
86
+
87
+ return decimal_value
88
+
89
+ decimal_latitude = convert_one(latitude, ("N", "S"), 90)
90
+ decimal_longitude = convert_one(longitude, ("E", "W"), 180)
91
+
92
+ return decimal_latitude, decimal_longitude
93
+
94
+
95
+ def to_degree(
96
+ latitude: float,
97
+ longitude: float,
98
+ ) -> Tuple[DMSCoordinate, DMSCoordinate]:
99
+ """Convert decimal latitude and longitude to DMS coordinates.
100
+
101
+ Parameters
102
+ ----------
103
+ latitude : float
104
+ Decimal latitude between -90 and 90 degrees.
105
+ longitude : float
106
+ Decimal longitude between -180 and 180 degrees.
107
+
108
+ Returns
109
+ -------
110
+ tuple
111
+ A pair of DMS tuples in the form
112
+ ((degrees, minutes, seconds, direction),
113
+ (degrees, minutes, seconds, direction)).
114
+ Seconds are returned as floats.
115
+
116
+ Examples
117
+ --------
118
+ >>> to_degree(-15.783333333333333, 35.0)
119
+ ((15, 47, 0.0, 'S'), (35, 0, 0.0, 'E'))
120
+ >>> to_degree(51.5, -0.11666666666666667)
121
+ ((51, 30, 0.0, 'N'), (0, 7, 0.0, 'W'))
122
+ """
123
+ def convert_one(value, max_degrees, positive_direction,
124
+ negative_direction):
125
+ if not isinstance(value, (int, float)) or isinstance(value, bool):
126
+ raise TypeError("Coordinates must be numeric.")
127
+
128
+ if not -max_degrees <= value <= max_degrees:
129
+ raise ValueError(
130
+ f"Coordinate must be between {-max_degrees} "
131
+ f"and {max_degrees}."
132
+ )
133
+
134
+ direction = negative_direction if value < 0 else positive_direction
135
+ absolute_value = abs(value)
136
+
137
+ degrees = int(absolute_value)
138
+ minutes_full = (absolute_value - degrees) * 60
139
+ minutes = int(minutes_full)
140
+ seconds = round((minutes_full - minutes) * 60, 6)
141
+
142
+ # Handle rounding that reaches 60 seconds or 60 minutes.
143
+ if seconds >= 60:
144
+ seconds = 0.0
145
+ minutes += 1
146
+
147
+ if minutes >= 60:
148
+ minutes = 0
149
+ degrees += 1
150
+
151
+ if degrees > max_degrees:
152
+ degrees = max_degrees
153
+ minutes = 0
154
+ seconds = 0.0
155
+
156
+ return degrees, minutes, seconds, direction
157
+
158
+ dms_latitude = convert_one(latitude, 90, "N", "S")
159
+ dms_longitude = convert_one(longitude, 180, "E", "W")
160
+
161
+ return dms_latitude, dms_longitude