you could use the us census data, and geopandas.
imports
import urllib
import requests
from pathlib import Path
from zipfile import ZipFile
import geopandas as gpd
import pandas as pd
from shapely.geometry import Point
get geometry data as a geopandas dataframe
src = [
{
"name": "counties",
"suffix": ".shp",
"url": "https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_county_5m.zip",
},
]
data = {}
print('gathering county data from census')
for s in src:
f = Path.cwd().joinpath(urllib.parse.urlparse(s["url"]).path.split("/")[-1])
if not f.exists():
r = requests.get(s["url"],stream=True,)
with open(f, "wb") as fd:
for chunk in r.iter_content(chunk_size=128): fd.write(chunk)
fz = ZipFile(f)
fz.extractall(f.parent.joinpath(f.stem))
data[s["name"]] = gpd.read_file(
f.parent.joinpath(f.stem).joinpath([f.filename
for f in fz.infolist()
if Path(f.filename).suffix == s["suffix"]][0])
).assign(source_name=s["name"])
gdf = pd.concat(data.values()).to_crs("EPSG:4326")
Lockport Illinois coordinates
query_point = Point(-88.057510, 41.589401)
use geopandas contains() to filter the data
contains = gdf.contains(query_point)
data = gdf[contains]
print(data['NAME'])
prints 'Will'
link to documentation:
https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.contains.html