0
# OpenStreetMap Integration
1
2
Direct integration with OpenStreetMap data through the Overpass API, enabling querying and visualization of OSM data by address, place, bounding box, or point with comprehensive tag-based filtering and export capabilities.
3
4
## Capabilities
5
6
### OSM Data Query by Location
7
8
Query OpenStreetMap data using various location-based approaches with comprehensive tag filtering for targeted data extraction.
9
10
```python { .api }
11
def osm_gdf_from_address(address, tags, **kwargs):
12
"""
13
Get OSM data for features near an address.
14
15
Args:
16
address (str): Address to geocode and search around
17
tags (dict): OSM tags to filter by (e.g., {'building': True})
18
**kwargs: Query options (distance, timeout, etc.)
19
20
Returns:
21
gpd.GeoDataFrame: OSM features as GeoDataFrame
22
"""
23
24
def osm_gdf_from_place(place, tags, **kwargs):
25
"""
26
Get OSM data within a named place boundary.
27
28
Args:
29
place (str): Place name to search within
30
tags (dict): OSM tags to filter by
31
**kwargs: Query options (which_result, timeout, etc.)
32
33
Returns:
34
gpd.GeoDataFrame: OSM features as GeoDataFrame
35
"""
36
37
def osm_gdf_from_point(point, tags, distance=1000, **kwargs):
38
"""
39
Get OSM data around a specific point.
40
41
Args:
42
point (tuple): (latitude, longitude) coordinates
43
tags (dict): OSM tags to filter by
44
distance (float): Search radius in meters
45
**kwargs: Query options (timeout, etc.)
46
47
Returns:
48
gpd.GeoDataFrame: OSM features as GeoDataFrame
49
"""
50
51
def osm_gdf_from_bbox(bbox, tags, **kwargs):
52
"""
53
Get OSM data within a bounding box.
54
55
Args:
56
bbox (list): Bounding box [minx, miny, maxx, maxy]
57
tags (dict): OSM tags to filter by
58
**kwargs: Query options (timeout, etc.)
59
60
Returns:
61
gpd.GeoDataFrame: OSM features as GeoDataFrame
62
"""
63
```
64
65
### OSM Data Export
66
67
Export OSM data directly to various file formats for use in external applications and analysis workflows.
68
69
```python { .api }
70
def osm_shp_from_address(address, tags, filename, **kwargs):
71
"""
72
Export OSM data near address to shapefile.
73
74
Args:
75
address (str): Address to search around
76
tags (dict): OSM tags to filter by
77
filename (str): Output shapefile path
78
**kwargs: Export options (distance, etc.)
79
80
Returns:
81
str: Path to created shapefile
82
"""
83
84
def osm_shp_from_place(place, tags, filename, **kwargs):
85
"""
86
Export OSM data from place to shapefile.
87
88
Args:
89
place (str): Place name to search within
90
tags (dict): OSM tags to filter by
91
filename (str): Output shapefile path
92
**kwargs: Export options
93
94
Returns:
95
str: Path to created shapefile
96
"""
97
98
def osm_shp_from_bbox(bbox, tags, filename, **kwargs):
99
"""
100
Export OSM data from bounding box to shapefile.
101
102
Args:
103
bbox (list): Bounding box coordinates
104
tags (dict): OSM tags to filter by
105
filename (str): Output shapefile path
106
**kwargs: Export options
107
108
Returns:
109
str: Path to created shapefile
110
"""
111
112
def osm_geojson_from_address(address, tags, filename, **kwargs):
113
"""
114
Export OSM data near address to GeoJSON.
115
116
Args:
117
address (str): Address to search around
118
tags (dict): OSM tags to filter by
119
filename (str): Output GeoJSON path
120
**kwargs: Export options (distance, etc.)
121
122
Returns:
123
str: Path to created GeoJSON file
124
"""
125
126
def osm_geojson_from_place(place, tags, filename, **kwargs):
127
"""
128
Export OSM data from place to GeoJSON.
129
130
Args:
131
place (str): Place name to search within
132
tags (dict): OSM tags to filter by
133
filename (str): Output GeoJSON path
134
**kwargs: Export options
135
136
Returns:
137
str: Path to created GeoJSON file
138
"""
139
140
def osm_geojson_from_bbox(bbox, tags, filename, **kwargs):
141
"""
142
Export OSM data from bounding box to GeoJSON.
143
144
Args:
145
bbox (list): Bounding box coordinates
146
tags (dict): OSM tags to filter by
147
filename (str): Output GeoJSON path
148
**kwargs: Export options
149
150
Returns:
151
str: Path to created GeoJSON file
152
"""
153
```
154
155
### OSM Tag Management
156
157
Discover and work with OpenStreetMap tags for comprehensive data filtering and feature selection.
158
159
```python { .api }
160
def osm_tags_list():
161
"""
162
Get list of common OSM tags and their descriptions.
163
164
Returns:
165
dict: Dictionary of OSM tags with descriptions and common values
166
"""
167
168
def osm_tag_info(tag_key):
169
"""
170
Get detailed information about specific OSM tag.
171
172
Args:
173
tag_key (str): OSM tag key (e.g., 'building', 'highway')
174
175
Returns:
176
dict: Tag information including common values and usage
177
"""
178
179
def validate_osm_tags(tags):
180
"""
181
Validate OSM tag dictionary for proper formatting.
182
183
Args:
184
tags (dict): OSM tags to validate
185
186
Returns:
187
bool: True if tags are valid, False otherwise
188
"""
189
```
190
191
### Map Integration
192
193
Add OSM data directly to maps with automatic styling and interactive features.
194
195
```python { .api }
196
def add_osm_from_address(self, address, tags, **kwargs):
197
"""
198
Add OSM data near address to map.
199
200
Args:
201
address (str): Address to search around
202
tags (dict): OSM tags to filter by
203
**kwargs: Map layer options (style, popup, layer_name, etc.)
204
"""
205
206
def add_osm_from_place(self, place, tags, **kwargs):
207
"""
208
Add OSM data from place to map.
209
210
Args:
211
place (str): Place name to search within
212
tags (dict): OSM tags to filter by
213
**kwargs: Map layer options
214
"""
215
216
def add_osm_from_point(self, point, tags, distance=1000, **kwargs):
217
"""
218
Add OSM data around point to map.
219
220
Args:
221
point (tuple): (latitude, longitude) coordinates
222
tags (dict): OSM tags to filter by
223
distance (float): Search radius in meters
224
**kwargs: Map layer options
225
"""
226
227
def add_osm_from_bbox(self, bbox, tags, **kwargs):
228
"""
229
Add OSM data from bounding box to map.
230
231
Args:
232
bbox (list): Bounding box coordinates
233
tags (dict): OSM tags to filter by
234
**kwargs: Map layer options
235
"""
236
```
237
238
## Common OSM Tags
239
240
### Building and Infrastructure
241
242
```python { .api }
243
# Building tags
244
building_tags = {
245
'building': True, # All buildings
246
'building': 'residential', # Residential buildings
247
'building': 'commercial', # Commercial buildings
248
'building': 'industrial', # Industrial buildings
249
'building': ['house', 'apartment'] # Specific building types
250
}
251
252
# Infrastructure tags
253
infrastructure_tags = {
254
'amenity': 'hospital', # Hospitals
255
'amenity': 'school', # Schools
256
'amenity': 'restaurant', # Restaurants
257
'tourism': 'hotel', # Hotels
258
'shop': True # All shops
259
}
260
```
261
262
### Transportation
263
264
```python { .api }
265
# Highway/road tags
266
highway_tags = {
267
'highway': True, # All roads
268
'highway': 'primary', # Primary roads
269
'highway': 'secondary', # Secondary roads
270
'highway': ['trunk', 'primary'], # Major roads
271
'railway': 'rail', # Railways
272
'railway': 'subway' # Subway lines
273
}
274
275
# Public transport
276
transport_tags = {
277
'public_transport': 'stop_position', # Transit stops
278
'amenity': 'bus_station', # Bus stations
279
'railway': 'station', # Train stations
280
'aeroway': 'aerodrome' # Airports
281
}
282
```
283
284
### Natural Features
285
286
```python { .api }
287
# Water features
288
water_tags = {
289
'natural': 'water', # Water bodies
290
'waterway': 'river', # Rivers
291
'waterway': 'stream', # Streams
292
'landuse': 'reservoir' # Reservoirs
293
}
294
295
# Land cover
296
landcover_tags = {
297
'natural': 'forest', # Forests
298
'landuse': 'grass', # Grassland
299
'natural': 'scrub', # Scrubland
300
'landuse': 'farmland' # Agricultural land
301
}
302
```
303
304
### Administrative Boundaries
305
306
```python { .api }
307
# Boundary tags
308
boundary_tags = {
309
'boundary': 'administrative', # Administrative boundaries
310
'admin_level': '2', # Country boundaries
311
'admin_level': '4', # State/province boundaries
312
'admin_level': '6', # County boundaries
313
'admin_level': '8' # City boundaries
314
}
315
316
# Places
317
place_tags = {
318
'place': 'city', # Cities
319
'place': 'town', # Towns
320
'place': 'village', # Villages
321
'place': 'neighbourhood' # Neighborhoods
322
}
323
```
324
325
## Usage Examples
326
327
### Basic OSM Data Query
328
329
```python
330
import leafmap
331
332
# Get buildings around an address
333
buildings = leafmap.osm_gdf_from_address(
334
address='Times Square, New York, NY',
335
tags={'building': True},
336
distance=500 # 500 meter radius
337
)
338
339
print(f"Found {len(buildings)} buildings")
340
341
# Display on map
342
m = leafmap.Map(center=[40.7580, -73.9855], zoom=16)
343
m.add_gdf(buildings,
344
layer_name='Buildings',
345
style={'fillColor': 'red', 'fillOpacity': 0.5})
346
m
347
```
348
349
### Transportation Network Analysis
350
351
```python
352
import leafmap
353
354
# Get road network for a city
355
roads = leafmap.osm_gdf_from_place(
356
place='Cambridge, Massachusetts, USA',
357
tags={'highway': ['primary', 'secondary', 'trunk', 'residential']}
358
)
359
360
# Get transit stops
361
transit = leafmap.osm_gdf_from_place(
362
place='Cambridge, Massachusetts, USA',
363
tags={'public_transport': 'stop_position'}
364
)
365
366
# Visualize transportation network
367
m = leafmap.Map(center=[42.3601, -71.0942], zoom=13)
368
369
m.add_gdf(roads,
370
layer_name='Roads',
371
style={'color': 'blue', 'weight': 2})
372
373
m.add_gdf(transit,
374
layer_name='Transit Stops',
375
style={'color': 'red', 'radius': 5})
376
377
m
378
```
379
380
### Land Use Analysis
381
382
```python
383
import leafmap
384
385
# Define bounding box for study area
386
bbox = [-122.52, 37.70, -122.35, 37.82] # San Francisco area
387
388
# Get different land use types
389
parks = leafmap.osm_gdf_from_bbox(
390
bbox=bbox,
391
tags={'leisure': 'park'}
392
)
393
394
water = leafmap.osm_gdf_from_bbox(
395
bbox=bbox,
396
tags={'natural': 'water'}
397
)
398
399
buildings = leafmap.osm_gdf_from_bbox(
400
bbox=bbox,
401
tags={'building': True}
402
)
403
404
# Create land use map
405
m = leafmap.Map(center=[37.76, -122.44], zoom=12)
406
407
m.add_gdf(water,
408
layer_name='Water Bodies',
409
style={'fillColor': 'blue', 'fillOpacity': 0.7})
410
411
m.add_gdf(parks,
412
layer_name='Parks',
413
style={'fillColor': 'green', 'fillOpacity': 0.5})
414
415
m.add_gdf(buildings,
416
layer_name='Buildings',
417
style={'fillColor': 'gray', 'fillOpacity': 0.3})
418
419
m
420
```
421
422
### POI (Points of Interest) Discovery
423
424
```python
425
import leafmap
426
427
# Get restaurants around a point
428
restaurants = leafmap.osm_gdf_from_point(
429
point=(40.7589, -73.9851), # Times Square
430
tags={'amenity': 'restaurant'},
431
distance=1000
432
)
433
434
# Get hotels
435
hotels = leafmap.osm_gdf_from_point(
436
point=(40.7589, -73.9851),
437
tags={'tourism': 'hotel'},
438
distance=1000
439
)
440
441
# Get attractions
442
attractions = leafmap.osm_gdf_from_point(
443
point=(40.7589, -73.9851),
444
tags={'tourism': 'attraction'},
445
distance=1000
446
)
447
448
# Create POI map
449
m = leafmap.Map(center=[40.7589, -73.9851], zoom=15)
450
451
m.add_gdf(restaurants,
452
layer_name='Restaurants',
453
popup=['name', 'cuisine'],
454
style={'color': 'red', 'radius': 5})
455
456
m.add_gdf(hotels,
457
layer_name='Hotels',
458
popup=['name', 'stars'],
459
style={'color': 'blue', 'radius': 7})
460
461
m.add_gdf(attractions,
462
layer_name='Attractions',
463
popup=['name', 'tourism'],
464
style={'color': 'green', 'radius': 8})
465
466
m
467
```
468
469
### Export OSM Data
470
471
```python
472
import leafmap
473
474
# Export buildings to shapefile
475
leafmap.osm_shp_from_place(
476
place='Boston, Massachusetts, USA',
477
tags={'building': True},
478
filename='boston_buildings.shp'
479
)
480
481
# Export roads to GeoJSON
482
leafmap.osm_geojson_from_bbox(
483
bbox=[-71.12, 42.35, -71.05, 42.37],
484
tags={'highway': ['primary', 'secondary', 'trunk']},
485
filename='boston_roads.geojson'
486
)
487
488
print("OSM data exported successfully")
489
```
490
491
### Advanced Tag Usage
492
493
```python
494
import leafmap
495
496
# Complex tag queries
497
complex_tags = {
498
'amenity': ['restaurant', 'cafe', 'bar'], # Multiple values
499
'building': True, # Any building
500
'name': '*' # Must have a name
501
}
502
503
# Query with multiple conditions
504
results = leafmap.osm_gdf_from_place(
505
place='Greenwich Village, New York, NY',
506
tags=complex_tags
507
)
508
509
# Conditional tags (restaurants with outdoor seating)
510
outdoor_dining = leafmap.osm_gdf_from_place(
511
place='Greenwich Village, New York, NY',
512
tags={
513
'amenity': 'restaurant',
514
'outdoor_seating': 'yes'
515
}
516
)
517
518
# Map results
519
m = leafmap.Map(center=[40.7335, -74.0027], zoom=15)
520
m.add_gdf(outdoor_dining,
521
layer_name='Outdoor Dining',
522
popup=['name', 'cuisine', 'outdoor_seating'])
523
m
524
```
525
526
## Query Options
527
528
### Distance and Spatial Options
529
530
```python
531
query_options = {
532
'distance': 1000, # Search radius in meters
533
'timeout': 300, # Query timeout in seconds
534
'which_result': 1, # Which geocoding result to use
535
'buffer': 100 # Additional buffer around area
536
}
537
```
538
539
### Data Processing Options
540
541
```python
542
processing_options = {
543
'retain_all': False, # Keep all OSM attributes
544
'complement': False, # Complement of the query
545
'custom_filter': None # Custom Overpass filter
546
}
547
```
548
549
### Export Options
550
551
```python
552
export_options = {
553
'driver': 'ESRI Shapefile', # Output format driver
554
'crs': 'EPSG:4326', # Coordinate reference system
555
'encoding': 'utf-8' # Text encoding
556
}
557
```
558
559
## OSM Data Structure
560
561
### Attribute Information
562
563
OSM data includes rich attribute information:
564
- **name**: Feature name
565
- **addr:street**, **addr:housenumber**: Address information
566
- **phone**, **website**: Contact information
567
- **opening_hours**: Operating hours
568
- **capacity**: Capacity information
569
- **operator**: Operating organization
570
571
### Geometry Types
572
573
OSM features come in different geometry types:
574
- **Points**: POIs, addresses, nodes
575
- **Lines**: Roads, rivers, boundaries
576
- **Polygons**: Buildings, parks, administrative areas
577
- **Relations**: Complex features with multiple parts
578
579
### Quality Considerations
580
581
- **Data completeness**: Varies by region and feature type
582
- **Update frequency**: Community-driven, varies by area
583
- **Attribute consistency**: Tag usage may vary between contributors
584
- **Licensing**: Open Database License (ODbL)