寻找长春的酒吧——获取任意城市的POI(AOI),不用再为收集不到POI数据发愁……

来到新的城市游玩,第一件事找喝酒的地方。我需要快速了解该城市的酒吧分布情况。正好前一段时间写了一篇使用R语言获取OSM数据的教程。今天就进行一个实践:找到吉林省长春市的酒吧,冲冲冲!

R语言中的osmdata 包提供有关全球各种空间属性和对象的空间数据。下面贴出可获取的各类数据:


##   [1] "4wd_only"                    "abandoned"                  
##   [3] "abutters"                    "access"                     
##   [5] "addr"                        "addr:city"                  
##   [7] "addr:conscriptionnumber"     "addr:country"               
##   [9] "addr:county"                 "addr:district"              
##  [11] "addr:flats"                  "addr:full"                  
##  [13] "addr:hamlet"                 "addr:housename"             
##  [15] "addr:housenumber"            "addr:inclusion"             
##  [17] "addr:interpolation"          "addr:place"                 
##  [19] "addr:postbox"                "addr:postcode"              
##  [21] "addr:province"               "addr:state"                 
##  [23] "addr:street"                 "addr:subdistrict"           
##  [25] "addr:suburb"                 "addr:unit"                  
##  [27] "admin_level"                 "aeroway"                    
##  [29] "agricultural"                "alt_name"                   
##  [31] "amenity"                     "area"                       
##  [33] "atv"                         "backward"                   
##  [35] "barrier"                     "basin"                      
##  [37] "bdouble"                     "bicycle"                    
##  [39] "bicycle_road"                "biergarten"                 
##  [41] "boat"                        "border_type"                
##  [43] "boundary"                    "brand"                      
##  [45] "bridge"                      "building"                   
##  [47] "building:colour"             "building:fireproof"         
##  [49] "building:flats"              "building:levels"            
##  [51] "building:material"           "building:min_level"         
##  [53] "building:part"               "building:soft_storey"       
##  [55] "bus_bay"                     "busway"                     
##  [57] "capacity"                    "castle_type"                
##  [59] "change"                      "charge"                     
##  [61] "clothes"                     "construction"               
##  [63] "construction#Railways"       "covered"                    
##  [65] "craft"                       "crossing"                   
##  [67] "crossing:island"             "cuisine"                    
##  [69] "cutting"                     "cycleway"                   
##  [71] "denomination"                "destination"                
##  [73] "diet"                        "direction"                  
##  [75] "dispensing"                  "disused"                    
##  [77] "drinking_water"              "drive_in"                   
##  [79] "drive_through"               "ele"                        
##  [81] "electric_bicycle"            "electrified"                
##  [83] "embankment"                  "embedded_rails"             
##  [85] "emergency"                   "end_date"                   
##  [87] "entrance"                    "est_width"                  
##  [89] "fee"                         "female"                     
##  [91] "fire_object:type"            "fire_operator"              
##  [93] "fire_rank"                   "foot"                       
##  [95] "footway"                     "ford"                       
##  [97] "forestry"                    "forward"                    
##  [99] "frequency"                   "fuel"                       
## [101] "gauge"                       "golf_cart"                  
## [103] "goods"                       "hazard"                     
## [105] "hazmat"                      "healthcare"                 
## [107] "healthcare:counselling"      "healthcare:speciality"      
## [109] "height"                      "hgv"                        
## [111] "highway"                     "historic"                   
## [113] "horse"                       "hot_water"                  
## [115] "ice_road"                    "incline"                    
## [117] "industrial"                  "inline_skates"              
## [119] "inscription"                 "int_name"                   
## [121] "internet_access"             "junction"                   
## [123] "kerb"                        "landuse"                    
## [125] "lanes"                       "lanes:bus"                  
## [127] "lanes:psv"                   "layer"                      
## [129] "leaf_cycle"                  "leaf_type"                  
## [131] "leisure"                     "lhv"                        
## [133] "lit"                         "loc_name"                   
## [135] "location"                    "male"                       
## [137] "man_made"                    "max_age"                    
## [139] "max_level"                   "maxaxleload"                
## [141] "maxheight"                   "maxlength"                  
## [143] "maxspeed"                    "maxstay"                    
## [145] "maxweight"                   "maxwidth"                   
## [147] "military"                    "min_age"                    
## [149] "min_level"                   "minspeed"                   
## [151] "mofa"                        "moped"                      
## [153] "motor_vehicle"               "motorboat"                  
## [155] "motorcar"                    "motorcycle"                 
## [157] "motorroad"                   "mountain_pass"              
## [159] "mtb:description"             "mtb:scale"                  
## [161] "name"                        "name:left"                  
## [163] "name:right"                  "name_1"                     
## [165] "name_2"                      "narrow"                     
## [167] "nat_name"                    "natural"                    
## [169] "noexit"                      "non_existent_levels"        
## [171] "nudism"                      "office"                     
## [173] "official_name"               "old_name"                   
## [175] "oneway"                      "opening_hours"              
## [177] "opening_hours:drive_through" "operator"                   
## [179] "orientation"                 "oven"                       
## [181] "overtaking"                  "parking"                    
## [183] "parking:condition"           "parking:lane"               
## [185] "passing_places"              "place"                      
## [187] "power"                       "power_supply"               
## [189] "priority"                    "priority_road"              
## [191] "produce"                     "proposed"                   
## [193] "protected_area"              "psv"                        
## [195] "public_transport"            "railway"                    
## [197] "railway:preserved"           "railway:track_ref"          
## [199] "recycling_type"              "ref"                        
## [201] "reg_name"                    "religion"                   
## [203] "rental"                      "residential"                
## [205] "roadtrain"                   "route"                      
## [207] "sac_scale"                   "sauna"                      
## [209] "service"                     "service_times"              
## [211] "shelter_type"                "shop"                       
## [213] "short_name"                  "shower"                     
## [215] "sidewalk"                    "site"                       
## [217] "ski"                         "smoothness"                 
## [219] "social_facility"             "sorting_name"               
## [221] "speed_pedelec"               "start_date"                 
## [223] "step_count"                  "substation"                 
## [225] "surface"                     "tactile_paving"             
## [227] "tank"                        "tidal"                      
## [229] "toilets"                     "toilets:wheelchair"         
## [231] "toll"                        "topless"                    
## [233] "tourism"                     "tracks"                     
## [235] "tracktype"                   "traffic_calming"            
## [237] "traffic_sign"                "trail_visibility"           
## [239] "trailblazed"                 "trailblazed:visibility"     
## [241] "tunnel"                      "turn"                       
## [243] "type"                        "unisex"                     
## [245] "usage"                       "vehicle"                    
## [247] "vending"                     "voltage"                    
## [249] "water"                       "wheelchair"                 
## [251] "wholesale"                   "width"                      
## [253] "winter_road"                 "wood"

