79327414

Date: 2025-01-03 18:59:45
Score: 2
Natty:
Report link

I want to remove all the cafe's plots that are far away from Transjakarta's line. I just want to show the cafe that intersects with Transjakarta's line because the radius range is only 200m from Transjakarta's line. How can I do that?

You just need to intersect your cafes' points with a 200-meter buffer around your transit lines.

import osmnx as ox

# get the transit lines near some point
point = (34.05, -118.25)
tags = {"railway": ["light_rail", "subway"]}
gdf_rail = ox.features.features_from_point(point, tags, dist=1500)
bbox = gdf_rail.union_all().envelope
gdf_rail = ox.projection.project_gdf(gdf_rail)

# get the cafes within 200 meters of the transit lines
tags = {"amenity": "cafe"}
gdf_poi = ox.features.features_from_polygon(bbox, tags).to_crs(gdf_rail.crs)
gdf_poi = gdf_poi[gdf_poi.intersects(gdf_rail.union_all().buffer(200))]
gdf_poi.shape

# plot the transit lines and nearby cafes
ax = gdf_rail.plot()
ax = gdf_poi.plot(ax=ax)

How can I show the legend title?

Previously answered at Title for matplotlib legend

Reasons:
  • Blacklisted phrase (0.5): How can I
  • Blacklisted phrase (1): can I do
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • High reputation (-1):
Posted by: gboeing