Skip to content

Commit 514fc09

Browse files
committed
fix to pre-commit
1 parent 4cc3cbf commit 514fc09

1 file changed

Lines changed: 19 additions & 40 deletions

File tree

‎geo-intro.ipynb‎

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -942,26 +942,17 @@
942942
"metadata": {},
943943
"outputs": [],
944944
"source": [
945-
"geolocator = Nominatim(user_agent=\"coding-for-economists/1.0\")\n",
946-
"\n",
947-
"# Function to safely geocode a place name\n",
948-
"# We use a local loop here because the Photon API (photon.komoot.io) frequently times out.\n",
949-
"# Using Nominatim directly gives us more control over timeouts and error handling.\n",
950-
"def get_geo(point_name):\n",
951-
" try:\n",
952-
" loc = geolocator.geocode(f\"{point_name}, NY\", timeout=10)\n",
953-
" return Point(loc.latitude, loc.longitude) if loc else None\n",
954-
" except Exception:\n",
955-
" return None\n",
956-
"\n",
957-
"boros_df['geometry'] = boros_df.boro_name.apply(get_geo)\n",
958-
"# Drop any failed geocode attempts before converting to GeoDataFrame\n",
959-
"boroughs_gdf = gpd.GeoDataFrame(\n",
960-
" boros_df.dropna(subset=['geometry']), \n",
961-
" geometry='geometry', \n",
962-
" crs='EPSG:4326'\n",
963-
")\n",
964-
"boroughs_gdf\n"
945+
"# If you don't have it, install geopy using 'pip install geopy'\n",
946+
"from geopy.geocoders import Nominatim\n",
947+
"\n",
948+
"# Create a geolocator using Open Street Map (aka Nominatim)\n",
949+
"# Use your own user agent identifier here\n",
950+
"geolocator = Nominatim(user_agent=\"codeforecon\")\n",
951+
"\n",
952+
"# Pass an address to retrieve full location information:\n",
953+
"location = geolocator.geocode(\"Bank of England\")\n",
954+
"\n",
955+
"location.address"
965956
]
966957
},
967958
{
@@ -1034,26 +1025,14 @@
10341025
"metadata": {},
10351026
"outputs": [],
10361027
"source": [
1037-
"geolocator = Nominatim(user_agent=\"coding-for-economists/1.0\")\n",
1038-
"\n",
1039-
"# Function to safely geocode a place name\n",
1040-
"# We use a local loop here because the Photon API (photon.komoot.io) frequently times out.\n",
1041-
"# Using Nominatim directly gives us more control over timeouts and error handling.\n",
1042-
"def get_geo(point_name):\n",
1043-
" try:\n",
1044-
" loc = geolocator.geocode(f\"{point_name}, NY\", timeout=10)\n",
1045-
" return Point(loc.latitude, loc.longitude) if loc else None\n",
1046-
" except Exception:\n",
1047-
" return None\n",
1048-
"\n",
1049-
"boros_df['geometry'] = boros_df.boro_name.apply(get_geo)\n",
1050-
"# Drop any failed geocode attempts before converting to GeoDataFrame\n",
1051-
"boroughs_gdf = gpd.GeoDataFrame(\n",
1052-
" boros_df.dropna(subset=['geometry']), \n",
1053-
" geometry='geometry', \n",
1054-
" crs='EPSG:4326'\n",
1055-
")\n",
1056-
"boroughs_gdf\n"
1028+
"# Nominatim (OpenStreetMap) is the provider here; it requires a user agent\n",
1029+
"boros_df[[\"geometry\", \"address\"]] = gpd.tools.geocode(\n",
1030+
" boros_df.boro_name + \", New York\",\n",
1031+
" provider=\"nominatim\",\n",
1032+
" user_agent=\"coding-for-economists/1.0\",\n",
1033+
" timeout=10,\n",
1034+
").set_geometry(\"geometry\")\n",
1035+
"boros_df"
10571036
]
10581037
},
10591038
{

0 commit comments

Comments
 (0)