{"id":16740469,"url":"https://github.com/flopp/py-staticmaps","last_synced_at":"2025-04-05T22:11:09.183Z","repository":{"id":44601302,"uuid":"291262458","full_name":"flopp/py-staticmaps","owner":"flopp","description":"A python module to create static map images with markers, geodesic lines, etc.","archived":false,"fork":false,"pushed_at":"2024-04-10T10:23:41.000Z","size":3108,"stargazers_count":150,"open_issues_count":9,"forks_count":20,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T21:05:24.828Z","etag":null,"topics":["geodesic","gis","maps","markers","osm","static-maps"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flopp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-29T11:58:05.000Z","updated_at":"2025-03-26T08:36:51.000Z","dependencies_parsed_at":"2024-04-09T17:38:53.078Z","dependency_job_id":"6c010412-00df-4f5a-9dd4-3f8aba502594","html_url":"https://github.com/flopp/py-staticmaps","commit_stats":{"total_commits":70,"total_committers":4,"mean_commits":17.5,"dds":"0.19999999999999996","last_synced_commit":"02c481b5f12a9df9da70a66189ca579d74ff5740"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flopp%2Fpy-staticmaps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flopp%2Fpy-staticmaps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flopp%2Fpy-staticmaps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flopp%2Fpy-staticmaps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flopp","download_url":"https://codeload.github.com/flopp/py-staticmaps/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406111,"owners_count":20933806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geodesic","gis","maps","markers","osm","static-maps"],"created_at":"2024-10-13T00:58:44.633Z","updated_at":"2025-04-05T22:11:09.159Z","avatar_url":"https://github.com/flopp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI](https://github.com/flopp/py-staticmaps/workflows/CI/badge.svg)](https://github.com/flopp/py-staticmaps/actions?query=workflow%3ACI)\n[![PyPI Package](https://img.shields.io/pypi/v/py-staticmaps.svg)](https://pypi.org/project/py-staticmaps/)\n[![Format](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)\n[![License MIT](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](LICENSE)\n\n# py-staticmaps\nA python module to create static map images (PNG, SVG) with markers, geodesic lines, etc.\n\n\n## Features\n\n- Map objects: pin-style markers, image (PNG) markers, polylines, polygons, (geodesic) circles\n- Automatic computation of best center + zoom from the added map objects\n- Several pre-configured map tile providers\n- Proper tile provider attributions display\n- On-disc caching of map tile images for faster drawing and reduced load on the tile servers\n- Non-anti-aliased drawing via `PILLOW`\n- Anti-aliased drawing via `pycairo` (optional; only if `pycairo` is installed properly)\n- SVG creation via `svgwrite`\n\n\n## Installation\n\n### SVG + non-anti-aliased PNG version\n\n```shell\npip install py-staticmaps\n```\n\n### SVG + anti-aliased PNG version (via Cairo)\n\n```shell\npip install py-staticmaps[cairo]\n```\n\n`py-staticmaps` uses `pycairo` for creating anti-aliased raster-graphics, so make sure `libcairo2` is installed on your system (on Ubuntu just install the `libcairo2-dev` package, i.e. `sudo apt install libcairo2-dev`).\n\n\n## Examples\n\nNote: PNG support (e.g. `context.render_cairo(...)`) is only available if the `pycairo` module is installed.\n\n### Markers and Geodesic Lines\n\n```python\nimport staticmaps\n\ncontext = staticmaps.Context()\ncontext.set_tile_provider(staticmaps.tile_provider_StamenToner)\n\nfrankfurt = staticmaps.create_latlng(50.110644, 8.682092)\nnewyork = staticmaps.create_latlng(40.712728, -74.006015)\n\ncontext.add_object(staticmaps.Line([frankfurt, newyork], color=staticmaps.BLUE, width=4))\ncontext.add_object(staticmaps.Marker(frankfurt, color=staticmaps.GREEN, size=12))\ncontext.add_object(staticmaps.Marker(newyork, color=staticmaps.RED, size=12))\n\n# render non-anti-aliased png\nimage = context.render_pillow(800, 500)\nimage.save(\"frankfurt_newyork.pillow.png\")\n\n# render anti-aliased png (this only works if pycairo is installed)\nimage = context.render_cairo(800, 500)\nimage.write_to_png(\"frankfurt_newyork.cairo.png\")\n\n# render svg\nsvg_image = context.render_svg(800, 500)\nwith open(\"frankfurt_newyork.svg\", \"w\", encoding=\"utf-8\") as f:\n    svg_image.write(f, pretty=True)\n```\n\n![franfurt_newyork](../assets/frankfurt_newyork.png?raw=true)\n\n\n### Transparent Polygons\n\n```python\nimport staticmaps\n\ncontext = staticmaps.Context()\ncontext.set_tile_provider(staticmaps.tile_provider_OSM)\n\nfreiburg_polygon = [\n    (47.96881, 7.79045),\n    (47.96866, 7.78610),\n    (47.97134, 7.77874),\n    ...\n]\n\ncontext.add_object(\n    staticmaps.Area(\n        [staticmaps.create_latlng(lat, lng) for lat, lng in freiburg_polygon],\n        fill_color=staticmaps.parse_color(\"#00FF003F\"),\n        width=2,\n        color=staticmaps.BLUE,\n    )\n)\n\n# render non-anti-aliased png\nimage = context.render_pillow(800, 500)\nimage.save(\"freiburg_area.pillow.png\")\n\n# render anti-aliased png (this only works if pycairo is installed)\nimage = context.render_cairo(800, 500)\nimage.write_to_png(\"freiburg_area.cairo.png\")\n\n# render svg\nsvg_image = context.render_svg(800, 500)\nwith open(\"freiburg_area.svg\", \"w\", encoding=\"utf-8\") as f:\n    svg_image.write(f, pretty=True)\n```\n\n![draw_gpx](../assets/freiburg_area.png?raw=true)\n\n\n### Drawing a GPX Track + Image Marker (PNG)\n\n```python\nimport sys\n\nimport gpxpy\nimport staticmaps\n\ncontext = staticmaps.Context()\ncontext.set_tile_provider(staticmaps.tile_provider_ArcGISWorldImagery)\n\nwith open(sys.argv[1], \"r\") as file:\n    gpx = gpxpy.parse(file)\n\nfor track in gpx.tracks:\n    for segment in track.segments:\n        line = [staticmaps.create_latlng(p.latitude, p.longitude) for p in segment.points]\n        context.add_object(staticmaps.Line(line))\n\nfor p in gpx.walk(only_points=True):\n    pos = staticmaps.create_latlng(p.latitude, p.longitude)\n    marker = staticmaps.ImageMarker(pos, \"start.png\", origin_x=27, origin_y=35)\n    context.add_object(marker)\n    break\n\n# render non-anti-aliased png\nimage = context.render_pillow(800, 500)\nimage.save(\"draw_gpx.pillow.png\")\n\n# render anti-aliased png (this only works if pycairo is installed)\nimage = context.render_cairo(800, 500)\nimage.write_to_png(\"draw_gpx.cairo.png\")\n```\n\n![draw_gpx](../assets/draw_gpx.png?raw=true)\n\n\n### US State Capitals\n\n```python\nimport json\nimport requests\nimport staticmaps\n\ncontext = staticmaps.Context()\ncontext.set_tile_provider(staticmaps.tile_provider_OSM)\n\nURL = (\n    \"https://gist.githubusercontent.com/jpriebe/d62a45e29f24e843c974/\"\n    \"raw/b1d3066d245e742018bce56e41788ac7afa60e29/us_state_capitals.json\"\n)\nresponse = requests.get(URL)\nfor _, data in json.loads(response.text).items():\n    capital = staticmaps.create_latlng(float(data[\"lat\"]), float(data[\"long\"]))\n    context.add_object(staticmaps.Marker(capital, size=5))\n\n# render non-anti-aliased png\nimage = context.render_pillow(800, 500)\nimage.save(\"us_capitals.pillow.png\")\n\n# render anti-aliased png (this only works if pycairo is installed)\nimage = context.render_cairo(800, 500)\nimage.write_to_png(\"us_capitals.cairo.png\")\n```\n\n![us_capitals](../assets/us_capitals.png?raw=true)\n\n\n### Geodesic Circles\n\n```python\nimport staticmaps\n\ncontext = staticmaps.Context()\ncontext.set_tile_provider(staticmaps.tile_provider_StamenToner)\n\ncenter1 = staticmaps.create_latlng(66, 0)\ncenter2 = staticmaps.create_latlng(0, 0)\n\ncontext.add_object(staticmaps.Circle(center1, 2000, fill_color=staticmaps.TRANSPARENT, color=staticmaps.RED, width=2))\ncontext.add_object(staticmaps.Circle(center2, 2000, fill_color=staticmaps.TRANSPARENT, color=staticmaps.GREEN, width=2))\ncontext.add_object(staticmaps.Marker(center1, color=staticmaps.RED))\ncontext.add_object(staticmaps.Marker(center2, color=staticmaps.GREEN))\n\n# render non-anti-aliased png\nimage = context.render_pillow(800, 500)\nimage.save(\"geodesic_circles.pillow.png\")\n\n# render anti-aliased png (this only works if pycairo is installed)\nimage = context.render_cairo(800, 600)\nimage.write_to_png(\"geodesic_circles.cairo.png\")\n```\n\n![geodesic_circles](../assets/geodesic_circles.png?raw=true)\n\n\n### Other Examples\n\nPlease take a look at the command line program which uses the `staticmaps` package: `staticmaps/cli.py`\n\n\n### Dependencies\n\n`py-staticmaps` uses\n\n- `PILLOW` for rendering raster-graphics\n- `pycairo` for rendering antialiased raster-graphics (optional!)\n- `svgwrite` for writing SVG files\n- `s2sphere` for geo coordinates handling\n- `geographiclib` for geodesic computations\n- `appdirs` for finding the user's default cache directory\n- `requests` for downloading tile files\n\n\n## License\n\n[MIT](LICENSE) \u0026copy; 2020-2021 Florian Pigorsch\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflopp%2Fpy-staticmaps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflopp%2Fpy-staticmaps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflopp%2Fpy-staticmaps/lists"}