OpenSource-Hub

prettymaps

ライブラリ

marceloprates/prettymaps

matplotlibで美しいOpenStreetMapの地図を描画する。

概要

OpenStreetMapデータに基づいてカスタムマップを描画するミニマリストなPythonライブラリ。レイヤー、スタイル、プリセットに対応し、ジェネラティブアートや地図制作に適しています。

README プレビュー

# prettymaps\n\nA minimal Python library to draw customized maps from [OpenStreetMap](https://www.openstreetmap.org/#map=12/11.0733/106.3078) created using the [osmnx](https://github.com/gboeing/osmnx), [matplotlib](https://matplotlib.org/), [shapely](https://shapely.readthedocs.io/en/stable/index.html) and [vsketch](https://github.com/abey79/vsketch) packages.\n\n\n\n# [](https://marceloprates.github.io/prettymaps/) [](https://pypi.org/project/prettymaps/) [](https://www.python.org/) [](LICENSE)\n\n\nThis work is [licensed](LICENSE) under a GNU Affero General Public License v3.0 (you can make commercial use, distribute and modify this project, but must **disclose** the source code with the license and copyright notice)\n\n## Note about crediting and NFTs:\n- Please keep the printed message on the figures crediting my repository and OpenStreetMap ([mandatory by their license](https://www.openstreetmap.org/copyright)).\n- I am personally **against** NFTs for their [environmental impact](https://earth.org/nfts-environmental-impact/), the fact that they're a [giant money-laundering pyramid scheme](https://twitter.com/smdiehl/status/1445795667826208770) and the structural incentives they create for [theft](https://twitter.com/NFTtheft) in the open source and generative art communities.\n- **I do not authorize in any way this project to be used for selling NFTs**, although I cannot legally enforce it. **Respect the creator**.\n- The [AeternaCivitas](https://magiceden.io/marketplace/aeterna_civitas) and [geoartnft](https://www.geo-nft.com/) projects have used this work to sell NFTs and refused to credit it. See how they reacted after being exposed: [AeternaCivitas](https://github.com/marceloprates/prettymaps/raw/main/pictures/NFT_theft_AeternaCivitas.jpg), [geoartnft](https://github.com/marceloprates/prettymaps/raw/main/pictures/NFT_theft_geoart.jpg).\n- **I have closed my other generative art projects on Github and won't be sharing new ones as open source to protect me f

FAQ (5)

トラブル対応
prettymapsのplotterモードで`save_as`を使用した際にSVGファイルが空白になる問題を修正するにはどうすればよいですか?

これはあなたのプロットパラメータの問題ではなく、prettymaps の plotter モードのバグでした。この問題はコミット 3f3b8be で修正されました。その修正を含むバージョンに更新してから、プロットを再実行してください。Google Colab では、次のように修正済みバージョンをインストールします:

!pip install git+https://github.com/marceloprates/prettymaps.git@3f3b8be

プロンプトが表示されたらランタイムを再起動し、コードを再度実行してください。例:

prettymaps.plot(..., mode='plotter', save_as='barcelona_plot.svg')

生成される SVG は空白ではなくなるはずです。

参照 Issue #138
トラブル対応
なぜ最初のPrettymapsのレンダリングは、CPUをほとんど使用していないのに約10分もかかるのですか?

この遅延は、リクエストをスロットルする公開Overpass APIをOSMnxが待機していることが原因です。ox.config(log_file=True)でログを有効にし、Pausing 56 seconds before making HTTP POST requestのようなメッセージを探してください。したがって、最初のフェッチはCPUバウンドではなくネットワークバウンドです。OSMのレスポンスはディスクにキャッシュされるため、同じエリアの後続のレンダリングははるかに高速になります。実行間でキャッシュを保持し、ディスクキャッシュの修正を含むバージョンに更新し、Overpassリクエストを最小限に抑えるためにマップエリアまたはOSMレイヤーの数を減らしてください。

参照 Issue #22
トラブル対応
prettymapsで都市名を指定してプロットする際に、河川や水域のジオメトリが欠落する問題を修正する方法

これは、ジオメトリと perimeter の交差処理によって、指定したエリアの境界をまたぐ OSM フィーチャーが削除されることが原因です。回避策として、地名の代わりに座標と半径を指定してプロットしてください:

plot((48.8534, 2.3397), radius=7000, ...)

指定した perimeter を維持するには、prettymaps/fetch.py 内の get_geometries() にパッチを適用してください。以下のコードを:

geometries = geometries.intersection(perimeter)

次のように置き換えます:

geometries = [geo.intersection(perimeter).buffer(0) for geo in geometries.geometry]

.buffer(0) の呼び出しにより、無効な交差結果が修復され、複数のポリゴンが保持されます。あるいは、issue #51 / "Fix geometry-perimeter intersection" PR で追跡されている修正を含む prettymaps リリースにアップグレードしてください。

参照 Issue #46
トラブル対応
多くの依存関係を持つPythonパッケージが既存のPython環境を壊すのを防ぐにはどうすればよいですか?

システムのPythonではなく、分離された仮想環境内にパッケージをインストールしてください。venvの場合は、python3 -m venv .venvを実行し、Linux/macOSではsource .venv/bin/activate、Windowsでは.venv\Scripts\activateでアクティベートしてから、pip install <package-name>でパッケージをインストールします。Condaの場合は、conda create -n myenv python=3.11 -yを実行し、次にconda activate myenvを実行して、pip install <package-name>またはconda install <package-name>でパッケージをインストールします。これにより、依存関係のバージョンをOSのPythonから分離し、バージョンの競合を回避できます。

参照 Issue #16
トラブル対応
道路幅を変更せずに、橋や特定のOSM道路タグを異なる色で表示するにはどうすればよいですか?

橋を別のレイヤーとして描画し、レイヤーごとのスタイルを適用してください。橋の構造物については、"bridge": {"tags": {"man_made": "bridge"}} のようなレイヤーを定義します。bridge タグが付与された highway セグメントについては、bridge=yes を持つウェイを選択する custom_filter を使用した別の道路レイヤーを使ってください。このレイヤーには異なる色とより高い zorder/z-height を設定し、通常の道路レイヤーの上にレンダリングされるようにします。ベースとなる highway レイヤーの幅の設定は変更しないでください。スタイリング API が明示的な値を必要とする場合は、橋のレイヤーに、道路レイヤーで使用されているものと同じ line-width マッピングを設定してください。

参照 Issue #12