# Fetching OSM roads

## Overview

`fetch_osm_roads()` provides a lightweight wrapper around osmdata that returns a road-line `sf` object you can pass directly into the rest of the `trafficCAR` workflow. It accepts either a place name (geocoded to a bounding box) or explicit bounding-box coordinates. Note that `fetch_osm_roads()` requires the osmdata package.

## Fetch by place name

    library(trafficCAR)

    # Query a place name (uses osmdata::getbb() under the hood)
    roads_sf <- fetch_osm_roads("College Station, TX")

    segments <- roads_to_segments(roads_sf)
    net <- build_network(segments)

## Fetch by bounding box

    library(trafficCAR)

    # xmin, ymin, xmax, ymax
    bbox <- c(-96.38, 30.59, -96.33, 30.63)
    roads_sf <- fetch_osm_roads(bbox)

    segments <- roads_to_segments(roads_sf)
    net <- build_network(segments)

## Filtering the OSM query

You can refine the query by passing highway values or additional tags.

    roads_sf <- fetch_osm_roads(
      "College Station, TX",
      value = c("primary", "secondary"),
      extra_tags = list(surface = "asphalt")
    )