### Geocoding request with custom server Source: https://github.com/dieghernan/nominatimlite/blob/main/tests/testthat/_snaps/geo_lite_struct_sf.md Example of a request that fails due to an unreachable server URL. ```R several <- geo_lite_struct_sf("madrid", full_results = TRUE, nominatim_server = "https://api.jsonserver.io/") ``` -------------------------------- ### Install nominatimlite from CRAN Source: https://github.com/dieghernan/nominatimlite/blob/main/README.md Install the stable version of the nominatimlite package from CRAN. ```r install.packages("nominatimlite") ``` -------------------------------- ### Install nominatimlite from r-universe Source: https://github.com/dieghernan/nominatimlite/blob/main/README.md Install the nominatimlite package from the r-universe repository, which may contain more recent versions. ```r install.packages("nominatimlite", repos = c( "https://dieghernan.r-universe.dev", "https://cloud.r-project.org" ) ) ``` -------------------------------- ### Handle Unreachable Server in geo_lite_struct Source: https://github.com/dieghernan/nominatimlite/blob/main/tests/testthat/_snaps/geo_lite_struct.md This example demonstrates how to handle cases where the specified Nominatim server is unreachable. It shows the expected error message when the API endpoint is not accessible. ```R several <- geo_lite_struct("Madrid", full_results = TRUE, nominatim_server = "https://api.jsonserver.io/") ``` -------------------------------- ### Geocoding request failure example Source: https://github.com/dieghernan/nominatimlite/blob/main/tests/testthat/_snaps/geo_lite.md This snippet demonstrates a failed geocoding attempt due to an unreachable server URL. ```R several <- geo_lite("Madrid", full_results = TRUE, nominatim_server = "https://api.jsonserver.io/") ``` -------------------------------- ### Reverse Geocoding with nominatimlite Source: https://github.com/dieghernan/nominatimlite/blob/main/tests/testthat/_snaps/reverse_geo_lite_sf.md Performs a reverse geocoding request using a custom Nominatim server. This example demonstrates a failure scenario when the specified server is unreachable. ```R several <- reverse_geo_lite_sf(40.75728, -73.98, full_results = TRUE, nominatim_server = "https://api.jsonserver.io/") ``` -------------------------------- ### Geo Lite SF Function Call Source: https://github.com/dieghernan/nominatimlite/blob/main/tests/testthat/_snaps/geo_lite_sf.md Example of calling the geo_lite_sf function with a specific server. This snippet demonstrates how to query geographic data and handle potential connection issues. ```R several <- geo_lite_sf("madrid", full_results = TRUE, nominatim_server = "https://api.jsonserver.io/") ``` -------------------------------- ### Reverse Geocoding Request Failure Source: https://github.com/dieghernan/nominatimlite/blob/main/tests/testthat/_snaps/reverse_geo_lite.md Example of a reverse geocoding call that fails due to an unreachable server URL. ```R several <- reverse_geo_lite(40.75728, -73.98, full_results = TRUE, nominatim_server = "https://api.jsonserver.io/") ``` -------------------------------- ### Geocode OSM IDs to sf Objects Source: https://context7.com/dieghernan/nominatimlite/llms.txt Look up OpenStreetMap objects by their IDs and retrieve them as sf objects. Use 'points_only = FALSE' to get detailed geometries like polygons. ```r notre_dame <- geo_address_lookup_sf( osm_ids = 201611261, type = "W" ) ``` ```r notre_dame_poly <- geo_address_lookup_sf( osm_ids = 201611261, type = "W", points_only = FALSE ) ``` ```r ggplot(notre_dame_poly) + geom_sf() ``` ```r objects <- geo_address_lookup_sf( osm_ids = c(146656, 240109189), type = c("R", "N"), # Relation and Node full_results = TRUE ) ``` -------------------------------- ### Check Nominatim API Access with nominatim_check_access Source: https://context7.com/dieghernan/nominatimlite/llms.txt Verifies connectivity to the Nominatim API server, useful for conditional execution. Can check the default server or a custom instance. ```r library(nominatimlite) # Check default OpenStreetMap Nominatim server if (nominatim_check_access()) { result <- geo_lite("London, UK") print(result) } else { message("Nominatim API is not accessible") } ``` ```r # Check custom Nominatim server custom_available <- nominatim_check_access( nominatim_server = "https://my-nominatim-instance.com/" ) ``` -------------------------------- ### Load nominatimlite package Source: https://github.com/dieghernan/nominatimlite/blob/main/README.md Load the nominatimlite package into the R session to use its functions. This is a prerequisite for using any of its geocoding capabilities. ```r library(nominatimlite) ``` -------------------------------- ### Search Amenities with Spatial Output Source: https://context7.com/dieghernan/nominatimlite/llms.txt Retrieves amenities as sf spatial objects, allowing for direct visualization and spatial filtering. ```r library(nominatimlite) library(ggplot2) # Get district boundary usera <- geo_lite_sf("Usera, Madrid, Spain", points_only = FALSE) # Find restaurants, pubs and schools amenities <- geo_amenity_sf( bbox = usera, amenity = c("restaurant", "pub", "school"), limit = 50 ) # Map amenities by type ggplot(usera) + geom_sf() + geom_sf(data = amenities, aes(color = query, shape = query)) # Get polygon geometries for larger amenities schools_poly <- geo_amenity_sf( bbox = usera, amenity = "school", limit = 20, points_only = FALSE, # Get building polygons strict = TRUE ) ``` -------------------------------- ### Free-Form Address Geocoding with geo_lite Source: https://context7.com/dieghernan/nominatimlite/llms.txt Use geo_lite for basic geocoding of single or multiple addresses. Specify `full_results = TRUE` to retrieve all Nominatim data, `return_addresses = TRUE` for full address details, or `custom_query` to filter by country codes. You can also customize column names for latitude and longitude or use a custom Nominatim server. ```r library(nominatimlite) # Basic geocoding - single address result <- geo_lite("1600 Pennsylvania Ave NW, Washington, DC") # Returns tibble with query, lat, lon columns # Geocode multiple addresses addresses <- c("Madrid, Spain", "Barcelona, Spain", "Paris, France") coords <- geo_lite(addresses, progressbar = FALSE) # Get full results with all Nominatim data full_result <- geo_lite( "Eiffel Tower, Paris", full_results = TRUE, return_addresses = TRUE ) # Restrict search to a specific country us_only <- geo_lite( c("Madrid", "Barcelona"), custom_query = list(countrycodes = "US"), full_results = TRUE ) # Custom column names for lat/long custom <- geo_lite( "Tokyo, Japan", lat = "latitude", long = "longitude" ) # Use a custom Nominatim server private_server <- geo_lite( "Berlin, Germany", nominatim_server = "https://my-nominatim-instance.com/" ) ``` -------------------------------- ### Load and Explore OSM Amenity Database Source: https://context7.com/dieghernan/nominatimlite/llms.txt Loads the built-in 'osm_amenities' dataset, which categorizes OpenStreetMap amenity types. Useful for discovering available amenities for geocoding functions. ```r library(nominatimlite) # Load the amenity database data("osm_amenities") # View structure head(osm_amenities) # Columns: category, amenity, comment ``` ```r # Filter by category sustenance <- osm_amenities[osm_amenities$category == "Sustenance", ] # Includes: bar, cafe, restaurant, pub, etc. ``` ```r education <- osm_amenities[osm_amenities$category == "Education", ] # Includes: school, university, library, etc. ``` ```r healthcare <- osm_amenities[osm_amenities$category == "Healthcare", ] # Includes: hospital, clinic, pharmacy, etc. ``` -------------------------------- ### Reverse Geocoding Coordinates to Addresses with reverse_geo_lite Source: https://context7.com/dieghernan/nominatimlite/llms.txt Use reverse_geo_lite to convert latitude and longitude coordinates into addresses. It supports geocoding multiple coordinate pairs simultaneously and allows customization of address column names. The `custom_query` parameter, particularly `zoom` and `extratags`, can control the level of address detail and retrieve additional Nominatim data. ```r library(nominatimlite) # Basic reverse geocoding address <- reverse_geo_lite( lat = 40.75728, long = -73.98586 ) # Returns: Times Square area address # Multiple coordinates at once coords <- reverse_geo_lite( lat = c(40.75728, 55.95335, 48.85889), long = c(-73.98586, -3.188375, 2.32004), progressbar = FALSE ) # Custom address column name result <- reverse_geo_lite( lat = 40.75728, long = -73.98586, address = "address_found" ) # Control zoom level for address detail # zoom = 3 (country), 5 (state), 8 (county), 10 (city), # 14 (suburb), 16-17 (streets), 18 (building) country_level <- reverse_geo_lite( lat = c(40.75728, 55.95335), long = c(-73.98586, -3.188375), custom_query = list(zoom = 3), # Country level full_results = TRUE ) city_level <- reverse_geo_lite( lat = 41.89026, long = 12.49309, custom_query = list(zoom = 10) # City level ) # Get full Nominatim response with extra tags detailed <- reverse_geo_lite( lat = 40.75728, long = -73.98586, custom_query = list(zoom = 0, extratags = TRUE), full_results = TRUE ) ``` -------------------------------- ### Structured Address Search with Spatial Output Source: https://context7.com/dieghernan/nominatimlite/llms.txt Returns sf spatial objects from structured address queries, useful for mapping and polygon retrieval. ```r library(nominatimlite) library(ggplot2) # Search for Plaza Mayor locations in Madrid plazas <- geo_lite_struct_sf( street = "Plaza Mayor", county = "Comunidad de Madrid", country = "Spain", limit = 50, full_results = TRUE ) # Get outline for reference madrid_outline <- geo_lite_sf("Comunidad de Madrid, Spain", points_only = FALSE) # Visualize with different address types ggplot(madrid_outline) + geom_sf() + geom_sf(data = plazas, aes(shape = addresstype, color = addresstype)) # Get polygon geometries for buildings building <- geo_lite_struct_sf( street = "Empire State Building", city = "New York", country = "United States", points_only = FALSE ) ``` -------------------------------- ### Reverse Geocoding with Spatial Output using reverse_geo_lite_sf Source: https://context7.com/dieghernan/nominatimlite/llms.txt Employ reverse_geo_lite_sf to convert coordinates into sf spatial objects, optionally retrieving polygon geometries for buildings and administrative areas by setting `points_only = FALSE`. This function facilitates direct use of reverse geocoding results in spatial analysis and visualization workflows. ```r library(nominatimlite) library(ggplot2) # Coliseum coordinates col_lat <- 41.89026 col_lon <- 12.49309 # Get Coliseum as polygon coliseum <- reverse_geo_lite_sf( lat = col_lat, long = col_lon, points_only = FALSE # Get building polygon ) ggplot(coliseum) + geom_sf() ``` -------------------------------- ### Convert Bounding Box to Polygon using bbox_to_poly Source: https://context7.com/dieghernan/nominatimlite/llms.txt Converts a numeric bounding box vector or named parameters into an sf POLYGON object. Useful for spatial operations and visualization. ```r library(nominatimlite) library(ggplot2) # Bounding box of Germany bbox_germany <- c(5.86631529, 47.27011137, 15.04193189, 55.09916098) germany_poly <- bbox_to_poly(bbox_germany) ggplot(germany_poly) + geom_sf() ``` ```r # Using named parameters custom_bbox <- bbox_to_poly( xmin = -10, ymin = 35, xmax = 5, ymax = 45 ) ``` ```r # Extract bbox from sf object and convert back to polygon seychelles <- geo_lite_sf("seychelles", points_only = FALSE) bbox <- sf::st_bbox(seychelles) bbox_polygon <- bbox_to_poly(bbox) ggplot(bbox_polygon) + geom_sf(fill = "lightblue", alpha = 0.5) + geom_sf(data = seychelles, fill = "wheat") ``` ```r # Specify custom CRS bbox_3857 <- bbox_to_poly(bbox_germany, crs = 3857) ``` -------------------------------- ### Reverse Geocoding with Spatial Output Source: https://context7.com/dieghernan/nominatimlite/llms.txt Performs reverse geocoding to retrieve spatial data for coordinates, allowing for zoom-level control and batch processing. ```r rome <- reverse_geo_lite_sf( lat = col_lat, long = col_lon, custom_query = list(zoom = 10), # City level points_only = FALSE ) ggplot(rome) + geom_sf() ``` ```r landmarks <- reverse_geo_lite_sf( lat = c(48.8584, 40.6892), long = c(2.2945, -74.0445), full_results = TRUE, points_only = FALSE ) ``` -------------------------------- ### Perform a structured geocoding query Source: https://github.com/dieghernan/nominatimlite/blob/main/NEWS.md Use the custom_query argument to pass additional parameters like address details or bounding boxes to the geocoding request. ```r geo_lite(address = "New York", custom_query = list(addressdetails = TRUE, viewbox = c(-60, -20, 60, 20)) ) ``` -------------------------------- ### Reverse Geocode Coordinates with reverse_geo_lite Source: https://github.com/dieghernan/nominatimlite/blob/main/README.md Converts geographic coordinates back into address strings using the reverse_geo_lite function. ```r reverse <- reverse_geo_lite( lat = lat_longs$latitude, long = lat_longs$longitude, address = "address_found", progressbar = FALSE ) ``` -------------------------------- ### OSM Object Lookup by ID Source: https://context7.com/dieghernan/nominatimlite/llms.txt Retrieves details for specific OpenStreetMap objects using their unique ID and type identifier. ```r library(nominatimlite) # Lookup ways by OSM ID (W = Way) ways <- geo_address_lookup( osm_ids = c(46240148, 34633854), type = "W" ) # Mixed types: R = Relation, N = Node mixed <- geo_address_lookup( osm_ids = c(146656, 240109189), type = c("R", "N") ) # Get full details detailed <- geo_address_lookup( osm_ids = 201611261, # Notre Dame Cathedral type = "W", full_results = TRUE ) ``` -------------------------------- ### Geocoding with Spatial Output using geo_lite_sf Source: https://context7.com/dieghernan/nominatimlite/llms.txt Utilize geo_lite_sf to geocode addresses and receive results as sf spatial objects. Set `points_only = FALSE` to obtain polygon geometries for areas or buildings. This function is useful for direct integration with spatial analysis and visualization in R. ```r library(nominatimlite) library(ggplot2) # Basic geocoding returning sf POINT point <- geo_lite_sf("Statue of Liberty, NY, USA") # Get polygon geometry for buildings/areas polygon <- geo_lite_sf( "Statue of Liberty, NY, USA", points_only = FALSE # Returns actual building polygon ) # Visualize the result ggplot(polygon) + geom_sf() # Search for multiple locations with a limit pizza_locations <- geo_lite_sf( "Pizza Hut, California", limit = 50, custom_query = list(countrycodes = "us") ) # Get state boundary as polygon california <- geo_lite_sf("California", points_only = FALSE) # Plot multiple layers ggplot(california) + geom_sf() + geom_sf(data = pizza_locations, col = "red") # Get administrative regions with full details madrid <- geo_lite_sf( "Comunidad de Madrid, Spain", limit = 2, points_only = FALSE, full_results = TRUE ) # Rivers and roads return as LINESTRING ohio_river <- geo_lite_sf("Ohio river", points_only = FALSE) ``` -------------------------------- ### Geocode Addresses with geo_lite Source: https://github.com/dieghernan/nominatimlite/blob/main/README.md Converts a set of addresses into latitude and longitude coordinates using the geo_lite function. ```r library(tibble) # create a dataframe with addresses some_addresses <- tribble( ~name, ~addr, "White House", "1600 Pennsylvania Ave NW, Washington, DC", "Transamerica Pyramid", "600 Montgomery St, San Francisco, CA 94111", "Willis Tower", "233 S Wacker Dr, Chicago, IL 60606" ) # geocode the addresses lat_longs <- geo_lite( some_addresses$addr, lat = "latitude", long = "longitude", progressbar = FALSE ) ``` -------------------------------- ### Search Amenities Within Bounding Box Source: https://context7.com/dieghernan/nominatimlite/llms.txt Finds specific OSM amenities within a defined geographic area, supporting both coordinate-based bounding boxes and sf objects. ```r library(nominatimlite) # Define bounding box: c(xmin, ymin, xmax, ymax) # Times Square area, NYC times_square_bbox <- c( -73.9894467311, 40.75573629, -73.9830630737, 40.75789245 ) # Find restaurants restaurants <- geo_amenity( bbox = times_square_bbox, amenity = "restaurant" ) # Search multiple amenity types food_places <- geo_amenity( bbox = times_square_bbox, amenity = c("restaurant", "pub", "cafe"), limit = 10 ) # Use strict mode to ensure results are inside bbox strict_results <- geo_amenity( bbox = times_square_bbox, amenity = c("restaurant", "pub"), limit = 10, strict = TRUE # Filter results strictly within bbox ) # Use sf object as bounding box california <- geo_lite_sf("California", points_only = FALSE) ca_hospitals <- geo_amenity( bbox = california, amenity = "hospital", limit = 50, full_results = TRUE ) # View available amenity types data("osm_amenities") head(osm_amenities) # Categories: sustenance, education, transportation, financial, healthcare, etc. ``` -------------------------------- ### Extract Spatial Features with nominatimlite Source: https://github.com/dieghernan/nominatimlite/blob/main/README.md Extracts various geographic features such as points, polygons, and lines using geo_lite_sf and visualizes them with ggplot2. ```r CA <- geo_lite_sf("California", points_only = FALSE) pizzahut <- geo_lite_sf( "Pizza Hut, California", limit = 50, custom_query = list(countrycodes = "us") ) library(ggplot2) ggplot(CA) + geom_sf() + geom_sf(data = pizzahut, col = "red") ``` ```r sol_poly <- geo_lite_sf("Statue of Liberty, NY, USA", points_only = FALSE) # a building - a polygon ggplot(sol_poly) + geom_sf() ``` ```r dayton <- geo_lite_sf("Dayton, OH") # default - a point ohio_state <- geo_lite_sf("Ohio, USA", points_only = FALSE) # a US state - a polygon ohio_river <- geo_lite_sf("Ohio river", points_only = FALSE) # a river - a line ggplot() + geom_sf(data = ohio_state) + geom_sf(data = dayton, color = "red", pch = 4) + geom_sf(data = ohio_river, color = "blue") ``` -------------------------------- ### Structured Address Search Source: https://context7.com/dieghernan/nominatimlite/llms.txt Geocodes addresses by splitting them into specific components like street, city, and country for higher precision. ```r library(nominatimlite) # Search by address components result <- geo_lite_struct( street = "Plaza Mayor", country = "Spain", limit = 50, full_results = TRUE ) # City-level search cities <- geo_lite_struct( city = "Springfield", state = "Illinois", country = "United States" ) # Postal code search by_postal <- geo_lite_struct( postalcode = "10001", country = "United States", full_results = TRUE ) # Combined parameters specific <- geo_lite_struct( street = "221B Baker Street", city = "London", country = "United Kingdom" ) # With amenity type cafes <- geo_lite_struct( amenity = "cafe", city = "Paris", country = "France", limit = 10 ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.