MCPcopy
hub / github.com/originalankur/maptoposter / create_poster

Function create_poster

create_map_poster.py:216–323  ·  view source on GitHub ↗
(city, country, point, dist, output_file)

Source from the content-addressed store, hash-verified

214 raise ValueError(f"Could not find coordinates for {city}, {country}")
215
216def create_poster(city, country, point, dist, output_file):
217 print(f"\nGenerating map for {city}, {country}...")
218
219 # Progress bar for data fetching
220 with tqdm(total=3, desc="Fetching map data", unit="step", bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt}') as pbar:
221 # 1. Fetch Street Network
222 pbar.set_description("Downloading street network")
223 G = ox.graph_from_point(point, dist=dist, dist_type='bbox', network_type='all')
224 pbar.update(1)
225 time.sleep(0.5) # Rate limit between requests
226
227 # 2. Fetch Water Features
228 pbar.set_description("Downloading water features")
229 try:
230 water = ox.features_from_point(point, tags={'natural': 'water', 'waterway': 'riverbank'}, dist=dist)
231 except:
232 water = None
233 pbar.update(1)
234 time.sleep(0.3)
235
236 # 3. Fetch Parks
237 pbar.set_description("Downloading parks/green spaces")
238 try:
239 parks = ox.features_from_point(point, tags={'leisure': 'park', 'landuse': 'grass'}, dist=dist)
240 except:
241 parks = None
242 pbar.update(1)
243
244 print("✓ All data downloaded successfully!")
245
246 # 2. Setup Plot
247 print("Rendering map...")
248 fig, ax = plt.subplots(figsize=(12, 16), facecolor=THEME['bg'])
249 ax.set_facecolor(THEME['bg'])
250 ax.set_position([0, 0, 1, 1])
251
252 # 3. Plot Layers
253 # Layer 1: Polygons
254 if water is not None and not water.empty:
255 water.plot(ax=ax, facecolor=THEME['water'], edgecolor='none', zorder=1)
256 if parks is not None and not parks.empty:
257 parks.plot(ax=ax, facecolor=THEME['parks'], edgecolor='none', zorder=2)
258
259 # Layer 2: Roads with hierarchy coloring
260 print("Applying road hierarchy colors...")
261 edge_colors = get_edge_colors_by_type(G)
262 edge_widths = get_edge_widths_by_type(G)
263
264 ox.plot_graph(
265 G, ax=ax, bgcolor=THEME['bg'],
266 node_size=0,
267 edge_color=edge_colors,
268 edge_linewidth=edge_widths,
269 show=False, close=False
270 )
271
272 # Layer 3: Gradients (Top and Bottom)
273 create_gradient_fade(ax, THEME['gradient_color'], location='bottom', zorder=10)

Callers 1

Calls 3

get_edge_colors_by_typeFunction · 0.85
get_edge_widths_by_typeFunction · 0.85
create_gradient_fadeFunction · 0.85

Tested by

no test coverage detected