使用Python,是否有函数、库或其他方法可以检查某个经度/经度坐标对是否落入定义的地理边界内?
示例:
32.781065,-96.797117在德克萨斯州吗?
发布于 2021-02-17 15:48:28
只是为了建立在mathisonian的答案上。
import reverse_geocoder
#create a list of US states (and the District of Columbia)
state_names = ["Alaska", "Alabama", "Arkansas", "Arizona", "California", "Colorado", "Connecticut", "District of Columbia","Delaware", "Florida","Georgia", "Hawaii", "Iowa", "Idaho", "Illinois", "Indiana", "Kansas", "Kentucky", "Louisiana", "Massachusetts", "Maryland", "Maine", "Michigan", "Minnesota", "Missouri", "Mississippi", "Montana", "North Carolina", "North Dakota", "Nebraska", "New Hampshire", "New Jersey", "New Mexico", "Nevada", "New York", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina","South Dakota", "Tennessee", "Texas", "Utah", "Virginia", "Vermont", "Washington", "Wisconsin", "West Virginia", "Wyoming"]
#get the metadata for the latitude and longitude coordinates
results = reverse_geocoder.search((32.781065, -96.797117))
#check if the location is a US state (the 'admin1' variable is where US states are listed)
if results[0]['admin1'] in state_names:
print(results[0]['admin1'])
这应该会打印出“德州”。
https://stackoverflow.com/questions/25008191
复制相似问题