This repository contains a set of Python scripts designed to facilitate the retrieval of geographic location information based on various parameters such as latitude and longitude coordinates, city names, country names, and state names.
This script provides a comprehensive functionality to locate the nearest geographic locations based on given latitude and longitude coordinates (in decimal format). It calculates distances to the closest populated place, road/railway, hill/mountain, lake, park, and building. Additionally, it can determine the nearest administrative location (e.g., city, state) based on the provided coordinates.
This utility script extracts state information from geonames data and generates a Python file named all_states_code.py
. It is employed internally by gps.py
, city-gps-location.py
and state-gps-location.py
to retrieve corresponding name of a state based on its code.
This script enables users to find the coordinates of a specific city based on its name. It leverages geonames data to perform the city search.
This script enables users to find the coordinates of a specific state based on its name.
Users can utilize this script to find the coordinates of a specific country (it makes more sense using allCountries.txt of Geonames).
To search for anything in the database, use the following input format: x,y
for coordinates (in decimal format) or 'Any string'
for a string. If you search for a coordinate, the script will retrieve the nearest coordinate's location and its information. If the search is for a string, the script will retrieve all locations and their information from the database that contain this searched string.
This code provides functions to convert between decimal and sexagesimal representations of geographic coordinates (latitude and longitude).
To use it correctly:
- Run the script.
python3 convert.py <"-1" for decimal to sexagesimal or "-2" for sexagesimal to decimal>
- Follow the prompts:
- For decimal to sexagesimal conversion, input latitude and longitude in decimal format (In the Southern hemisphere, use negative values for latitude, and in the Western hemisphere, use negative values for longitude). Example:
-15.7373
than36.7289
- For sexagesimal to decimal conversion, input latitude and longitude in the specified sexagesimal format (N/S for latitude, and E/W for longitude). Example:
39º 42' 17'' N
than22º 49' 52'' E
- For decimal to sexagesimal conversion, input latitude and longitude in decimal format (In the Southern hemisphere, use negative values for latitude, and in the Western hemisphere, use negative values for longitude). Example:
- The script will output the converted coordinates.
- Ensure that you have Python 3.x installed on your system.
- Download the geonames text files from Geonames and place them in the repository directory, and change the .txt name file for your own country .txt database in each code you will use.
- Run the desired Python script according to your location search requirements.
python3 <file.py>
- Python 3.x
- Geonames text files (downloaded from the Geonames website)
- [d4v1-sudo]
-
Remember, to use geographic coordinates in these python codes, decimal format is required. I made
convert.py
precisely for type compatibility issues, as my codes do not accept the sexagesimal system (XXº XX' XX'' N/S/E/W). Then useconvert.py
for testing and conversions. -
Feel free to contribute to this project by adding new features, fixing bugs, improving documentation, or addressing issues. Your contributions are highly appreciated!
-
If you have any questions or suggestions, please don't hesitate to reach out.