{ "info": { "author": "Tammo Ippen", "author_email": "tammo.ippen@posteo.de", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "GEOPIP: Geojson Point in Polygon (PIP)\n======================================\n\n|Build Status| |Coverage Status| |Tested CPython Versions| |Tested PyPy\nVersions| |PyPi version| |PyPi license|\n\nReverse geocode a lng/lat coordinate within a geojson\n``FeatureCollection`` and return information about the containing\ncountry (polygon).\n\nBasically, you can use any\n`geojson `__ file (top level is a\n``FeatureCollection``) for reverse coding - set the environment variable\n``REVERSE_GEOCODE_DATA`` to the geojson file. Only ``Polygon`` and\n``MultiPolygon`` features will be used! If a point is found to be in a\nfeature, the ``properties`` of that feature will be returned.\n\nIn other words, provide a geojson with postcode boundaries, and you can\nquery for the postcode in which a coordinate is. Provide timezone\nboundaries and you can find the timezone for a coordinate. Be creative\n:).\n\nThe default shape data (contained within the package) is from\n`thematicmapping `__\n(the simple shapes). It contains polygons representing one country with\nthe following meta-data (``properties``):\n\n::\n\n FIPS String(2) FIPS 10-4 Country Code\n ISO2 String(2) ISO 3166-1 Alpha-2 Country Code\n ISO3 String(3) ISO 3166-1 Alpha-3 Country Code\n UN Short Integer(3) ISO 3166-1 Numeric-3 Country Code\n NAME String(50) Name of country/area\n AREA Long Integer(7) Land area, FAO Statistics (2002)\n POP2005 Double(10,0) Population, World Population Prospects (2005)\n REGION Short Integer(3) Macro geographical (continental region), UN Statistics\n SUBREGION Short Integer(3) Geographical sub-region, UN Statistics\n LON FLOAT (7,3) Longitude\n LAT FLOAT (6,3) Latitude\n\nHence, you can use this package as an *offline reverse geocoder on the\ncountry level* (by default):\n\n.. code:: python\n\n In [1]: import geopip\n In [2]: geopip.search(lng=4.910248, lat=50.850981)\n Out[2]:\n {'AREA': 0,\n 'FIPS': 'BE',\n 'ISO2': 'BE',\n 'ISO3': 'BEL',\n 'LAT': 50.643,\n 'LON': 4.664,\n 'NAME': 'Belgium',\n 'POP2005': 10398049,\n 'REGION': 150,\n 'SUBREGION': 155,\n 'UN': 56}\n\n**NOTE**: Since the polygons for each country are quite simple, reverse\ngeocoding at the borders of two countrys is **not** exact. Use polygons\nwith higher resolution for these use cases (see `Data <#data>`__).\n\nThe ``shapely`` package will be used, if installed. Otherwise, a pure\npython implementation will be used (on the basis of `winding\nnumbers `__). See\n`here `__,\n`here `__ and\n`here `__\nfor more informations and example implementations. Espacially for larger\nfeatures, the shapely implementation might give performance improvements\n(default shape data and 2.6 GHz Intel Core i7, python3.6.2, cythonized\nversion of\n`geohash-hilbert `__):\n\n*Pure*:\n\n.. code:: python\n\n In [1]: import geopip\n In [2]: geopip._geopip.p_in_polygon?\n Signature: geopip._geopip.p_in_polygon(p, shp)\n Docstring:\n Test, whether point `p` is in shape `shp`.\n\n Use the pure python implementation for this.\n\n Parameters:\n p: Tuple[float, float] Point (lng, lat) in WGS84.\n shp: Dict[str, Any] Prepared shape dictionary from `geopip._pure.prepare()`.\n\n Returns:\n boolean: True, if p in shp, False otherwise\n File: ~/repositories/geopip/geopip/_pure.py\n Type: function\n In [3]: %timeit geopip.search(4.910248, 50.850981)\n 25.6 \u00b5s \u00b1 390 ns per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n\n*Shapely*:\n\n.. code:: python\n\n In [1]: import geopip\n In [2]: geopip_geopip.p_in_polygon?\n Signature: geopip._geopip.p_in_polygon(p, shp)\n Docstring:\n Test, whether point `p` is in shape `shp`.\n\n Use the shapely implementation for this.\n\n Parameters:\n p: Tuple[float, float] Point (lng, lat) in WGS84.\n shp: Dict[str, Any] Prepared shape dictionary from `geopip._shapely.prepare()`.\n\n Returns:\n boolean: True, if p in shp, False otherwise\n File: ~/repositories/geopip/geopip/_shapely.py\n Type: function\n In [3]: %timeit geopip.search(4.910248, 50.850981)\n 50 \u00b5s \u00b1 601 ns per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n\nFor simple geojsons, the pure python implementation is faster, but on\nmore complex polygons, the shapely implementation will win.\n\nInstall\n-------\n\n.. code:: sh\n\n pip install geopip\n\nIf you require the extra speed, because you have many polygons and / or\nvery detailed polygons, try installing geohash-hilbert with Cython\nextensions and / or have (vectorized) shapely installed.\n\n.. code:: sh\n\n # make sure to have GEOS library installed (including dev extensions)\n pip install numpy 'shapely[vectorized]>=1.6'\n\n pip install cython # for building geohash-hilbert's cython extension\n pip install --upgrade geohash-hilbert\n\nData\n----\n\nOther interesting shape data can be found at:\n\n- http://www.naturalearthdata.com/downloads/ : Different thematic shape\n files at 10m, 50m and 110m resolution.\n- http://www.gadm.org/version2 : Administrative area 0 or 1 contain\n contries or states, respectively. Attention to the license!\n- https://www2.census.gov/geo/tiger/: Various shape/gdb files and\n information for USA.\n- http://guides.library.upenn.edu/c.php?g=475518&p=3254770: Links to\n various geoinformation data.\n- http://thematicmapping.org/downloads/world\\_borders.php: Country\n borders and some interesting information. The default file is from\n here. There is also a higher resolution version.\n- https://github.com/evansiroky/timezone-boundary-builder: Time zone\n boundaries. See releases for downloads.\n- https://www.suche-postleitzahl.org/plz-karte-erstellen: DE\n postalcodes + size + population (Census / OSM).\n- https://www2.census.gov/geo/tiger/TIGER2010DP1/ZCTA\\_2010Census\\_DP1.zip:\n US postalcodes + size + population (Census; field definition see\n ``DP_TableDescriptions.xls`` in the zip).\n\n**NOTE**: shapefiles / gdb databases have to be transformed into\ngeojson. One way is to use\n`fiona `__. Assuming the gdb files\nare in the directory ``/data/gdb``:\n\n.. code:: python\n\n fio insp /data/gdb\n # a python shell opens\n >>> import json\n >>> features = []\n >>> for feat in src:\n ... features += [feat]\n ...\n >>> f = open('/data/gdb.geo.json', 'w')\n >>> json.dump(dict(type='FeatureCollection', features=features), f)\n >>> f.close()\n\nThen the ``gdb`` will be transformed into a geojson file\n``gdb.geo.json``.\n\nDocumentation\n=============\n\n(*TODO* more) Basically, there are the two functions ``geopip.search``\nand ``geopip.search_all`` that perform the search in the provided\n``FeatureCollection``. Then there is the class ``geopip.GeoPIP`` that\naccepts a ``FeatureCollection`` either as a file or a dictionary and\nprovides the same search functionality:\n\n``search``\n----------\n\n.. code:: python\n\n In [1]: import geopip\n In [2]: geopip.search?\n Signature: geopip.search(lng, lat)\n Docstring:\n Reverse geocode lng/lat coordinate within the features from `instance().shapes`.\n\n Look within the features from the `instance().shapes` function for a polygon that\n contains the point (lng, lat). From the first found feature the `porperties`\n will be returned. `None`, if no feature containes the point.\n\n Parameters:\n lng: float Longitude (-180, 180) of point. (WGS84)\n lat: float Latitude (-90, 90) of point. (WGS84)\n\n Returns:\n Dict[Any, Any] `Properties` of found feature. `None` if nothing is found.\n File: ~/repositories/geopip/geopip/__init__.py\n Type: function\n\n``search_all``\n--------------\n\n.. code:: python\n\n In [1]: import geopip\n In [2]: geopip.search_all?\n Signature: geopip.search_all(lng, lat)\n Docstring:\n Reverse geocode lng/lat coordinate within the features from `instance().shapes`.\n\n Look within the features from the `instance().shapes` function for all polygon that\n contains the point (lng, lat). From all found feature the `porperties`\n will be returned (more or less sorted from smallest to largest feature).\n `None`, if no feature containes the point.\n\n Parameters:\n lng: float Longitude (-180, 180) of point. (WGS84)\n lat: float Latitude (-90, 90) of point. (WGS84)\n\n Returns:\n Iterator[Dict[Any, Any]] Iterator for `properties` of found features.\n File: ~/repositories/geopip/geopip/__init__.py\n Type: function\n\n``GeoPIP``\n----------\n\n.. code:: python\n\n In [1]: import geopip\n In [2]: geopip.GeoPIP?\n Init signature: geopip.GeoPIP(self, *args, **kwargs)\n Docstring:\n GeoPIP: Geojson Point in Polygon (PIP)\n\n Reverse geocode a lng/lat coordinate within a geojson `FeatureCollection` and\n return information about the containing polygon.\n Init docstring:\n Provide the geojson either as a file (`filename`) or as a geojson\n dict (`geojson_dict`). If none of both is given, it tries to load the\n file pointed to in the environment variable `REVERSE_GEOCODE_DATA`. If the\n variable is not set, a default geojson will be loaded (packaged):\n http://thematicmapping.org/downloads/world_borders.php\n\n During init, the geojson will be prepared (see pure / shapely implementation)\n and indexed with geohashes.\n\n Provide the parameters as kwargs!\n\n Allowed parameters:\n filename: str Path to a geojson file.\n geojson_dict: Dict[str, Any] Geojson dictionary. `FeatureCollection` required!\n File: ~/repositories/geopip/geopip/_geopip.py\n Type: type\n\nA ``GeoPIP`` object provides the same ``search`` and ``search_all``\nfunctions.\n\n.. |Build Status| image:: https://travis-ci.org/tammoippen/geopip.svg?branch=master\n :target: https://travis-ci.org/tammoippen/geopip\n.. |Coverage Status| image:: https://coveralls.io/repos/github/tammoippen/geopip/badge.svg?branch=master\n :target: https://coveralls.io/github/tammoippen/geopip?branch=master\n.. |Tested CPython Versions| image:: https://img.shields.io/badge/cpython-2.7%2C%203.5%2C%203.6%2C%20nightly-brightgreen.svg\n :target: https://img.shields.io/badge/cpython-2.7%2C%203.5%2C%203.6%2C%20nightly-brightgreen.svg\n.. |Tested PyPy Versions| image:: https://img.shields.io/badge/pypy-2.7--5.8.0%2C%203.5--5.8.0-brightgreen.svg\n :target: https://img.shields.io/badge/pypy-2.7--5.8.0%2C%203.5--5.8.0-brightgreen.svg\n.. |PyPi version| image:: https://img.shields.io/pypi/v/geopip.svg\n :target: https://pypi.python.org/pypi/geopip\n.. |PyPi license| image:: https://img.shields.io/pypi/l/geopip.svg\n :target: https://pypi.python.org/pypi/geopip", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/tammoippen/geopip/archive/v1.1.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/tammoippen/geopip", "keywords": "geojson,point in polygon,reverse geocode,countries", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "geopip", "package_url": "https://pypi.org/project/geopip/", "platform": "", "project_url": "https://pypi.org/project/geopip/", "project_urls": { "Download": "https://github.com/tammoippen/geopip/archive/v1.1.tar.gz", "Homepage": "https://github.com/tammoippen/geopip" }, "release_url": "https://pypi.org/project/geopip/1.1/", "requires_dist": null, "requires_python": "", "summary": "Reverse geocode a lng/lat coordinate within a geojson FeatureCollection.", "version": "1.1" }, "last_serial": 3320496, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "661286aa5f16d3374ec046d21c42cfd4", "sha256": "128209729ccb3ce894aed0f6e6c5497bb7c2dec7b7176160d5c34f4de8d096eb" }, "downloads": -1, "filename": "geopip-0.1.tar.gz", "has_sig": false, "md5_digest": "661286aa5f16d3374ec046d21c42cfd4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 344618, "upload_time": "2017-08-24T11:27:18", "url": "https://files.pythonhosted.org/packages/96/c8/e8520c02017066c15aa254fa7d4b885928d87ca5120fe04c73618f559185/geopip-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "4e4acf917640c53b7af0bc2dc3a26d7a", "sha256": "e3a455a09e199da22a12bbf50d2c0180b4a7e91fb3ecb7298eb3b61956aa35b4" }, "downloads": -1, "filename": "geopip-0.2.tar.gz", "has_sig": false, "md5_digest": "4e4acf917640c53b7af0bc2dc3a26d7a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 345453, "upload_time": "2017-08-24T14:22:40", "url": "https://files.pythonhosted.org/packages/97/7a/342927ed9c604b5361bbb7ff1f0451f5dafe97018e98167541e58be21880/geopip-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "176c03b7bfe91859279597523e680b7b", "sha256": "bd5570b89696ebfa59d83dfa2676a8bf8f352221a0e1260707bb8a6fb04e51cb" }, "downloads": -1, "filename": "geopip-0.3.tar.gz", "has_sig": false, "md5_digest": "176c03b7bfe91859279597523e680b7b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 345450, "upload_time": "2017-08-24T14:50:18", "url": "https://files.pythonhosted.org/packages/35/c5/21016d265922b9d9fba0ef011b13062d4460b14c7eaf4c7214545ba20360/geopip-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "e044eff5a46be408de131deed7007460", "sha256": "2b4d4cfd6dec096af252a4f57069886401742add3f2f6205d078eb1596bb28f0" }, "downloads": -1, "filename": "geopip-0.4.tar.gz", "has_sig": false, "md5_digest": "e044eff5a46be408de131deed7007460", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 347332, "upload_time": "2017-09-08T13:52:34", "url": "https://files.pythonhosted.org/packages/29/40/6d107d479a3b52495c20cae45dc2575c6a87bc68e1c5db4f3c93d2ce9f72/geopip-0.4.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "9365d97c37254662ae8e21c88a2f97d7", "sha256": "6a73b62e79a2a94cc4bd3b32409a816686e885f7ffc1cb3938ce85036e707f27" }, "downloads": -1, "filename": "geopip-1.0.tar.gz", "has_sig": false, "md5_digest": "9365d97c37254662ae8e21c88a2f97d7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 357940, "upload_time": "2017-09-21T11:59:44", "url": "https://files.pythonhosted.org/packages/41/cb/255344e2986cda95b69bd9d0798ad3f6948979b5a5e6e6aba8809eff6979/geopip-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "0d96e4ba070be2b858d894fcaad7d942", "sha256": "db76cdf77089b51bea6e5c62bb7509c8bff0901ed712d12124154f953f6f6aef" }, "downloads": -1, "filename": "geopip-1.1.tar.gz", "has_sig": false, "md5_digest": "0d96e4ba070be2b858d894fcaad7d942", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 359991, "upload_time": "2017-11-09T19:43:30", "url": "https://files.pythonhosted.org/packages/f8/68/6915c368d8ca24f1b8e91b3184241fc9a6379ff0fd39f9b949ed5a835037/geopip-1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0d96e4ba070be2b858d894fcaad7d942", "sha256": "db76cdf77089b51bea6e5c62bb7509c8bff0901ed712d12124154f953f6f6aef" }, "downloads": -1, "filename": "geopip-1.1.tar.gz", "has_sig": false, "md5_digest": "0d96e4ba070be2b858d894fcaad7d942", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 359991, "upload_time": "2017-11-09T19:43:30", "url": "https://files.pythonhosted.org/packages/f8/68/6915c368d8ca24f1b8e91b3184241fc9a6379ff0fd39f9b949ed5a835037/geopip-1.1.tar.gz" } ] }