Beispiel #1
0
 def add_neighbor_hash_polys(self, h, fill_color, width, color):
     hashes = pygeodesy.geohash.neighbors(h)
     for n in hashes.values():
         self.add_object(
             staticmaps.Area(make_hash_poly_points(n),
                             fill_color=fill_color,
                             width=width,
                             color=color))
def create_area(*coords):
    context = staticmaps.Context()
    context.set_tile_provider(staticmaps.tile_provider_OSM)
    rectangle = [(coords[0], coords[1]), (coords[2], coords[1]),
                 (coords[2], coords[3]), (coords[0], coords[3]),
                 (coords[0], coords[1])]

    context.add_object(
        staticmaps.Area(
            [staticmaps.create_latlng(lat, lng) for lat, lng in rectangle],
            fill_color=staticmaps.parse_color("#FFFFFF00"),
            width=2,
            color=staticmaps.BLUE,
        ))
    return context
Beispiel #3
0
    (47.96768, 7.81300),
    (47.96724, 7.81219),
    (47.96592, 7.80894),
    (47.96425, 7.80478),
    (47.96369, 7.80338),
    (47.96430, 7.80115),
    (47.96484, 7.79920),
    (47.96712, 7.79471),
    (47.96883, 7.79090),
    (47.96881, 7.79045),
]

context.add_object(
    staticmaps.Area(
        [staticmaps.create_latlng(lat, lng) for lat, lng in freiburg_polygon],
        fill_color=staticmaps.parse_color("#00FF007F"),
        width=2,
        color=staticmaps.BLUE,
    ))

# render png via pillow
image = context.render_pillow(800, 500)
image.save("freiburg_area.pillow.png")

# render png via cairo
if staticmaps.cairo_is_supported():
    image = context.render_cairo(800, 500)
    image.write_to_png("freiburg_area.cairo.png")

# render svg
svg_image = context.render_svg(800, 500)
with open("freiburg_area.svg", "w", encoding="utf-8") as f:
#!/usr/bin/env python

# py-staticmaps
# Copyright (c) 2020 Florian Pigorsch; see /LICENSE for licensing information

import staticmaps

context = staticmaps.Context()

p1 = staticmaps.create_latlng(48.005774, 7.834042)
p2 = staticmaps.create_latlng(47.988716, 7.868804)
p3 = staticmaps.create_latlng(47.985958, 7.824601)

context.add_object(
    staticmaps.Area([p1, p2, p3, p1],
                    color=staticmaps.RED,
                    fill_color=staticmaps.TRANSPARENT,
                    width=2))
context.add_object(staticmaps.Marker(p1, color=staticmaps.BLUE))
context.add_object(staticmaps.Marker(p2, color=staticmaps.GREEN))
context.add_object(staticmaps.Marker(p3, color=staticmaps.YELLOW))

for name, provider in staticmaps.default_tile_providers.items():
    context.set_tile_provider(provider)

    # render png via pillow
    image = context.render_pillow(800, 500)
    image.save(f"provider_{name}.pillow.png")

    # render png via cairo
    if staticmaps.cairo_is_supported():
        image = context.render_cairo(800, 500)
Beispiel #5
0
 def add_hash_poly(self, h, fill_color, width, color):
     self.add_object(
         staticmaps.Area(make_hash_poly_points(h),
                         fill_color=fill_color,
                         width=width,
                         color=color))
Beispiel #6
0
def main() -> None:
    args_parser = argparse.ArgumentParser(prog="createstaticmap")
    args_parser.add_argument(
        "--center",
        metavar="LAT,LNG",
        type=str,
    )
    args_parser.add_argument(
        "--zoom",
        metavar="ZOOM",
        type=int,
    )
    args_parser.add_argument(
        "--width",
        metavar="WIDTH",
        type=int,
        required=True,
    )
    args_parser.add_argument(
        "--height",
        metavar="HEIGHT",
        type=int,
        required=True,
    )
    args_parser.add_argument(
        "--background",
        metavar="COLOR",
        type=str,
    )
    args_parser.add_argument(
        "--marker",
        metavar="LAT,LNG",
        type=str,
        action="append",
    )
    args_parser.add_argument(
        "--line",
        metavar="LAT,LNG LAT,LNG ...",
        type=str,
        action="append",
    )
    args_parser.add_argument(
        "--area",
        metavar="LAT,LNG LAT,LNG ...",
        type=str,
        action="append",
    )
    args_parser.add_argument(
        "--bounds",
        metavar="LAT,LNG LAT,LNG",
        type=str,
    )
    args_parser.add_argument(
        "--tiles",
        metavar="TILEPROVIDER",
        type=str,
        choices=staticmaps.default_tile_providers.keys(),
        default=staticmaps.tile_provider_OSM.name(),
    )
    args_parser.add_argument(
        "--file-format",
        metavar="FORMAT",
        type=FileFormat,
        choices=FileFormat,
        default=FileFormat.GUESS,
    )
    args_parser.add_argument(
        "filename",
        metavar="FILE",
        type=str,
        nargs=1,
    )

    args = args_parser.parse_args()

    context = staticmaps.Context()

    context.set_tile_provider(staticmaps.default_tile_providers[args.tiles])

    if args.center is not None:
        context.set_center(staticmaps.parse_latlng(args.center))
    if args.zoom is not None:
        context.set_zoom(args.zoom)
    if args.background is not None:
        context.set_background_color(staticmaps.parse_color(args.background))
    if args.area:
        for coords in args.area:
            context.add_object(
                staticmaps.Area(staticmaps.parse_latlngs(coords)))
    if args.line:
        for coords in args.line:
            context.add_object(
                staticmaps.Line(staticmaps.parse_latlngs(coords)))
    if args.marker:
        for coords in args.marker:
            context.add_object(
                staticmaps.Marker(staticmaps.parse_latlng(coords)))
    if args.bounds is not None:
        context.add_bounds(staticmaps.parse_latlngs2rect(args.bounds))

    file_name = args.filename[0]
    if determine_file_format(args.file_format, file_name) == FileFormat.PNG:
        image = context.render_cairo(args.width, args.height)
        image.write_to_png(file_name)
    else:
        svg_image = context.render_svg(args.width, args.height)
        with open(file_name, "w", encoding="utf-8") as f:
            svg_image.write(f, pretty=True)
    print(f"wrote result image to {file_name}")