我们今天想获取的是长春市的酒吧(bar),它属于"amenity"类别。我们开始编码:

第一步需要做的是获取长春市的经纬度边界信息

#导入OSMdata和处理矢量数据的包
library(osmdata)
library(sf)
# 导入长春市的矢量边界数据,数据格式是shp
zh = st_read("E:/Arcgis 地图资源/市县/市县/长春市.shp")
#获取边界信息
bb = st_bbox(zh)
bb
# bb = st_bbox(zh)
# bb
#     xmin      ymin      xmax      ymax 
 124.01570  43.16146 127.09373  45.25250 

现在长春市的边界数据拿到了,这个范围的所有酒吧别想跑了。我们直接写代码让它们无所遁形

#bar酒吧
cc_bar <- opq (bbox = c (124.01570,43.16146,127.09373,45.25250 )) %>% # 
  add_osm_feature(key = "amenity", value = "bar") %>%
  osmdata_sf ()
#下面开始可视化
library(ggplot2)
map = ggplot()+
  geom_sf(data = zh)+
  geom_sf(data = cc_bar$osm_points, inherit.aes = FALSE, color = "#ffbe7f", size = .8, alpha = .8)
map
#保存到本地
ccb = cc_bar$osm_points
st_write(ccb, "G:/R/mk/ccbar.gpkg")

 下面就是结果,看起来不是很多啊,有没有小伙伴证实一下。

图片

我们在QGIS中打开看一下数据是否正常,看起来不错,名字都挺不错的。

那么到这里我们就获取了长春市的bar数据,其实其他类别的数据也可以轻松的获得,比如学校,银行,医院,餐厅等,下面给出代码:

#学校
cc_scholl <- opq (bbox = c (124.01570,43.16146,127.09373,45.25250 )) %>% # 
  add_osm_feature(key = "amenity", value = "school") %>%
  osmdata_sf ()
#餐厅
cc_restaurant <- opq (bbox = c (124.01570,43.16146,127.09373,45.25250 )) %>% # 
  add_osm_feature(key = "amenity", value = "restaurant") %>%
  osmdata_sf ()
#银行
cc_bank <- opq (bbox = c (124.01570,43.16146,127.09373,45.25250 )) %>% # 
  add_osm_feature(key = "amenity", value = "bank") %>%
  osmdata_sf ()
#医院
cc_hosiptal <- opq (bbox = c (124.01570,43.16146,127.09373,45.25250 )) %>% # 
  add_osm_feature(key = "amenity", value = "hospital") %>%
  osmdata_sf ()

 

 

在这个被冰雪覆盖的季节里,长春的每一条街道,每一座建筑,都似乎在诉说着它独特的故事。城市的灯火阑珊处,隐藏着无数的温馨与感动………

大家如果觉得这篇有用的话,多多点赞转发支持一下,祝大家一切顺利!我是加拿大一枝黄花,我们下期见。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梧桐GIS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值