<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def route_to_geojson( feed: "Feed", route_id: str, date: Optional[str] = None, *, include_stops: bool = False, ) -> Dict: """ Return a GeoJSON rendering of the route and, optionally, its stops. Parameters feed : Feed route_id : string ID of a route in ``feed.routes`` date : string YYYYMMDD date string restricting the output to trips active on the date include_stops : boolean If ``True``, then include stop features in the result Returns ------- dictionary A decoded GeoJSON feature collection comprising a LineString features of the distinct shapes of the trips on the route. If ``include_stops``, then include one Point feature for each stop on the route. """

    # Get set of unique trip shapes for route
    shapes = (
        feed.get_trips(date=date)
        .loc[lambda x: x["route_id"] == route_id, "shape_id"]
        .unique()
    )
    if not shapes.size:
        return {"type": "FeatureCollection", "features": []}

    geom_by_shape = feed.build_geometry_by_shape(shape_ids=shapes)

    # Get route properties
    route = (
        feed.get_routes(date=date)
        .loc[lambda x: x["route_id"] == route_id]
        .fillna("n/a")
        .to_dict(orient="records", into=OrderedDict)
    )[0]

    # Build route shape features
    features = [
        {
            "type": "Feature",
            "properties": route,
            "geometry": sg.mapping(sg.LineString(geom)),
        }
        for geom in geom_by_shape.values()
    ]

    # Build stop features if desired
    if include_stops:
        stops = (
            feed.get_stops(route_id=route_id)
            .fillna("n/a")
            .to_dict(orient="records", into=OrderedDict)
        )
        features.extend(
            [
                {
                    "type": "Feature",
                    "geometry": {
                        "type": "Point",
                        "coordinates": [stop["stop_lon"], stop["stop_lat"]],
                    },
                    "properties": stop,
                }
                for stop in stops
            ]
        )

    return {"type": "FeatureCollection", "features": features}