--- license: cc-by-4.0 task_categories: - text-generation - text-classification language: - en tags: - geospatial - places - points of interest - poi - location-data - activities - landmarks - venues pretty_name: Places size_categories: - 10K= min_lat) & (df['latitude'] <= max_lat) & (df['longitude'] >= min_lon) & (df['longitude'] <= max_lon) ] # Example: Find places in San Francisco area sf_places = filter_by_bbox(places_with_coords, 37.7, 37.8, -122.5, -122.4) ``` #### Working with Tags ```python # Load all necessary tables places_df = pd.DataFrame(load_dataset("path/to/places_dataset.py", "place")['train']) tags_df = pd.DataFrame(load_dataset("path/to/places_dataset.py", "tag")['train']) place_tags_df = pd.DataFrame(load_dataset("path/to/places_dataset.py", "place_tag")['train']) # Get all tags for a specific place def get_place_tags(place_id): # Find all tag relationships for this place tag_ids = place_tags_df[place_tags_df['place_id'] == place_id]['tag_id'] # Get tag details return tags_df[tags_df['id'].isin(tag_ids)] # Find all places with a specific tag def find_places_by_tag(tag_name): # Find the tag tag = tags_df[tags_df['name'] == tag_name] if tag.empty: return pd.DataFrame() tag_id = tag.iloc[0]['id'] # Find all places with this tag place_ids = place_tags_df[place_tags_df['tag_id'] == tag_id]['place_id'] return places_df[places_df['id'].isin(place_ids)] # Example: Find all coffee shops coffee_shops = find_places_by_tag('Coffee Shop') ``` ### Using the Alternative Loading Function ```python from places_dataset import load_places_as_dict # Load all tables as a dictionary data = load_places_as_dict('/path/to/data/directory') # Access individual tables places = data['place'] locations = data['location'] tags = data['tag'] ``` ### Working with Geospatial Data #### Coordinate System Information - **Latitude/Longitude**: WGS84 (EPSG:4326) - Standard GPS coordinates - **Geom column**: Projected geometry, useful for visualization and area calculations - **Geog column**: Geography type for accurate distance and spatial calculations #### Example: Distance Calculations ```python import math def haversine_distance(lat1, lon1, lat2, lon2): """Calculate distance between two points on Earth in kilometers.""" R = 6371 # Earth's radius in kilometers lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2]) dlat = lat2 - lat1 dlon = lon2 - lon1 a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2 c = 2 * math.asin(math.sqrt(a)) return R * c # Find places near a specific coordinate def find_nearby_places(places_with_coords, center_lat, center_lon, radius_km): nearby = [] for _, place in places_with_coords.iterrows(): distance = haversine_distance( center_lat, center_lon, place['latitude'], place['longitude'] ) if distance <= radius_km: nearby.append({**place.to_dict(), 'distance_km': distance}) return pd.DataFrame(nearby).sort_values('distance_km') # Example: Find places within 5km of a location nearby = find_nearby_places(places_with_coords, 37.7749, -122.4194, 5) ```