prettymaps - A minimal Python library to draw customized maps from OpenStreetMap data.

Overview

prettymaps

A minimal Python library to draw customized maps from OpenStreetMap data.

Based on osmnx, matplotlib, shapely and vsketch libraries.

Google Colaboratory Demo

Open In Colab

Installation

Install with

$ pip install git+https://github.com/abey79/vsketch#egg=vsketch
$ pip install git+https://github.com/marceloprates/prettymaps.git

Usage example (For more examples, see this Jupyter Notebook):

# Init matplotlib figure
fig, ax = plt.subplots(figsize = (12, 12), constrained_layout = True)

backup = plot(
    # Address:
    'Praça Ferreira do Amaral, Macau',
    # Plot geometries in a circle of radius:
    radius = 1100,
    # Matplotlib axis
    ax = ax,
    # Which OpenStreetMap layers to plot and their parameters:
    layers = {
            # Perimeter (in this case, a circle)
            'perimeter': {},
            # Streets and their widths
            'streets': {
                'width': {
                    'motorway': 5,
                    'trunk': 5,
                    'primary': 4.5,
                    'secondary': 4,
                    'tertiary': 3.5,
                    'residential': 3,
                    'service': 2,
                    'unclassified': 2,
                    'pedestrian': 2,
                    'footway': 1,
                }
            },
            # Other layers:
            #   Specify a name (for example, 'building') and which OpenStreetMap tags to fetch
            'building': {'tags': {'building': True, 'landuse': 'construction'}, 'union': False},
            'water': {'tags': {'natural': ['water', 'bay']}},
            'green': {'tags': {'landuse': 'grass', 'natural': ['island', 'wood'], 'leisure': 'park'}},
            'forest': {'tags': {'landuse': 'forest'}},
            'parking': {'tags': {'amenity': 'parking', 'highway': 'pedestrian', 'man_made': 'pier'}}
        },
        # drawing_kwargs:
        #   Reference a name previously defined in the 'layers' argument and specify matplotlib parameters to draw it
        drawing_kwargs = {
            'background': {'fc': '#F2F4CB', 'ec': '#dadbc1', 'hatch': 'ooo...', 'zorder': -1},
            'perimeter': {'fc': '#F2F4CB', 'ec': '#dadbc1', 'lw': 0, 'hatch': 'ooo...',  'zorder': 0},
            'green': {'fc': '#D0F1BF', 'ec': '#2F3737', 'lw': 1, 'zorder': 1},
            'forest': {'fc': '#64B96A', 'ec': '#2F3737', 'lw': 1, 'zorder': 1},
            'water': {'fc': '#a1e3ff', 'ec': '#2F3737', 'hatch': 'ooo...', 'hatch_c': '#85c9e6', 'lw': 1, 'zorder': 2},
            'parking': {'fc': '#F2F4CB', 'ec': '#2F3737', 'lw': 1, 'zorder': 3},
            'streets': {'fc': '#2F3737', 'ec': '#475657', 'alpha': 1, 'lw': 0, 'zorder': 3},
            'building': {'palette': ['#FFC857', '#E9724C', '#C5283D'], 'ec': '#2F3737', 'lw': .5, 'zorder': 4},
        }
)

Gallery:

Barcelona:

Heerhugowaard:

Barra da Tijuca:

Porto Alegre:

