Using Python, is there a function, library, or other way to check to see if a certain lat/lon coordinate pair fall within a defined geographical boundary such as a US state?
Example:
Does 32.781065, -96.797117 fall within Texas?
The latitude and longitude, if present will always appear in the form of (X, Y) where X and Y are decimal numbers. For a valid (latitude, longitude) pair: -90<=X<=+90 and -180<=Y<=180. They will not contain any symbols for degrees or radians or N/S/E/W.
To search for a place, enter the latitude and longitude GPS coordinates on Google Maps. You can also find the coordinates of the places you previously found. Besides longitude and latitude, you can use plus codes to share a place without an address.
When writing latitude and longitude, write latitude first, followed by a comma, and then longitude. For example, the above lines of latitude and longitude would be written as "15°N, 30°E."
You could use the reverse geocode library, and then check that the "admin1" area is a specific US state.
It converts lat/lon coordinates into dictionaries like:
{
'name': 'Mountain View',
'cc': 'US',
'lat': '37.38605',
'lon': '-122.08385',
'admin1': 'California',
'admin2': 'Santa Clara County'
}
You can use the geocoder library which you can install using pip install geocoder
.
import geocoder
results = geocoder.google('32.781065, -96.797117', reverse = True)
print(results.current_result.state_long)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With