[Sưu tầm] Cách cài đặt PrettyMaps
Hồm trước mình có giới thiệu cái tool tạo bản đồ nghệ thuật - map art ở đây
https://dothanhlong.org/suu-tam-prettymaps-tool-tao-map-art/
Hôm nay tình cờ lại thấy có bạn chia sẻ kỹ hơn, nên sưu tầm lại đây, dành cho ai có hứng thú thì làm theo 😛
Nguồn:
- https://github.com/tructransecure/prettymaps.vietnam
- https://www.facebook.com/groups/j2team.community/posts/1682561665409280/
Công cụ tạo bản đồ đặc biệt sử dụng các thư viện Python kết hợp dữ liệu từ OpenStreetMap
Hướng dẫn cài đặt trên hệ điều hành Ubuntu 21.04 x64
Chuẩn bị
sudo apt update && sudo apt upgrade
sudo apt install git
sudo apt install python3-pip
sudo pip install --upgrade pip
sudo pip install --upgrade setuptools
Cài đặt PrettyMaps
cd home
sudo pip install git+https://github.com/abey79/vsketch#egg=vsketch --no-warn-script-location
sudo pip install git+https://github.com/marceloprates/prettymaps.git... --no-warn-script-location
sudo mkdir ../prints
sudo mkdir ../assets
sudo mkdir ../assets/Permanent_Marker
sudo wget -O ../assets/Permanent_Marker/PermanentMarker-Regular.ttf https://github.com/.../Perman.../PermanentMarker-Regular.ttf
Sau khi cài đặt hoàn tất thì mọi người sẵn sàng để tùy biến bản đồ thông qua các code mẫu (python) có sẵn trong repo github
Lưu ý:
Để có thể thể hiện phần biển và các thành phần liên quan cần thiết bổ sung thư viện "water-polygons-split" có thể được tải về từ link sau
https://osmdata.openstreetmap.de/download/water-polygons-split-4326.zip
Code mẫu
#
#Khai báo các tham số hệ thống và gọi thư viện
#
import sys
sys.path.append('../')
import vsketch
from prettymaps import *
import matplotlib.font_manager as fm
from matplotlib import pyplot as plt
#
#Thông tin chung
#
palette = ['#FFC857', '#E9724C', '#C5283D']
#
#Thiết lập tham số
#
fig, ax = plt.subplots(figsize = (20, 20), constrained_layout = True)
backup = plot(
#
#Tọa độ vị trí trên Google Maps hoặc tên địa điểm kèm bán kính (tính bằng mét)
#Nếu trong quá trình xử lý bị "Killed" thì giảm bán kính lại nhỏ hơn
#
(10.7744704,106.7019512), radius = 1000,
ax = ax,
layers = {
'perimeter': {},
'streets': {
'width': {
'motorway': 5,
'trunk': 5,
'primary': 4.5,
'secondary': 4,
'tertiary': 3.5,
'residential': 3,
'living_street': 2,
'pedestrian': 1,
'footway': 1,
'track': 1,
'bridleway': 1
}
},
#
#Tùy biến các tham số tag theo tài liệu hướng dẫn của OpenStreetMaps để phù hợp các lớp địa hình
#
'building': {'tags': {'building': True, 'landuse': 'construction'}, 'union': False},
'water': {'tags': {'natural': ['water','lake'],'waterway':['river','riverbank','canal','lagoon']}},
'green': {'tags': {'landuse': ['grass','farmland','farmyard','reservoir','forest'], 'natural': ['island', 'wood'], 'leisure': 'park'}},
'scrub': {'tags': {'natural': 'scrub'}},
'walls': {'tags': {'manmade': 'embankment'}},
},
#
#Thiết lập màu sắc cho các layer đã tùy biến
#
drawing_kwargs = {
'background': {'fc': '#000080', 'ec': '#dadbc1', 'hatch': 'ooo...', 'zorder': -1},
'perimeter': {'fc': '#F2F4CB', 'ec': '#dadbc1', 'lw': 0, 'hatch': 'ooo...', 'zorder': 0},
'green': {'fc': '#D0F1BF', 'ec': '#2F3737', 'hatch_c': '#b3cfa5', 'hatch': 'ooo...', 'lw': 1, 'zorder': 1},
'scrub': {'fc': '#89d689', 'ec': '#2F3737', 'hatch_c': '#75bd75', 'hatch': 'ooo...', 'lw': 1, 'zorder': 1},
'water': {'fc': '#a1e3ff', 'ec': '#2F3737', 'lw': 1, 'zorder': 2},
'streets': {'fc': '#2F3737', 'ec': '#475657', 'alpha': 1, 'lw': 0, 'zorder': 3},
'walls': {'fc': '#2F3737', 'ec': '#475657', 'alpha': 1, 'lw': 0, 'zorder': 3},
'building': {'palette': palette, 'ec': '#2F3737', 'lw': .5, 'zorder': 4},
},
osm_credit = {'color': '#2F3737'}
)
#
#Lưu bản đồ ra tập tin ảnh & vector
#
plt.savefig('/home/tructt/sg.png')
plt.savefig('/home/tructt/sg.svg')
Thành phố Huế
Sài Gòn
Credit: marceloprates/prettymaps
Code mẫu
City sample with sea
#
#Khai báo các tham số hệ thống và gọi thư viện
#
from prettymaps import *
from matplotlib import pyplot as plt
def postprocessing(layers):
layers['perimeter'] = layers['perimeter'].buffer(10)
return layers
#
#Thông tin chung
#
palette = ['#FFC857', '#E9724C', '#C5283D']
dilate = 100
circle=False
#
#Thiết lập tham số
#
figsize=(20,20)
fig, ax = plt.subplots(figsize = figsize, constrained_layout = True)
# Plot
layers = plot(
#
#Tọa độ vị trí trên Google Maps hoặc tên địa điểm kèm bán kính (tính bằng mét)
#Nếu trong quá trình xử lý bị "Killed" thì giảm bán kính lại nhỏ hơn
#
(16.0493665,108.2166648),
radius=8000,
ax = ax,
layers = {
'perimeter': {'circle': circle, 'dilate': dilate},
'streets': {
'width': {
'motorway': 5,
'trunk': 5,
'primary': 4.5,
'secondary': 4,
'tertiary': 3.5,
'residential': 3,
'living_street': 2,
'pedestrian': 1,
'footway': 1,
'track': 1,
'bridleway': 4
}
},
#
#Tùy biến các tham số tag theo tài liệu hướng dẫn của OpenStreetMaps để phù hợp các lớp địa hình
#
'building': {'tags': {'building': True, 'building':['home','house','family_house','residential','apartments','detached','villa','manor'],'landuse': ['construction','retail','industrial','commercial','education','port','depot']}, 'union': False},
'water': {'tags': {'natural': ['water','lake','river','bay','habour','marina'],'waterway':['river','riverbank','canal','lagoon']}},
'sea': {'tags': {'natural':['coastline','bay','shoal','beach','marina','sea','habour','ocean'],'place':['sea','ocean']}},
'green': {'tags': {'landuse': ['grass','farmland','farmyard','reservoir','forest','allotments','flowerbed','meadow','orchard','greenfield'], 'natural': ['island', 'wood','forest','tree','tree_row'],'leisure': ['park','beach_resort','garden','golf_course','nature_reserve']}},
'scrub': {'tags': {'natural': ['scrub','sand','dune','hill']}},
'walls': {'tags': {'manmade': 'embankment'}},
#
#Giải nén tập tin water_polygons.shp để thiết lập đường dẫn phù hợp
#
'coastline': {'file_location':'/home/tructt/Desktop/Maps.BH/MapData/water/water_polygons.shp','buffer':100000,'circle':circle },
},
#
#Thiết lập màu sắc cho các layer đã tùy biến
#
drawing_kwargs = {
'background': {'fc': '#274e13', 'ec': '#c27ba0', 'hatch': 'ooo...', 'zorder': -1},
'perimeter': {'fc': '#F2F4CB', 'ec': '#dadbc1', 'lw': 0, 'hatch': 'ooo...', 'zorder': 0},
'green': {'fc': '#D0F1BF', 'ec': '#2F3737', 'hatch_c': '#b3cfa5', 'hatch': 'ooo...', 'lw': 1, 'zorder': 1},
'scrub': {'fc': '#89d689', 'ec': '#2F3737', 'hatch_c': '#75bd75', 'hatch': 'ooo...', 'lw': 1, 'zorder': 1},
'water': {'fc': '#a1e3ff', 'ec': '#2F3737', 'lw': 1, 'zorder': 2},
'sea': {'fc': '#44A7C4', 'ec': '#000080', 'lw': 1, 'zorder': 1},
'coastline': {'fc': '#a8e1e6', 'ec': '#2F3737', 'hatch_c': '#9bc3d4', 'hatch': 'ooo...', 'lw': 1, 'zorder': 2},
'streets': {'fc': '#2F3737', 'ec': '#475657', 'alpha': 1, 'lw': 0, 'zorder': 3},
'walls': {'fc': '#990000', 'ec': '#475657', 'alpha': 1, 'lw': 0, 'zorder': 3},
'building': {'palette': palette, 'ec': '#FF0000', 'lw': .5, 'zorder': 4},
},
osm_credit = {'color': '#3b4545'}
)
#
#Lưu bản đồ ra tập tin ảnh & vector
#
plt.savefig('/home/tructt/Desktop/Maps.BH/DaNang.png')
plt.savefig('/home/tructt/Desktop/Maps.BH/DaNang.svg')
City samples with river
#
#Khai báo các tham số hệ thống và gọi thư viện
#
import sys
sys.path.append('../')
import vsketch
from prettymaps import *
import matplotlib.font_manager as fm
from matplotlib import pyplot as plt
#
#Thông tin chung
#
palette = ['#FFC857', '#E9724C', '#C5283D']
#
#Thiết lập tham số
#
fig, ax = plt.subplots(figsize = (20, 20), constrained_layout = True)
backup = plot(
#
#Tọa độ vị trí trên Google Maps hoặc tên địa điểm kèm bán kính (tính bằng mét)
#Nếu trong quá trình xử lý bị "Killed" thì giảm bán kính lại nhỏ hơn
#
(10.7744704,106.7019512), radius = 1000,
ax = ax,
layers = {
'perimeter': {},
'streets': {
'width': {
'motorway': 5,
'trunk': 5,
'primary': 4.5,
'secondary': 4,
'tertiary': 3.5,
'residential': 3,
'living_street': 2,
'pedestrian': 1,
'footway': 1,
'track': 1,
'bridleway': 1
}
},
#
#Tùy biến các tham số tag theo tài liệu hướng dẫn của OpenStreetMaps để phù hợp các lớp địa hình
#
'building': {'tags': {'building': True, 'landuse': 'construction'}, 'union': False},
'water': {'tags': {'natural': ['water','lake'],'waterway':['river','riverbank','canal','lagoon']}},
'green': {'tags': {'landuse': ['grass','farmland','farmyard','reservoir','forest'], 'natural': ['island', 'wood'], 'leisure': 'park'}},
'scrub': {'tags': {'natural': 'scrub'}},
'walls': {'tags': {'manmade': 'embankment'}},
},
#
#Thiết lập màu sắc cho các layer đã tùy biến
#
drawing_kwargs = {
'background': {'fc': '#000080', 'ec': '#dadbc1', 'hatch': 'ooo...', 'zorder': -1},
'perimeter': {'fc': '#F2F4CB', 'ec': '#dadbc1', 'lw': 0, 'hatch': 'ooo...', 'zorder': 0},
'green': {'fc': '#D0F1BF', 'ec': '#2F3737', 'hatch_c': '#b3cfa5', 'hatch': 'ooo...', 'lw': 1, 'zorder': 1},
'scrub': {'fc': '#89d689', 'ec': '#2F3737', 'hatch_c': '#75bd75', 'hatch': 'ooo...', 'lw': 1, 'zorder': 1},
'water': {'fc': '#a1e3ff', 'ec': '#2F3737', 'lw': 1, 'zorder': 2},
'streets': {'fc': '#2F3737', 'ec': '#475657', 'alpha': 1, 'lw': 0, 'zorder': 3},
'walls': {'fc': '#2F3737', 'ec': '#475657', 'alpha': 1, 'lw': 0, 'zorder': 3},
'building': {'palette': palette, 'ec': '#2F3737', 'lw': .5, 'zorder': 4},
},
osm_credit = {'color': '#2F3737'}
)
#
#Lưu bản đồ ra tập tin ảnh & vector
#
plt.savefig('/home/tructt/sg.png')
plt.savefig('/home/tructt/sg.svg')