latlong.standardize_latlong
latlong.standardize_latlong(lat, lon)Convert various latitude/longitude formats to a standardized decimal degree format.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| lat | str or float | Latitude value in various formats. Supported formats: - Decimal degrees (e.g., 34.0522) - Degrees, minutes, seconds (e.g., 34d3’8”N) - Degrees and decimal minutes (e.g., 34d3.133’N) | required |
| lon | str or float | Longitude value in various formats. Supported formats: - Decimal degrees (e.g., -118.2437) - Degrees, minutes, seconds (e.g., 118d14’37”W) - Degrees and decimal minutes (e.g., 118d14.617’W) | required |
Returns
| Name | Type | Description |
|---|---|---|
| tuple | A tuple of floats containing standardized latitude and longitude in decimal degrees. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If the input format is not recognized or if the coordinates are out of valid geographic ranges (Latitude must be between -90 and 90 and longitude must be between -180 and 180). | |
| TypeError | If the input types are not str or float. |
Examples
>>> # Decimal Degrees
>>> standardize_latlong(34.0522, -118.2437)
(34.0522, -118.2437)>>> # Degrees, Minutes, Seconds (DMS)
>>> standardize_latlong("34d3'8"N", "118d14'37"W")
(34.05222222222222, -118.2436111111111)>>> # Degrees and Decimal Minutes (DDM)
>>> standardize_latlong("34d3.133'N", "118d14.617'W")
(34.05221666666667, -118.24361666666667)