{ "info": { "author": "Markus Konrad", "author_email": "markus.konrad@wzb.eu", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Scientific/Engineering :: Information Analysis", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "# geovoronoi \u2013 a package to create and plot Voronoi regions inside geographic areas\n\nMarkus Konrad , July 2019\n\n## Overview\n\n![Voronoi regions of random points across Spain and their respective area](https://raw.githubusercontent.com/WZBSocialScienceCenter/geovoronoi/master/examples/random_points_and_area.png)\n\n*geovoronoi* helps generating [Voronoi regions](https://en.wikipedia.org/wiki/Voronoi_diagram) for geographic data, for example coordinates of public universities in a certain country. This in turn may be used to estimate some kind of \"coverage\".\n\nIt takes a list of coordinates and calculates the Voronoi regions from them using [SciPy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.Voronoi.html#scipy.spatial.Voronoi). At the edges, these regions go to infinity. We can then take the shape of the surrounding area (e.g. the shape of a country as polygon) to cut the Voronoi regions so that they fit into the provided shape, making the regions at the edges finite. *geovoronoi* uses [shapely](http://toblerity.org/shapely/) for these operations. The package furthermore implements some functions for easy plotting of the resulting Voronoi regions.\n\n## Installation\n\nThis package is available on [PyPI](https://pypi.org/project/geovoronoi/). You can install the latest version via *pip* as follows:\n\n```\n# install with \"plotting\" dependencies (recommended):\npip install -U geovoronoi[plotting]\n\n# or install base version:\npip install -U geovoronoi\n``` \n\n## Usage\n\nYou have a geographic area that contains some points for which you want to generate Voronoi regions. This geographic area is a [shapely Polygon/MultiPolygon object](http://toblerity.org/shapely/manual.html#polygons) (that you, for example obtained from a GeoJSON file that you loaded with [GeoPandas](http://geopandas.org/) or [Fiona](http://toblerity.org/fiona/)). The *N* points you have are either in the form of a *N*x2 NumPy array, or a list of shapely Point objects (they can be converted with the functions `coords_to_points` and `points_to_coords`). Both the points and the surrounding geographic area must have the same [CRS (coordinate reference system)](https://en.wikipedia.org/wiki/Spatial_reference_system).\n\nLet's take for example these randomly generated points in Italy (in [World Mercator CRS](https://epsg.io/3395)): \n\n```python\nimport numpy as np\n\n# coords = ... generate some coordinates with np.random.uniform ...\nprint(coords)\n```\n\n```\narray([[1690891.43454513, 4865911.53550427],\n [1303898.2749075 , 5398659.4816214 ],\n [1379407.32051822, 5701267.51923313],\n [1703402.05850744, 4916559.63783754],\n ...\n ]])\n``` \n\nThe surrounding shape of Italy was obtained beforehand from GeoPandas:\n\n```python\nimport geopandas as gpd\n\nworld = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))\narea = world[world.name == 'Italy']\n\narea = area.to_crs(epsg=3395) # convert to World Mercator CRS\narea_shape = area.iloc[0].geometry # get the Polygon\n```\n\nNow we can calculate the Voronoi regions, cut them with the geographic area shape and assign the points to them:\n\n```python\nfrom geovoronoi import voronoi_regions_from_coords\n\npoly_shapes, pts, poly_to_pt_assignments = voronoi_regions_from_coords(coords, area_shape)\n```\n\n`poly_shapes` is a list of shapely Polygon objects that represent the shape of the respective Voronoi region. With them, you can do everything that the [shapely API](http://toblerity.org/shapely/manual.html#polygons) provides. You can, for example, get each Voronoi region's [area](http://toblerity.org/shapely/manual.html#object.area) (there's also a helper function `calculate_polygon_areas` in *geovoronoi* for that). \n\n`pts` is list of shapely Point objects converted from `coords` (in the same order). `poly_to_pt_assignments` is a nested list that for each Voronoi region in `poly_shapes` contains a list of indices into `pts` (and hence `coords`) that represent the points that belong to this Voronoi region. Usually, this is only a single point. However, in case of duplicate points (e.g. both or more points have exactly the same coordinates) then all these duplicate points are listed for the respective Voronoi region.\n\nYou can plot the results with the functions from the `plotting` sub-module:\n\n```python\nimport matplotlib.pyplot as plt\nfrom geovoronoi.plotting import subplot_for_map, plot_voronoi_polys_with_points_in_area\n\nfig, ax = subplot_for_map()\nplot_voronoi_polys_with_points_in_area(ax, area_shape, poly_shapes, coords, poly_to_pt_assignments)\nplt.show()\n```\n\nThis would be an example output (see \"Limitations\" below for the issue of the regions in Sardinia):\n\n![Voronoi regions of random points across Italy](https://raw.githubusercontent.com/WZBSocialScienceCenter/geovoronoi/master/examples/random_points_across_italy.png)\n\nSee the full example source code in [examples/random_points_across_italy.py](examples/random_points_across_italy.py). See also the other examples in the [examples/](examples) directory that show how to calculate the area of the Voronoi regions, handle duplicate points or interact with GeoPandas. \n\n## Dependencies\n\n*geovoronoi* requires **Python 3.4 or newer**. The following packages need to be installed (if not, they will be automatically installed if you use a Python package manager like *pip*):\n\n* NumPy\n* SciPy\n* shapely\n* matplotlib (only necessary for plotting)\n* geopandas (only necessary for plotting)\n* descartes (only necessary for plotting)\n\n## Limitations\n\n* MultiPolygon shapes of geographic areas are not treated separately when cutting the Voronoi regions (see Sardinia in `random_points_across_italy.py` example)\n\n## TODO\n\n* support of MultiPolygon shapes of geographic areas (see Sardinia in `random_points_across_italy.py` example)\n* support for plotting `area_shape` objects with multiple geometries\n\n## License\n\nLicensed under [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). See `LICENSE.txt` file. \n\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/WZBSocialScienceCenter/geovoronoi", "keywords": "voronoi tesselation gis geographic area visualization plotting", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "geovoronoi", "package_url": "https://pypi.org/project/geovoronoi/", "platform": "", "project_url": "https://pypi.org/project/geovoronoi/", "project_urls": { "Homepage": "https://github.com/WZBSocialScienceCenter/geovoronoi", "Source": "https://github.com/WZBSocialScienceCenter/geovoronoi", "Tracker": "https://github.com/WZBSocialScienceCenter/geovoronoi/issues" }, "release_url": "https://pypi.org/project/geovoronoi/0.1.2/", "requires_dist": [ "numpy (>=1.11.0)", "scipy (>=0.12.0)", "shapely (>=1.6.0)", "matplotlib (>=2.1.0) ; extra == 'plotting'", "geopandas (>=0.5.0) ; extra == 'plotting'", "descartes (>=1.1.0) ; extra == 'plotting'" ], "requires_python": ">=3.4", "summary": "a package to create and plot Voronoi regions in geographic areas", "version": "0.1.2" }, "last_serial": 5894982, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "7e0d417cdd165eaeb6fa38d7650b0cab", "sha256": "bf67ee4d2fc2def390dc6cc1e7656c36589dcbf39c03ad90258db2a2c79cb2e3" }, "downloads": -1, "filename": "geovoronoi-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "7e0d417cdd165eaeb6fa38d7650b0cab", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4", "size": 12034, "upload_time": "2018-03-16T09:50:16", "url": "https://files.pythonhosted.org/packages/b9/8f/7188ca67b0154fa7a615d69a7222003dc393a1526cf11b4d03d76f388bf7/geovoronoi-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "771767d9b1a036576c789bd634fb5750", "sha256": "793e4982a2c06ec7d2bcf782abaec7f3f56a5f7c8d4e4647b1e2ad0666e02e8c" }, "downloads": -1, "filename": "geovoronoi-0.1.0.tar.gz", "has_sig": false, "md5_digest": "771767d9b1a036576c789bd634fb5750", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 11612, "upload_time": "2018-03-16T09:50:18", "url": "https://files.pythonhosted.org/packages/bd/be/09ca58d46b9aa4fb92cfa2702c6d92f1632a85a60907ea73fd9278bc30da/geovoronoi-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "2a928fa83f1c38788fad8b9ddc5bc828", "sha256": "74da2c4b62c78b20f470493675cc86729f23b15c7910520bbbd77fcae537289e" }, "downloads": -1, "filename": "geovoronoi-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "2a928fa83f1c38788fad8b9ddc5bc828", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4", "size": 16746, "upload_time": "2019-07-11T12:49:39", "url": "https://files.pythonhosted.org/packages/09/16/45a50afdde9042b0c3513b5ac5ded18b197913c72ff88fe2bc585d211439/geovoronoi-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ed7cd301528d5f53616d15ac163a6103", "sha256": "0f097d5c58facf73bd5c09d71aef983e9c4139b48f05bd0c876961cd44d731e9" }, "downloads": -1, "filename": "geovoronoi-0.1.1.tar.gz", "has_sig": false, "md5_digest": "ed7cd301528d5f53616d15ac163a6103", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 13957, "upload_time": "2019-07-11T12:49:41", "url": "https://files.pythonhosted.org/packages/dd/bd/d58ae9d903c54ef432940f1a94afadc9f1d6c86c53c8f1195ad2166b0a30/geovoronoi-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "c4f7c3113024b4b047933c302860b219", "sha256": "8b6dbcae002e1f24e66235929508d800bf24ae43da3e7c080786b1a6a27ff667" }, "downloads": -1, "filename": "geovoronoi-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "c4f7c3113024b4b047933c302860b219", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4", "size": 16767, "upload_time": "2019-09-27T09:04:00", "url": "https://files.pythonhosted.org/packages/81/22/92f86762c99f12e8ea23366edb23193634d0292257bd07dbef85967be0b8/geovoronoi-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d3caf7adf99e0ab64b160f3b75bfc17d", "sha256": "b8413ccbcbaad82c008c27887302bc90ec7a6f94c1a80eaf8254b846da77ff16" }, "downloads": -1, "filename": "geovoronoi-0.1.2.tar.gz", "has_sig": false, "md5_digest": "d3caf7adf99e0ab64b160f3b75bfc17d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 13981, "upload_time": "2019-09-27T09:04:02", "url": "https://files.pythonhosted.org/packages/9a/4f/295e2bc513a54bde378c8fbca8edb16035b70852b9a8326d26fec2180e0f/geovoronoi-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c4f7c3113024b4b047933c302860b219", "sha256": "8b6dbcae002e1f24e66235929508d800bf24ae43da3e7c080786b1a6a27ff667" }, "downloads": -1, "filename": "geovoronoi-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "c4f7c3113024b4b047933c302860b219", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4", "size": 16767, "upload_time": "2019-09-27T09:04:00", "url": "https://files.pythonhosted.org/packages/81/22/92f86762c99f12e8ea23366edb23193634d0292257bd07dbef85967be0b8/geovoronoi-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d3caf7adf99e0ab64b160f3b75bfc17d", "sha256": "b8413ccbcbaad82c008c27887302bc90ec7a6f94c1a80eaf8254b846da77ff16" }, "downloads": -1, "filename": "geovoronoi-0.1.2.tar.gz", "has_sig": false, "md5_digest": "d3caf7adf99e0ab64b160f3b75bfc17d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 13981, "upload_time": "2019-09-27T09:04:02", "url": "https://files.pythonhosted.org/packages/9a/4f/295e2bc513a54bde378c8fbca8edb16035b70852b9a8326d26fec2180e0f/geovoronoi-0.1.2.tar.gz" } ] }