Issues
  • ci: Add publishing workflow with GitHub Actions

    ci: Add publishing workflow with GitHub Actions

    Resolves #67

    Add GHA based workflow to release a sdist and wheel to:

    • TestPyPI on tags
    • PyPI on GitHub releases

    Things that @marceloprates would need to do for this PR to work:


    Example resulting release workflow:

    Locally on main run:

    $ git checkout main && git pull # verify that you're on main and synced with GitHub
    $ <whatever you need to do to bump the release number>  # Matthew uses bump2version on most of his projects, but whatever works here
    $ git push origin main --tags # push the commit and the tag to GitHub, causing TestPyPI to publish
    
    • Got to TestPyPI (https://test.pypi.org/project/prettymaps/) to look if the release looks okay
    • Then on GitHub:
      1. Go to releases: https://github.com/marceloprates/prettymaps/releases
      2. Click "Draft a new release"
      3. On the new page enter the tag you just pushed (e.g. v0.1.0) in the "Tag version" box and the "Release title" box (to make it easy unless you really want to get descriptive)
      4. Enter any release notes and click "Publish release"
    • This then kicks of the publication CD workflow that will use the PyPI API key to publish.
    opened by matthewfeickert 10
  • Error with installation on Python 3.9

    Error with installation on Python 3.9

    If I follow the installation instructions, vsketch works, but for prettymaps I get the following error:

    pip install "git+https://github.com/marceloprates/prettymaps.git"
    Defaulting to user installation because normal site-packages is not writeable
    Collecting git+https://github.com/marceloprates/prettymaps.git
      Cloning https://github.com/marceloprates/prettymaps.git to /tmp/pip-req-build-9bvx3_4y
      Running command git clone -q https://github.com/marceloprates/prettymaps.git /tmp/pip-req-build-9bvx3_4y
    ERROR: Exception:
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 223, in _main
        status = self.run(options, args)
      File "/usr/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 180, in wrapper
        return func(self, options, args)
      File "/usr/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 320, in run
        requirement_set = resolver.resolve(
      File "/usr/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 121, in resolve
        self._result = resolver.resolve(
      File "/usr/lib/python3.9/site-packages/resolvelib/resolvers.py", line 454, in resolve
        state = resolution.resolve(requirements, max_rounds=max_rounds)
      File "/usr/lib/python3.9/site-packages/resolvelib/resolvers.py", line 319, in resolve
        name, crit = self._merge_into_criterion(r, parent=None)
      File "/usr/lib/python3.9/site-packages/resolvelib/resolvers.py", line 176, in _merge_into_criterion
        crit = Criterion.from_requirement(self._p, requirement, parent)
      File "/usr/lib/python3.9/site-packages/resolvelib/resolvers.py", line 80, in from_requirement
        cands = build_iter_view(matches)
      File "/usr/lib/python3.9/site-packages/resolvelib/structs.py", line 148, in build_iter_view
        matches = list(matches)
      File "/usr/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 285, in <genexpr>
        if constraint.is_satisfied_by(c)
      File "/usr/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/base.py", line 66, in is_satisfied_by
        return self.specifier.contains(candidate.version, prereleases=True)
      File "/usr/lib/python3.9/site-packages/packaging/specifiers.py", line 790, in contains
        item = parse(item)
      File "/usr/lib/python3.9/site-packages/packaging/version.py", line 57, in parse
        return Version(version)
      File "/usr/lib/python3.9/site-packages/packaging/version.py", line 296, in __init__
        match = self._regex.search(version)
    TypeError: expected string or bytes-like object
    

    This is within a Miniconda environment using Python 3.9. Is there a way to fix this?

    opened by flxai 9
  • NameError: name 'plt' is not defined

    NameError: name 'plt' is not defined

    Hi. How can I fix this error while generating the script? Thanks.

    Traceback (most recent call last): File "C:\Users\cuyug\Desktop\TroPYcal codes\prettymaps.py", line 4, in <module> from prettymaps import * File "C:\Users\cuyug\Desktop\TroPYcal codes\prettymaps.py", line 17, in <module> layers = plot( NameError: name 'plot' is not defined

    opened by matthewcuyugan 4
  • Google Collab example does not work

    Google Collab example does not work

    Seems to be quite a few import errors when trying to run the google collab version. This is a super cool project but I can't get it to run.

    opened by caseydierking 4
  • Rendering coastline

    Rendering coastline

    I believe this fixes the issue in #7 . It's difficult to get polygons for the coastline as the polygons will be extremely large and may in some cases have errors (as mentioned on the OSM wiki). The smaller closed polygons with repaired coastlines from OSMCoastline is made available here.

    The water-polygons-split-4326.zip file is 738MB and the extracted .shp file is about 1GB.

    A coastline layer can be used to point to the extracted water_polygons.shp file (using the file_location key) along while using a buffer to ensure the polygons are included (this file needs to be downloaded first). The large buffer does not seem to add that much extra time to the processing as the file is already downloaded.

    'coastline':{
        'file_location':'./water-polygons-split-4326/water-polygons-split-4326/water_polygons.shp',
        'buffer':100000,
        'circle':False
    },
    

    Before this change the map for Eureka, California would look like: image

    and after it looks like: image

    In both these examples I also have water layer as the coastline data does not rivers and bays etc:

    'water': {
        'tags':{
            'waterway': True,
            'water': True,
            'harbour': True,
            'marina': True,
            'bay': True,
            'river': True
        },
        'dilate':100
    },
    
    opened by G21-Goose 4
  • build: Add MANIFEST.in with prune strategy

    build: Add MANIFEST.in with prune strategy

    • Resolves #65
    • Needed for Issue #67
    * Use `prune **` to remove all files from the sdist
        - c.f. https://packaging.python.org/guides/using-manifest-in/#manifest-in-commands
        - "Setuptools also has undocumented support for ** matching zero or
           more characters including forward slash, backslash, and colon."
    * Manually include all "default" files for a sdist in MANIFEST.in
        - c.f. https://packaging.python.org/guides/using-manifest-in/#how-files-are-included-in-an-sdist
    * Include requirements.txt as not using declartive spec for setup
    
    opened by matthewfeickert 3
  • Rotation

    Rotation

    Hi,

    I love your project, thanks for sharing it! Is there any way to rotate the underlying map? I'm doing a city where the roads are just a few degrees off from alignment with North and I'd love to rotate the image. Any tips?

    Thanks,

    Matt

    opened by mawise 3
  • Rivers are not displayed

    Rivers are not displayed

    Is it possible to draw rivers too? Until now the layers ['perimeter', 'landuse', 'water', 'building', 'streets'] are supported if I am not mistaken? Is it possible to add the key waterway or something like that?

    opened by araccaine 2
  • FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\cuyug\assets\Permanent_Marker\PermanentMarker-Regular.ttf`

    FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\cuyug\assets\Permanent_Marker\PermanentMarker-Regular.ttf`

    Can someone help me how to fix these errors? Thanks in advance.

    FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\cuyug\assets\Permanent_Marker\PermanentMarker-Regular.ttf`

    DeprecationWarning: An exception was ignored while fetching the attributearray_interfacefrom an object of type 'Polygon'. With the exception ofAttributeErrorNumPy will always raise this exception in the future. Raise this deprecation warning to see the original exception. (Warning added NumPy 1.21)

    opened by matthewcuyugan 2
  • Fix geometry-perimeter intersection

    Fix geometry-perimeter intersection

    Some geometry was removed, even through it was partially in the perimeter such as in issue #46 where not all the river was visible because the last bit partially went out of the perimeter. This seemed to happen when a perimeter was provided and not a point or radius.

    If geometries = geometries.intersection(perimeter) is changed to geometries = geometries.intersection(perimeter).buffer(0) it seems to have behaviour that would be expected.

    Before change image

    After change image

    Also the buffer on the perimeter in get_geometries() and get_streets() was being performed on the longitude and latitude in degrees, not meters. It now projects it, buffers it in meters, then turns it back into degrees for the ox.geometries_from_polygon()/ox.graph_from_polygon().

    The get_streets() function would have streets going over the perimeter when only used with a perimeter. This was because the intersection code wasn't running when only a perimeter was used, and the perimeter was still a GeoDataFrame because the line perimeter = unary_union(ox.project_gdf(perimeter).geometry) was missing.

    opened by G21-Goose 2
  • Portrait orientation of Barcelona example

    Portrait orientation of Barcelona example

    Hello! Is it possible to make Barcelona example in portrait orientation? Draw map 2/3 proportion rectangle not square.

    opened by generativearts 2
  • Add GPX data support

    Add GPX data support

    This PR lays the ground work for full fledged GPX support. It can take a .gpx file as input and center the map around it. If no radius is specified it also sets the radius to encompass the whole track. In the future this can be expanded to include a layer for visual output.

    opened by Alexjsenn 0
  • Oakland Harbor Not Rendering Correctly

    Oakland Harbor Not Rendering Correctly

    Hi,

    I am rendering a map of West Oakland, CA, using the below code:

    layers = {
                        'perimeter': {'circle': False, 'dilate': dilate},
                        'streets': {
                            'width': {
                                    'primary': 5,
                                    'secondary': 4,
                                    'tertiary': 3,
                                    'residential': 2,
                                    'footway': 1,
                            },
                            'circle': False,
                            'dilate': dilate
                        },
                        'building': {'tags': {'building': True, 'landuse': 'construction'}, 'union': False, 'circle': False, 'dilate': dilate},
                        'water': {'tags': {
                                    'waterway': True,
                                    'water': True,
                                    'harbour': True,
                                    'marina': True,
                                    'bay': True,
                                    'river': True
                         }, 'circle': False, 'dilate': dilate},
                        'green': {'tags': {'landuse': 'grass', 'natural': ['island', 'wood'], 'leisure': 'park'}, 'circle': False, 'dilate': dilate},
                        'forest': {'tags': {'landuse': 'forest'}, 'circle': False, 'dilate': dilate},
                        'parking': {'tags': {'amenity': 'parking', 'highway': 'pedestrian', 'man_made': 'pier'}, 'circle': False, 'dilate': dilate},
    
                    },
                    drawing_kwargs = {
                        'background': {'fc': '#F2F4CB', 'ec': '#dadbc1', 'hatch': 'ooo...', 'zorder': -1},
                        'perimeter': {'fc': '#F2F4CB', 'ec': '#dadbc1', 'lw': 0, 'hatch': 'ooo...',  'zorder': 0},
                        'green': {'fc': '#D0F1BF', 'ec': '#2F3737', 'lw': 1, 'zorder': 1},
                        'forest': {'fc': '#64B96A', 'ec': '#2F3737', 'lw': 1, 'zorder': 1},
                        'water': {'fc': '#a1e3ff', 'ec': '#2F3737', 'hatch': 'ooo...', 'hatch_c': '#85c9e6', 'lw': 1, 'zorder': 2},
                        'parking': {'fc': '#F2F4CB', 'ec': '#2F3737', 'lw': 1, 'zorder': 3},
                        'streets': {'fc': '#2F3737', 'ec': '#475657', 'alpha': 1, 'lw': 0, 'zorder': 3},
                        'building': {'palette': ['#FFC857', '#E9724C', '#C5283D'], 'ec': '#2F3737', 'lw': .5, 'zorder': 4},
                    },
    

    As you can see, though, my output does not match the OSM map, as the Oakland Inner Harbor is not rendering: image image

    Any idea what could be going on here?

    opened by tklutey 0
  • Notebook broke due to dependency problem

    Notebook broke due to dependency problem

    Hi,

    the linked example notebook broke (regardless of whether it's executed on Binder or Colab) with the following dependency problem:

    There are some problems showing when initially executing the first cell. When executing the second cell afterwards I get this:

    ContextualVersionConflict: (scipy 1.4.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('scipy<2.0,>=1.6'), {'vpype'})

    opened by sporst 1
  • Washington DC not horizontal rendered

    Washington DC not horizontal rendered

    Hi, i was just trying to render Washington DC (38.89872,-77.03654).

    Open street Maps Map of Washington shows me that all streets are horizontal East-West.

    But when i render it, it looks like this: washington

    Just a bit rotated.... I used following Notebook: Washington.pdf

    Is there any explanation to that phenomena? Can i rotate the location but still render as a horizontal square?

    Thanks

    opened by smilebasti 1
  • Licence

    Licence

    I fully understand the change of the licence and absolute support it. But I don't think CC is not the correct one since it is more for art and scientific papers etc.

    See githubs desciption: The most common license for Open Access scientific publications. Not recommended for software.

    I propose GPL 3.0

    opened by worldpotato 16
  • feat: Use bump2version to make new release tags

    feat: Use bump2version to make new release tags

    To try to reduce some of the workflow confusion that PR #69 caused, this PR assumes that maintainers will use bump2version to make a release tag and adds a .bumpversion.cfg file that enables committing changes and tagging the commit with the new version tag (equivalent of adding --commit and --tag at the CLI API).

    This PR also adds instructions to walk a maintainer through a release process.


    @marceloprates I've left this PR in draft status and have it with parent of 77b992e rather than the current project HEAD so that I can rebase it after whatever actions you take RE: our discussion in https://github.com/marceloprates/prettymaps/pull/69#issuecomment-936460764. I'm of course happy to elaborate or revise any part of this PR! :+1:

    opened by matthewfeickert 0
  • GPX data

    GPX data

    Hey,

    I love the the package. The maps look really great.

    Is it possible to use gpx data to generate the maps? For instance by rendering a map around a gpx track or/and by rendering a gpx track layer?

    That would be super cool to visualize trekking/hiking/bike tours.

    Best, Sebastian

    opened by s-bl 1
  • Railways

    Railways

    I have a problem to get Railways to display on the map at all.

    I used this code for my railway

           'railway': {
                'custom_filter': '["rail|light_rail|subway|tram|disused|construction|abandoned|monorail|narrow_gauge"]',
                'width': {
                    'rail': 7,
                    'light_rail': 5
                    'subway': 5,
                    'tram': 4,
                    'disused': 4,
                    'construction': 3,
                    'abandoned': 3,
                    'monorail': 3,
                    'narrow_gauge': 3,
                },
            'circle': False,
            'dilate': dilate
            },
    

    and kwargs

    'railway': {'fc': '#2F3737', 'ec': '#475657', 'alpha': 1, 'lw': 0, 'zorder': 6}

    I tried to map this area which has plenty of different kinds of railway

    https://www.openstreetbrowser.org/#railway-infrastructure/w178925635&map=18/52.42969/13.25519&categories=railway-infrastructure

    It will not display anything at all for that area. Did anyone got railways working or is that feature not implemented (yet)

    opened by Stelorio 4
  • Installation fails in WSL Ubuntu 20.04

    Installation fails in WSL Ubuntu 20.04

    When I try to install it, it fails with following error message:

    pip install git+https://github.com/abey79/vsketch#egg=vsketch
    Collecting vsketch from git+https://github.com/abey79/vsketch#egg=vsketch
      Cloning https://github.com/abey79/vsketch to /tmp/pip-install-qgq8p8ja/vsketch
      Installing build dependencies ... done
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/usr/lib/python3.7/tokenize.py", line 447, in open
            buffer = _builtin_open(filename, 'rb')
        FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-install-qgq8p8ja/vsketch/setup.py'
    
        ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-qgq8p8ja/vsketch/
    

    Same with the other command Is there an alternative way to install it? It looks like something is wrong with the tmp folder, not sure what tho.

    opened by baeric 2
Releases(v0.1.3)
Owner
Marcelo de Oliveira Rosa Prates
PhD in Machine Learning from the Federal University of Rio Grande do Sul (UFRGS). Passionate about deep learning, education and generative art.
Marcelo de Oliveira Rosa Prates
A library to access OpenStreetMap related services

OSMPythonTools The python package OSMPythonTools provides easy access to OpenStreetMap (OSM) related services, among them an Overpass endpoint, Nomina

Franz-Benjamin Mocnik 270 Feb 11, 2022
OSMnx: Python for street networks. Retrieve, model, analyze, and visualize street networks and other spatial data from OpenStreetMap.

OSMnx OSMnx is a Python package that lets you download geospatial data from OpenStreetMap and model, project, visualize, and analyze real-world street

Geoff Boeing 3.4k Feb 12, 2022
Tools for the extraction of OpenStreetMap street network data

OSMnet Tools for the extraction of OpenStreetMap (OSM) street network data. Intended to be used in tandem with Pandana and UrbanAccess libraries to ex

Urban Data Science Toolkit 45 Nov 7, 2021
Example of animated maps in matplotlib + geopandas using entire time series of congressional district maps from UCLA archive. rendered, interactive version below

Example of animated maps in matplotlib + geopandas using entire time series of congressional district maps from UCLA archive. rendered, interactive version below

Apoorva Lal 4 Sep 17, 2021
Python renderer for OpenStreetMap with custom icons intended to display as many map features as possible

Map Machine project consists of Python OpenStreetMap renderer: SVG map generation, SVG and PNG tile generation, Röntgen icon set: unique CC-BY 4.0 map

Sergey Vartanov 78 Feb 6, 2022
A bot that tweets info and location map for new bicycle parking added to OpenStreetMap within a GeoJSON boundary.

Bike parking tweepy bot app A twitter bot app that searches for bicycle parking added to OpenStreetMap. Relies on AWS Lambda/S3, Python3, Tweepy, Flas

Angelo Trivisonno 1 Dec 19, 2021
Python library to visualize circular plasmid maps

Plasmidviewer Plasmidviewer is a Python library to visualize plasmid maps from GenBank. This library provides only the function to visualize circular

Mori Hideto 1 Dec 12, 2021
Python Data. Leaflet.js Maps.

folium Python Data, Leaflet.js Maps folium builds on the data wrangling strengths of the Python ecosystem and the mapping strengths of the Leaflet.js

null 5.6k Feb 12, 2022
python toolbox for visualizing geographical data and making maps

geoplotlib is a python toolbox for visualizing geographical data and making maps data = read_csv('data/bus.csv') geoplotlib.dot(data) geoplotlib.show(

Andrea Cuttone 952 Feb 11, 2022
Google maps for Jupyter notebooks

gmaps gmaps is a plugin for including interactive Google maps in the IPython Notebook. Let's plot a heatmap of taxi pickups in San Francisco: import g

Pascal Bugnion 728 Feb 1, 2022
Solving the Traveling Salesman Problem using Self-Organizing Maps

Solving the Traveling Salesman Problem using Self-Organizing Maps This repository contains an implementation of a Self Organizing Map that can be used

Diego Vicente 1.7k Feb 2, 2022
Interactive Maps with Geopandas

Create Interactive maps ??️ with your geodataframe Geopatra extends geopandas for interactive mapping and attempts to wrap the goodness of amazing map

sangarshanan 44 Dec 29, 2021
Google Maps keeps old satellite imagery around for a while – this tool collects what's available for a user-specified region in the form of a GIF.

google-maps-at-88-mph The folks maintaining Google Maps regularly update the satellite imagery it serves its users, but outdated versions of the image

Noah Doersing 92 Feb 7, 2022
Daily social mapping project in November 2021. Maps made using PyGMT whenever possible.

Daily social mapping project in November 2021. Maps made using PyGMT whenever possible.

Wei Ji 13 Dec 26, 2021
Deal with Bing Maps Tiles and Pixels / WGS 84 coordinates conversions, and generate grid Shapefiles

PyBingTiles This is a small toolkit in order to deal with Bing Tiles, used i.e. by Facebook for their Data for Good datasets. Install Clone this repos

Shoichi 1 Dec 8, 2021
Implemented a Google Maps prototype that provides the shortest route in terms of distance

Implemented a Google Maps prototype that provides the shortest route in terms of distance, the fastest route, the route with the fewest turns, and a scenic route that avoids roads when provided a source and destination. The algorithms used were DFS, BFS, A*, and Iterative Depth First Search.

null 1 Dec 26, 2021
Spectral decomposition for characterizing long-range interaction profiles in Hi-C maps

Inspectral Spectral decomposition for characterizing long-range interaction prof

Nezar Abdennur 4 Feb 2, 2022
peartree: A library for converting transit data into a directed graph for sketch network analysis.

peartree ?? ?? peartree is a library for converting GTFS feed schedules into a representative directed network graph. The tool uses Partridge to conve

Kuan Butts 133 Feb 4, 2022
Open Data Cube analyses continental scale Earth Observation data through time

Open Data Cube Core Overview The Open Data Cube Core provides an integrated gridded data analysis environment for decades of analysis ready earth obse

Open Data Cube 362 Feb 4, 2022