iplocate/mapsgen.py

122 lines
3.8 KiB
Python
Raw Normal View History

import staticmaps
from iplocate import selfpath
2023-12-26 02:11:15 -03:00
# context.set_tile_provider(staticmaps.tile_provider_ArcGISWorldImagery)
# context.set_tile_provider(staticmaps.tile_provider_CartoDarkNoLabels)
cntxt200 = staticmaps.Context()
cntxt200.set_tile_provider(staticmaps.tile_provider_OSM)
cntxt300 = staticmaps.Context()
cntxt300.set_tile_provider(staticmaps.tile_provider_OSM)
cntxtAll = staticmaps.Context()
cntxtAll.set_tile_provider(staticmaps.tile_provider_OSM)
2023-12-26 02:11:15 -03:00
def map200(geolocs):
for loc in geolocs:
lat = float(loc[0].split(',')[0])
lon = float(loc[0].split(',')[1])
2024-01-21 01:26:36 -03:00
marca200 = staticmaps.create_latlng(lat, lon)
cntxt200.add_object(
staticmaps.Marker(
marca200,
color=staticmaps.parse_color('#00ff29'),
size=7
)
)
svg_image = cntxt200.render_svg(1920, 1080)
2023-12-26 02:11:15 -03:00
with open(f"{selfpath}/maps/map_200.svg", "w", encoding="utf-8") as f:
svg_image.write(f, pretty=True)
2023-12-26 02:11:15 -03:00
image = cntxt200.render_cairo(1920, 1080)
image.write_to_png(f"{selfpath}/maps/map_200.png")
def map300(geolocs):
for loc in geolocs:
lat = float(loc[0].split(',')[0])
lon = float(loc[0].split(',')[1])
2024-01-21 01:26:36 -03:00
marca300 = staticmaps.create_latlng(lat, lon)
cntxt300.add_object(staticmaps.Marker(
marca300, color=staticmaps.parse_color('#b20101'), size=5))
svg_image = cntxt300.render_svg(1920, 1080)
2023-12-26 02:11:15 -03:00
with open(f"{selfpath}/maps/map_300.svg", "w", encoding="utf-8") as f:
svg_image.write(f, pretty=True)
2023-12-26 02:11:15 -03:00
image = cntxt300.render_cairo(1920, 1080)
image.write_to_png(f"{selfpath}/maps/map_300.png")
def maps_gen(locs_200, locs_300):
maps_thumbs(locs_200, locs_300)
map200(locs_200)
map300(locs_300)
for loc in locs_300:
lat = float(loc[0].split(',')[0])
lon = float(loc[0].split(',')[1])
2023-12-26 02:11:15 -03:00
marca3 = staticmaps.create_latlng(lat, lon)
cntxtAll.add_object(
staticmaps.Marker(
marca3,
color=staticmaps.parse_color('#b20101'),
size=5
)
)
2023-12-26 02:11:15 -03:00
for loc in locs_200:
lat = float(loc[0].split(',')[0])
lon = float(loc[0].split(',')[1])
2024-01-21 01:26:36 -03:00
marca3 = staticmaps.create_latlng(lat, lon)
cntxtAll.add_object(
staticmaps.Marker(
marca3,
color=staticmaps.parse_color('#00ff29'),
size=6
)
)
svg_image = cntxtAll.render_svg(1920, 1080)
2023-12-26 02:11:15 -03:00
with open(f"{selfpath}/maps/map_all.svg", "w", encoding="utf-8") as f:
svg_image.write(f, pretty=True)
2023-12-26 02:11:15 -03:00
image = cntxtAll.render_cairo(1920, 1080)
image.write_to_png(f"{selfpath}/maps/map_all.png")
maps_thumbs(locs_200, locs_300)
def maps_thumbs(locs_200, locs_300):
cntxtdemo = staticmaps.Context()
cntxtdemo.set_tile_provider(staticmaps.tile_provider_OSM)
for loc in locs_300:
lat = float(loc[0].split(',')[0])
lon = float(loc[0].split(',')[1])
2023-12-26 02:11:15 -03:00
demo300 = staticmaps.create_latlng(lat, lon)
cntxtdemo.add_object(
staticmaps.Marker(
demo300,
color=staticmaps.parse_color('#b20101'),
size=4
)
)
for loc in locs_200:
lat = float(loc[0].split(',')[0])
lon = float(loc[0].split(',')[1])
2024-01-21 01:26:36 -03:00
demo200 = staticmaps.create_latlng(lat, lon)
cntxtdemo.add_object(
staticmaps.Marker(
demo200,
color=staticmaps.parse_color('#00ff29'),
size=5
)
)
svg_thumb = cntxtdemo.render_svg(1024, 768)
2023-12-26 02:11:15 -03:00
with open(f"{selfpath}/maps/map_thumb.svg", "w", encoding="utf-8") as f:
svg_thumb.write(f, pretty=True)
2023-12-26 02:11:15 -03:00
image = cntxtdemo.render_cairo(1024, 768)
image.write_to_png(f"{selfpath}/maps/map_thumb.png")